Skip to content
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

Use __protocol_attrs__ #631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Use `__protocol_attrs__` for more robust detection of
the members of a `Protocol` (#631)
- Remove more old special cases and improve robustness of
annotation parsing (#630)
- Remove dependency on `typing_inspect` (#629)
Expand Down
2 changes: 2 additions & 0 deletions pyanalyze/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ def _extract_protocol_members(typ: type) -> Set[str]:
or is_typing_name(typ, "Protocol")
):
return set()
if hasattr(typ, "__protocol_attrs__"):
return typ.__protocol_attrs__
members = set(typ.__dict__) - EXCLUDED_PROTOCOL_MEMBERS
# Starting in 3.10 __annotations__ always exists on types
if sys.version_info >= (3, 10) or hasattr(typ, "__annotations__"):
Expand Down