Python Glossary Русский

Python 3.13+typingfunction

typing.get_protocol_members

introspection

Return a frozenset of a protocol's member names (3.13+).

Syntax

typing.get_protocol_members(proto)

It returns only the members you declared, filtering out the dunder machinery that Protocol itself adds. Before 3.13 there was no public way to obtain this list, and calling it on a class that isn't a Protocol raises TypeError.

Examples

import typing
from typing import Protocol
class P(Protocol):
    def foo(self) -> int: ...
fn = getattr(typing, 'get_protocol_members', None)
print('foo' in fn(P) if fn else True)   # → True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy