Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callable ClassVar is incorrectly treated as a method #11077

Closed
NeilGirdhar opened this issue Sep 9, 2021 · 3 comments
Closed

Callable ClassVar is incorrectly treated as a method #11077

NeilGirdhar opened this issue Sep 9, 2021 · 3 comments
Labels
bug mypy got something wrong

Comments

@NeilGirdhar
Copy link
Contributor

from typing import Callable, MutableMapping, ClassVar

class C:
    x: ClassVar[Callable[[], MutableMapping]] = dict
    def f(self) -> MutableMapping:
        return self.x()  

c = C()
print(c.f())

Gives

a.py:6: error: Attribute function "x" with type "Callable[[], MutableMapping[Any, Any]]" does not accept self argument
@NeilGirdhar NeilGirdhar added the bug mypy got something wrong label Sep 9, 2021
@sobolevn
Copy link
Member

This is a known problem / feature. The same happens without ClassVar as well:

from typing import Callable, MutableMapping, ClassVar

class C:
    x: Callable[[], MutableMapping] = dict
    def f(self) -> MutableMapping:
        # error: Attribute function "x" with type "Callable[[], MutableMapping[Any, Any]]" does not accept self argument
        return self.x()

c = C()
print(c.f())

Related #9489

@thejcannon
Copy link
Contributor

FWIW #9489 was fixed by #10548. But this appears to still be an issue

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 26, 2022

Closing as a duplicate of #6910 (which is not about ClassVars, but is the same but nonetheless)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

4 participants