Closed as not planned
Closed as not planned
Description
Bug Report
On 0.960, if an attribute is typed as a dataclasses.InitVar
and later tries to assign an attribute with the same name, mypy will complain on the assignment statement that the dataclass has no such attribute.
This does not occur on 0.950.
To Reproduce
import dataclasses
from dataclasses import InitVar
@dataclasses.dataclass
class Foo:
a: int
b: InitVar[int]
def __post_init__(self, b: int) -> None:
self.b = self.a + 1
$ pipx run --spec mypy==0.950 mypy --strict script.py
Success: no issues found in 1 source file
$ pipx run --spec mypy==0.960 mypy --strict script.py
script.py: note: In member "__post_init__" of class "Foo":
script.py:11:9: error: "Foo" has no attribute "b" [attr-defined]
self.b = self.a + 1
^
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
I expected that mypy would not complain about an assignment just because it shares the same name as an InitVar
.
Actual Behavior
mypy warns the user that the attribute does not exists in an assignment expression.
Your Environment
- Mypy version used: 0.960
- Mypy command-line flags:
--strict
- Python version used: 3.10
- Operating system and version: macOS 12.3.1