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 commented on Sep 17, 2021
This is a known problem / feature. The same happens without ClassVar as well:
Related #9489
thejcannon commented on Jan 31, 2022
FWIW #9489 was fixed by #10548. But this appears to still be an issue
AlexWaygood commented on Mar 26, 2022
Closing as a duplicate of #6910 (which is not about ClassVars, but is the same but nonetheless)
h4l commented on 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 commented on 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