From 3b9a4c53ba669ac7012a995fbc3a34d8cfff1684 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Tue, 18 Jul 2023 01:24:45 -0400 Subject: [PATCH 1/3] Add regression test --- test-data/unit/check-plugin-attrs.test | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test-data/unit/check-plugin-attrs.test b/test-data/unit/check-plugin-attrs.test index 913584224764..6124c1627b8d 100644 --- a/test-data/unit/check-plugin-attrs.test +++ b/test-data/unit/check-plugin-attrs.test @@ -2250,3 +2250,22 @@ 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 frozen + +T = TypeVar('T') + +@frozen +class A(Generic[T]): + x: T + +@frozen +class B(A[int]): + pass + +b = B(42) +reveal_type(b.x) # N: Revealed type is "builtins.int" + +[builtins fixtures/plugin_attrs.pyi] From cb188b4750dd9368a5158be007416da8aabf6697 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Tue, 18 Jul 2023 01:25:01 -0400 Subject: [PATCH 2/3] Fix --- mypy/plugins/attrs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/plugins/attrs.py b/mypy/plugins/attrs.py index 0f748cc140e8..d444c18852dd 100644 --- a/mypy/plugins/attrs.py +++ b/mypy/plugins/attrs.py @@ -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) From bdda3500c1d6e2b91ae17522e3abcbfc0ec68b53 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Sun, 30 Jul 2023 20:37:30 -0400 Subject: [PATCH 3/3] add converter to testFrozenInheritFromGeneric --- test-data/unit/check-plugin-attrs.test | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-plugin-attrs.test b/test-data/unit/check-plugin-attrs.test index 6124c1627b8d..078e272abda6 100644 --- a/test-data/unit/check-plugin-attrs.test +++ b/test-data/unit/check-plugin-attrs.test @@ -2253,19 +2253,24 @@ c = attrs.assoc(c, name=42) # E: Argument "name" to "assoc" of "C" has incompat [case testFrozenInheritFromGeneric] from typing import Generic, TypeVar -from attrs import frozen +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) +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]