Open
Description
We have some code that simplifies to this:
class A:
@classmethod
def hi(cls):
pass
bye = classmethod(hi.__func__)
(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 for hi
(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.