PyDocs

Nav

Development Tools

overload

typing

decorator (source)
  • @overload
Decorator for overloaded functions/methods.

In a non-stub file, place two or more stub definitions for the same
function in a row, each decorated with @overload, followed
by an implementation.  The implementation should *not*
be decorated with @overload::

    @overload
    def utf8(value: None) -> None: ...
    @overload
    def utf8(value: bytes) -> bytes: ...
    @overload
    def utf8(value: str) -> bytes: ...
    def utf8(value):
        ...  # implementation goes here

In a stub file or in an abstract method (for example, in a Protocol definition),
the implementation may be omitted::

    @overload
    def utf8(value: None) -> None: ...
    @overload
    def utf8(value: bytes) -> bytes: ...
    @overload
    def utf8(value: str) -> bytes: ...

The overloads for a function can be retrieved at runtime using the
get_overloads() function.
Changed in 3.11
  • 3.11: Overloaded functions can now be introspected at runtime using get_overloads().
0 Examples
No examples for typing/overload.
See Also
No see-alsos for typing/overload
0 Notes
No notes for overload