MCPcopy Index your code
hub / github.com/python/cpython / get_protocol_members

Function get_protocol_members

Lib/typing.py:3859–3875  ·  view source on GitHub ↗

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, /)

Source from the content-addressed store, hash-verified

3857
3858
3859def 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
3878def __getattr__(attr):

Calls 1

is_protocolFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…