PyDocs

Nav

Functional Programming Modules

singledispatch

functools

decorator · Added in 3.4 (source)
  • @singledispatch
Single-dispatch generic function decorator.

Transforms a function into a generic function, which can have different
behaviours depending upon the type of its first argument. The decorated
function acts as the default implementation, and additional
implementations can be registered using the register() attribute of the
generic function.
Changed in 3.7, 3.11
  • 3.7: The register() attribute now supports using type annotations.
  • 3.11: The register() attribute now supports typing.Union as a type annotation.
Members of singledispatch

r

register
To add overloaded implementations to the function, use the register() attribute of the generic function, which can be used as a decorator.
1 Example
>>> from functools import singledispatch
>>> @singledispatch
... def fun(arg, verbose=False):
...     if verbose:
...         print("Let me just say,", end=" ")
...     print(arg)
from the Python docs
See Also
No see-alsos for functools/singledispatch
0 Notes
No notes for singledispatch