Functional Classes

functools.singledispatchmethod()

Define a generic method dispatching on the first argument after self or cls. Register specializations on the descriptor.

Formal Syntax & Structure

python syntaxpython
functools.singledispatchmethod(func)

Parameters & Attributes

NameTypeDescription
funccallableCallable applied by the operation.

Return Value

descriptor

The descriptor result described above.

Working Example

Example Snippetpython
import functoolsclass C: @functools.singledispatchmethod def show(self,x): return "other" @show.register(int) def _(self,x): return "int"print((C().show(2),C().show("x")))
Python Reference