Python Glossary Русский

Python 3.11+typingfunction

typing.get_overloads

introspection

Return the list of registered @overload implementations of a function (3.11+).

Syntax

typing.get_overloads(func)

Pass the final implementation function, not an @overload stub; with no overloads registered you get an empty list. Before Python 3.11 overloads were invisible at runtime — now @overload records them, and typing.clear_overloads() clears the registry.

Examples

from typing import overload, get_overloads, clear_overloads
print(get_overloads(len) == [])   # → True
from typing import overload, get_overloads, clear_overloads
@overload
def parse(x: int) -> int: ...
@overload
def parse(x: str) -> str: ...
def parse(x): return x   # единственная реальная реализация
print(len(get_overloads(parse)))   # → 2
print(get_overloads(parse)[0].__annotations__['x'] is int)   # → True
print(parse('ok'))   # → ok
clear_overloads()
print(get_overloads(parse) == [])   # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy