Skip to content

[red-knot] add Type::SubclassOf support to Type::call and Type::call_unbound #15948

Open
@carljm

Description

Description

Existing type checkers (and the typing spec) allow calling an object of type type[C] (in red-knot, Type::SubclassOf(<Class C>)), with the result of the call being an object of type C (in red-knot, Type::Instance(<Class C>)).

This is not actually sound, because Liskov compatibility is not enforced on type constructor methods (__init__ and __new__) when subclassing, so you can't be sure that a constructor call that works for a class C will actually work for a subclass of C. But it's widely relied on, and we will have to support it.

I would like to have an opt-in diagnostic emitted whenever you call an object of type[C], so users who want to avoid this unsoundness have that option.

Metadata

Assignees

Labels

help wantedContributions especially welcomered-knotMulti-file analysis & type inference

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions