mypy infers the wrong type for classmethods #3482
Labels
bug
mypy got something wrong
topic-descriptors
Properties, class vs. instance attributes
topic-runtime-semantics
mypy doesn't model runtime semantics correctly
We have some code that simplifies to this:
(The real code is wrapping an async classmethod with a sync version; there's another async-to-sync wrapper in there.)
Mypy doesn't like this code because it doesn't know that classmethods have a
__func__
attribute. The typeshed annotation for classmethod includes__func__
, but mypy doesn't infer the real classmethod type forhi
(which is the actual type at runtime), it just infers a general callable type.This may not be easily fixed until we have protocol support and can more easily have various callable subtypes?
I'm also OK if this is closed as "just use cast() if you're accessing private attributes of a classmethod"; it's certainly not high priority.
The text was updated successfully, but these errors were encountered: