Skip to content

[red-knot] Implement subtyping/assignability between different callable objects #16953

@dhruvmanila

Description

@dhruvmanila

With #16804 completed, we have the necessary infrastructure to check subtype/assignability relationship between two callable objects. Currently, it only does the check for subtyping/assignability between two GeneralCallableType types, which effectively means typing.Callable annotation or lambdas, as those are the only things that construct the GeneralCallableType. (We do expose knot_extensions.CallableTypeFromFunction from knot_extensions which converts a FunctionType into a GeneralCallableType but that's mainly to help write tests for it.)

This issue is to check other subtype and assignability relationships involving callable objects that still need to be implemented:

  • A CallableType is always a subtype of KnownClass::Object (and never the other way around)
  • A FunctionType can be a subtype of Callable (but never the other way around)
  • Other (non-GeneralCallable) Type::Callable variants, like bound methods, can be subtypes of / assignable to Callables.
  • InstanceType (with a __call__ method) can be a subtype of Callable (but never the other way around)

Metadata

Metadata

Assignees

Labels

help wantedContributions especially welcometyMulti-file analysis & type inference

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions