You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
classmethod decorator transforms callable into callable rather than producing a classmethod? #12673
At the point at which the decorator is applied, the class method isn't a callable yet. It's a classmethod object that replies to __get__ to produce the bound method. Yet, MyPy already thinks it's a callable:
from __future__ importannotationsfromtypingimportCallabledefdecorate(c: classmethod[None]) ->Callable[[X], None]:
defg(x: X) ->None:
returnc.__func__(type(x))
returngclassX:
@decorate# error: Argument 1 to "decorate" has incompatible type "Callable[[Type[X]], None]"; expected "classmethod[None]"@classmethoddeff(cls) ->None:
print("okay")
x=X()
x.f() # error: Invalid self argument "Type[X]" to class attribute function "f" with type "Callable[[X], None]"
Pyright won't fix the first problem, so I can just ignore it. But is the second problem fixable? The decorator changes the class method into an ordinary method, so why is x.f() passing the type?
Activity
NeilGirdhar commentedon Apr 26, 2022
Pyright won't fix the first problem, so I can just ignore it. But is the second problem fixable? The decorator changes the class method into an ordinary method, so why is
x.f()passing the type?NeilGirdhar commentedon Aug 16, 2023
This would be solved by python/typing#1372