Skip to content

[1.0 backport] Fix AttrsInstance protocol check with cache (#14551) #14558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
==