Skip to content

Commit 0e4521a

Browse files
authored
Fix inheriting from generic @Frozen attrs class (#15700)
Fixes #15658.
1 parent 89c6596 commit 0e4521a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

mypy/plugins/attrs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ def _make_frozen(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute])
803803
else:
804804
# This variable belongs to a super class so create new Var so we
805805
# can modify it.
806-
var = Var(attribute.name, ctx.cls.info[attribute.name].type)
806+
var = Var(attribute.name, attribute.init_type)
807807
var.info = ctx.cls.info
808808
var._fullname = f"{ctx.cls.info.fullname}.{var.name}"
809809
ctx.cls.info.names[var.name] = SymbolTableNode(MDEF, var)

test-data/unit/check-plugin-attrs.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,3 +2253,27 @@ c = attrs.assoc(c, name=42) # E: Argument "name" to "assoc" of "C" has incompat
22532253

22542254
[builtins fixtures/plugin_attrs.pyi]
22552255
[typing fixtures/typing-medium.pyi]
2256+
2257+
[case testFrozenInheritFromGeneric]
2258+
from typing import Generic, TypeVar
2259+
from attrs import field, frozen
2260+
2261+
T = TypeVar('T')
2262+
2263+
def f(s: str) -> int:
2264+
...
2265+
2266+
@frozen
2267+
class A(Generic[T]):
2268+
x: T
2269+
y: int = field(converter=f)
2270+
2271+
@frozen
2272+
class B(A[int]):
2273+
pass
2274+
2275+
b = B(42, 'spam')
2276+
reveal_type(b.x) # N: Revealed type is "builtins.int"
2277+
reveal_type(b.y) # N: Revealed type is "builtins.int"
2278+
2279+
[builtins fixtures/plugin_attrs.pyi]

0 commit comments

Comments
 (0)