Skip to content

wrong inference of function literals off subclass-of types #2428

@carljm

Description

@carljm

I think our inference of singleton function or bound-method types when accessed off nominal-instance or subclass-of types is simply wrong and needs to be fixed. The nominal-instance type A includes instances of A and all subclasses of A. That means it is wrong to say that instance_of_a.method is a singleton bound-method type, unless either A or A.method is marked as final. Similarly, type[A] includes subclasses of A, so subclass_of_A.method cannot be a singleton function literal type.

Accessing methods as attributes of class-literal types can still correctly return a function literal.

One unfortunate side effect of making the above fix is that we will lose go-to-definition on most methods. To avoid this regression, we may need to allow callable types to optionally carry a "most precise known" source definition (or definitions?), which is not "part of the type" in terms of type relations but can be used for go-to-definition.

Originally posted by @carljm in #770

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions