Search notes:

Python standard library: functools

functools is used with and for callable objects.
functools is a wrapper module for the C module _functools.

singledispatch

singledispatch allows for a rudimentary function overloading:
from functools import singledispatch

@singledispatch
def F(a):
    print('F was called')

# Overload F for an int
@F.register(int)
def _(a):
    print('F was called, the argument is an int')

# Overload F for a str
@F.register(str)
def _(a):
    print('F was called, the argument is a str')

F([])
F(42)
F('Hello world')
See also PEP 443, PEP 3124 and pkgutil.simplegeneric.

See also

partial() creates a partial object.
The cache decorator.
itertools
standard library
toolz.

Index