Closed as not planned
Description
Bug Report
@hauntsaninja suggested I raise this.
To Reproduce
from dataclasses import dataclass
from typing import TypeVar, Generic, Any
T = TypeVar('T')
@dataclass()
class Element(Generic[T]):
value: T
parent: "Element[Any] | None" = None
def walk(self) -> None:
current: Element[Any] | None = self
while current := current.parent:
print(current.value)
Expected Behavior
$ pyright --version
pyright 1.1.393
$ pyright type_bug.py
0 errors, 0 warnings, 0 informations
Actual Behavior
$ mypy --version
mypy 1.14.1 (compiled: yes)
$ mypy type_bug.py
type_bug.py:14: error: Item "None" of "Element[Any] | None" has no attribute "parent" [union-attr]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.14.1
- Python version used: Python 3.12.1