astral-sh/ruff

[red-knot] support type[Any]

Closed this issue · 5 comments

The Python type system supports the type[Any] type as a special case of the type[...] special form. This is a gradual type representing some unknown class and all of its subclasses.

Once we have fixed #14544, we should also support type[Any]. This will require updating our representation of SubclassOfType to an enum, so it can store either a Class or just represent type[Any]. This will also require checking each place we handle Type::SubclassOf and updating it to handle the gradual variant correctly.

We should also infer type[Any] from an annotation that just uses bare type, e.g. x: type = ....

I suspect the enum we want here will have the same variants as this one:

pub(super) enum ClassBase<'db> {

I don't know whether it's worth trying to reuse (and rename?) that one or create another one with the same variants

This seems simple enough. I'll have a PR ready by tomorrow.

This seems simple enough. I'll have a PR ready by tomorrow.

Appreciate the interest in contributing! This issue (and a few others) are assigned to me because they are on the ramp up plan for a new Astral team member. If there isn't an unassigned issue that looks interesting to you, I can create some additional ones soon!

This issue (and a few others) are assigned to me because they are on the ramp up plan for a new Astral team member.

Is that so? The branch is at 90% already, but I guess I'll have to drop it then.

We should also infer type[Any] from an annotation that just uses bare type, e.g. x: type = ....

Surfacing from #14876 (comment) that we have decided to interpret bare type as type[object], not type[Any].