Skip to content

Commit

Permalink
Fix inheriting from generic @Frozen attrs class (#15700)
Browse files Browse the repository at this point in the history
Fixes #15658.
  • Loading branch information
ikonst authored Aug 12, 2023
1 parent 89c6596 commit 0e4521a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def _make_frozen(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute])
else:
# This variable belongs to a super class so create new Var so we
# can modify it.
var = Var(attribute.name, ctx.cls.info[attribute.name].type)
var = Var(attribute.name, attribute.init_type)
var.info = ctx.cls.info
var._fullname = f"{ctx.cls.info.fullname}.{var.name}"
ctx.cls.info.names[var.name] = SymbolTableNode(MDEF, var)
Expand Down
24 changes: 24 additions & 0 deletions test-data/unit/check-plugin-attrs.test
Original file line number Diff line number Diff line change
Expand Up @@ -2253,3 +2253,27 @@ c = attrs.assoc(c, name=42) # E: Argument "name" to "assoc" of "C" has incompat

[builtins fixtures/plugin_attrs.pyi]
[typing fixtures/typing-medium.pyi]

[case testFrozenInheritFromGeneric]
from typing import Generic, TypeVar
from attrs import field, frozen

T = TypeVar('T')

def f(s: str) -> int:
...

@frozen
class A(Generic[T]):
x: T
y: int = field(converter=f)

@frozen
class B(A[int]):
pass

b = B(42, 'spam')
reveal_type(b.x) # N: Revealed type is "builtins.int"
reveal_type(b.y) # N: Revealed type is "builtins.int"

[builtins fixtures/plugin_attrs.pyi]

0 comments on commit 0e4521a

Please sign in to comment.