Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
#103160 added an attribute__protocol_attrs__ that holds the names of all protocol attributes:
>>> from typing import Protocol>>> class X(Protocol):... a: int... def b(self) -> str: pass... >>> X.__protocol_attrs__{'b', 'a'}This is useful for code that needs to extract the names included in a Protocol at runtime. Previously, this was quite difficult, as you had to look at the class's__dict__ and__annotations__ directly and exclude a long list of internal attributes (e.g.https://github.com/quora/pyanalyze/blob/bd7f520adc2d8b098be657dfa514d1433bea3b0c/pyanalyze/checker.py#L428).
However, currently__protocol_attrs__ is an undocumented private attribute. I think we should either document it or add an introspection helper liketyping.get_protocol_attrs() that exposes it.