-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
Under structural subtyping with a variable narrowed to Final
, it's possible to modify the var contents
To Reproduce
# poc.py
from dataclasses import dataclass
from typing import Protocol, Final
@dataclass
class FinalY:
y: Final[int] = 0
class Y(Protocol):
y: int
def f(x: Y) -> Y:
x.y = 42
return x
print(f(FinalY(17)))
$ mypy poc.py
Success: no issues found in 1 source file
$ python poc.py
FinalY(y=42)
Expected Behavior
Class with a variable Final[T]
should not be a structural subtype of a protocol with variable T
Your Environment
- Mypy version used: 0.910
- Python version used: 3.9.6
This bug was inspired by @erictraut's example of how to deal with other kind of issue
KotlinIsland and DetachHead