Skip to content

Commit

Permalink
Fix AttrsInstance protocol check with cache (#14551)
Browse files Browse the repository at this point in the history
Use correct fullname for `__attrs_attrs__` ClassVar to fix issue with
warm cache.
Closes #14099
  • Loading branch information
cdce8p authored Jan 30, 2023
1 parent 8af3af3 commit 8e9f89a
Show file tree
Hide file tree
Showing 2 changed files with 35 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 @@ -828,7 +828,7 @@ def _add_attrs_magic_attribute(
ctx.cls,
MAGIC_ATTR_NAME,
TupleType(attributes_types, fallback=attributes_type),
fullname=f"{ctx.cls.fullname}.{attr_name}",
fullname=f"{ctx.cls.fullname}.{MAGIC_ATTR_NAME}",
override_allow_incompatible=True,
is_classvar=True,
)
Expand Down
34 changes: 34 additions & 0 deletions test-data/unit/fine-grained-attr.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,37 @@ A.__attrs_attrs__.b

[out]
==

[case magicAttributeConsistency2-only_when_cache]
[file c.py]
import attr

@attr.s
class Entry:
var: int = attr.ib()
[builtins fixtures/attr.pyi]

[file m.py]
from typing import Any, ClassVar, Protocol
from c import Entry

class AttrsInstance(Protocol):
__attrs_attrs__: ClassVar[Any]

def func(e: AttrsInstance) -> None: ...
func(Entry(2))

[file m.py.2]
from typing import Any, ClassVar, Protocol
from c import Entry

class AttrsInstance(Protocol):
__attrs_attrs__: ClassVar[Any]

def func(e: AttrsInstance) -> int:
return 2 # Change return type to force reanalysis

func(Entry(2))

[out]
==

0 comments on commit 8e9f89a

Please sign in to comment.