Skip to content

Commit 61d6cad

Browse files
authored
[1.0 backport] Fix AttrsInstance protocol check with cache (#14551) (#14558)
1 parent 332616c commit 61d6cad

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

mypy/plugins/attrs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def _add_attrs_magic_attribute(
828828
ctx.cls,
829829
MAGIC_ATTR_NAME,
830830
TupleType(attributes_types, fallback=attributes_type),
831-
fullname=f"{ctx.cls.fullname}.{attr_name}",
831+
fullname=f"{ctx.cls.fullname}.{MAGIC_ATTR_NAME}",
832832
override_allow_incompatible=True,
833833
is_classvar=True,
834834
)

test-data/unit/fine-grained-attr.test

+34
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,37 @@ A.__attrs_attrs__.b
4646

4747
[out]
4848
==
49+
50+
[case magicAttributeConsistency2-only_when_cache]
51+
[file c.py]
52+
import attr
53+
54+
@attr.s
55+
class Entry:
56+
var: int = attr.ib()
57+
[builtins fixtures/attr.pyi]
58+
59+
[file m.py]
60+
from typing import Any, ClassVar, Protocol
61+
from c import Entry
62+
63+
class AttrsInstance(Protocol):
64+
__attrs_attrs__: ClassVar[Any]
65+
66+
def func(e: AttrsInstance) -> None: ...
67+
func(Entry(2))
68+
69+
[file m.py.2]
70+
from typing import Any, ClassVar, Protocol
71+
from c import Entry
72+
73+
class AttrsInstance(Protocol):
74+
__attrs_attrs__: ClassVar[Any]
75+
76+
def func(e: AttrsInstance) -> int:
77+
return 2 # Change return type to force reanalysis
78+
79+
func(Entry(2))
80+
81+
[out]
82+
==

0 commit comments

Comments
 (0)