typing.get_protocol_members
Prev: typing.get_overloads | Up: typing | Next: typing.get_type_hints
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.get_protocol_members
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import get_protocol_members
Signature & Overview
typing.get_protocol_members(tp: type, /) -> frozenset[str]
Return the set of members defined in a Protocol.
Usage
from typing import Protocol, get_protocol_members
class SizedLike(Protocol):
def __len__(self) -> int: ...
assert get_protocol_members(SizedLike) == frozenset({"__len__"})
Gotchas
- Requires Python 3.13+: Returns the exact
frozensetof attribute/method names required by aProtocol.
REPL Inspect
from typing import get_protocol_members
help(get_protocol_members)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/get_overloads Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/get_type_hints Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing