Return the set of members defined in a Protocol. Example:: >>> from typing import Protocol, get_protocol_members >>> class P(Protocol): ... def a(self) -> str: ... ... b: int >>> get_protocol_members(P) == frozenset({'a', 'b'}) True
(tp: type, /)
| 3857 | |
| 3858 | |
| 3859 | def get_protocol_members(tp: type, /) -> frozenset[str]: |
| 3860 | """Return the set of members defined in a Protocol. |
| 3861 | |
| 3862 | Example:: |
| 3863 | |
| 3864 | >>> from typing import Protocol, get_protocol_members |
| 3865 | >>> class P(Protocol): |
| 3866 | ... def a(self) -> str: ... |
| 3867 | ... b: int |
| 3868 | >>> get_protocol_members(P) == frozenset({'a', 'b'}) |
| 3869 | True |
| 3870 | |
| 3871 | Raise a TypeError for arguments that are not Protocols. |
| 3872 | """ |
| 3873 | if not is_protocol(tp): |
| 3874 | raise TypeError(f'{tp!r} is not a Protocol') |
| 3875 | return frozenset(tp.__protocol_attrs__) |
| 3876 | |
| 3877 | |
| 3878 | def __getattr__(attr): |
searching dependent graphs…