-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
mypy infers the wrong type for classmethods #3482
Copy link
Copy link
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-descriptorsProperties, class vs. instance attributesProperties, class vs. instance attributestopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-descriptorsProperties, class vs. instance attributesProperties, class vs. instance attributestopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy 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.