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
Callable ClassVar is incorrectly treated as a method #11077
This is a known problem / feature. The same happens without ClassVar as well:
fromtypingimportCallable, MutableMapping, ClassVarclassC:
x: Callable[[], MutableMapping] =dictdeff(self) ->MutableMapping:
# error: Attribute function "x" with type "Callable[[], MutableMapping[Any, Any]]" does not accept self argumentreturnself.x()
c=C()
print(c.f())
Can we re-open this? It's not fixed and not a duplicate of #6910. The related issue for instance vars was fixed, but it remains a problem for ClassVar[Callable[...]].
Activity
sobolevn commentedon Sep 17, 2021
This is a known problem / feature. The same happens without
ClassVaras well:Related #9489
thejcannon commentedon Jan 31, 2022
FWIW #9489 was fixed by #10548. But this appears to still be an issue
AlexWaygood commentedon Mar 26, 2022
Closing as a duplicate of #6910 (which is not about
ClassVars, but is the same but nonetheless)h4l commentedon Jun 15, 2025
Can we re-open this? It's not fixed and not a duplicate of #6910. The related issue for instance vars was fixed, but it remains a problem for
ClassVar[Callable[...]].thejcannon commentedon Jun 15, 2025
Blast from the past!
FWIW there's a recent ongoing Discourse discussion about this
https://discuss.python.org/t/when-should-we-assume-callable-types-are-method-descriptors/92938