File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -755,8 +755,10 @@ def is_instance_var(var: Var) -> bool:
755755 var .name in var .info .names
756756 and var .info .names [var .name ].node is var
757757 and not var .is_classvar
758- # variables without annotations are treated as classvar
759- and not var .is_inferred
758+ # variables without annotations are treated as classvar,
759+ # but not when they are annotated as `a: Final = 1`,
760+ # since it will be inferenced as `Literal[1]`
761+ and not (var .is_inferred and not var .is_final )
760762 )
761763
762764
Original file line number Diff line number Diff line change @@ -2553,3 +2553,18 @@ class X(metaclass=DCMeta):
25532553class Y(X):
25542554 a: int # E: Covariant override of a mutable attribute (base class "X" defined the type as "Optional[int]", expression has type "int")
25552555[builtins fixtures/tuple.pyi]
2556+
2557+
2558+ [case testFrozenWithFinal]
2559+ from dataclasses import dataclass
2560+ from typing import Final
2561+
2562+ @dataclass(frozen=True)
2563+ class My:
2564+ a: Final = 1
2565+ b: Final[int] = 2
2566+
2567+ m = My()
2568+ reveal_type(m.a) # N: Revealed type is "Literal[1]?"
2569+ reveal_type(m.b) # N: Revealed type is "builtins.int"
2570+ [builtins fixtures/tuple.pyi]
You can’t perform that action at this time.
0 commit comments