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

Frozen dataclass with function fields incorrectly thinks first argument is self #10711

Closed
wrobell opened this issue Jun 25, 2021 · 9 comments
Closed
Labels
bug mypy got something wrong topic-dataclasses

Comments

@wrobell
Copy link

wrobell commented Jun 25, 2021

Example from #5485 works with mypy 0.902

from dataclasses import dataclass
from typing import Callable

@dataclass
class Repro:
    fn: Callable[[int], str]

r = Repro(fn=repr)
assert "1" == r.fn(1)

but let's change the dataclass to a frozen one

from dataclasses import dataclass
from typing import Callable

@dataclass(frozen=True)
class Repro:
    fn: Callable[[int], str]

r = Repro(fn=repr)
assert "1" == r.fn(1)

then

$ mypy t.py
t.py:9: error: Invalid self argument "Repro" to attribute function "fn" with type "Callable[[int], str]"
t.py:9: error: "str" not callable
Found 2 errors in 1 file (checked 1 source file)
@wrobell wrobell added the bug mypy got something wrong label Jun 25, 2021
@hauntsaninja
Copy link
Collaborator

Can you repro against master? I don't think #10548 made it into any of the recent releases

@wrobell
Copy link
Author

wrobell commented Jun 26, 2021

Works with mypy from master. Thanks.

@dimaqq
Copy link

dimaqq commented Aug 24, 2021

Ah, would be nice to have this released! 🙏🏿

@gwerbin
Copy link
Contributor

gwerbin commented Sep 20, 2021

Does #10548 also fix #9489 and #10353? They both look like dupes of #5485 but I'm not totally sure if they're all subtly different in some way.

@hauntsaninja
Copy link
Collaborator

Yup, those should be fixed

@wrobell
Copy link
Author

wrobell commented Apr 22, 2022

@hauntsaninja I am reopening this issue as it seems the fix fell through the crack. I checked all 0.9xx versions and the fix never went to any of the releases, it seems

https://mypy-play.net/?mypy=0.942&python=3.10&gist=ce6181fa059e3ea269f3356fd7af65be

@wrobell wrobell reopened this Apr 22, 2022
@hauntsaninja
Copy link
Collaborator

Unfortunately, #10548 was reverted in #11571

@erictraut
Copy link

It looks like this fix eventually made it in. I'm not able to repro the problem with mypy 1.5, so I think this is safe to close.

@hauntsaninja
Copy link
Collaborator

Fixed in #13400

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

No branches or pull requests

6 participants