1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
3 NAMEBASE= python-singledispatch
7 SDESC[py38]= Backport of single-dispatch functions (PY38)
8 SDESC[py39]= Backport of single-dispatch functions (PY39)
9 HOMEPAGE= https://github.com/jaraco/singledispatch
10 CONTACT= Python_Automaton[python@ironwolf.systems]
13 SITES[main]= PYPIWHL/a2/7d/97e7f80c04be35ec0f73228c0b1c9a868ef5cb473101e639dd058e4106c0
14 DISTFILE[1]= singledispatch-3.6.0-py2.py3-none-any.whl:main
19 OPTIONS_AVAILABLE= PY38 PY39
20 OPTIONS_STANDARD= none
21 VOPTS[py38]= PY38=ON PY39=OFF
22 VOPTS[py39]= PY38=OFF PY39=ON
24 DISTNAME= singledispatch-3.6.0.dist-info
28 [PY38].RUN_DEPENDS_ON= python-six:single:py38
29 [PY38].USES_ON= python:py38,wheel
31 [PY39].RUN_DEPENDS_ON= python-six:single:py39
32 [PY39].USES_ON= python:py39,wheel
34 [FILE:2963:descriptions/desc.single]
39 :alt: Code style: Black
41 [PEP 443] proposed to expose
42 a mechanism in the functools standard library module in Python 3.4
43 that provides a simple form of generic programming known as
44 single-dispatch generic functions.
46 This library is a backport of this functionality to Python 2.6 - 3.3.
48 To define a generic function, decorate it with the ``@singledispatch``
49 decorator. Note that the dispatch happens on the type of the first
50 argument, create your function accordingly::
52 >>> from singledispatch import singledispatch
54 ... def fun(arg, verbose=False):
56 ... print("Let me just say,", end=" ")
59 To add overloaded implementations to the function, use the
60 ``register()`` attribute of the generic function. It is a decorator,
61 taking a type parameter and decorating a function implementing the
62 operation for that type::
64 >>> @fun.register(int)
65 ... def _(arg, verbose=False):
67 ... print("Strength in numbers, eh?", end=" ")
70 >>> @fun.register(list)
71 ... def _(arg, verbose=False):
73 ... print("Enumerate this:")
74 ... for i, elem in enumerate(arg):
77 To enable registering lambdas and pre-existing functions, the
78 ``register()`` attribute can be used in a functional form::
80 >>> def nothing(arg, verbose=False):
83 >>> fun.register(type(None), nothing)
85 The ``register()`` attribute returns the undecorated function which
86 enables decorator stacking, pickling, as well as creating unit tests for
87 each variant independently::
89 >>> @fun.register(float)
90 ... @fun.register(Decimal)
91 ... def fun_num(arg, verbose=False):
93 ... print("Half of your number:", end=" ")
99 When called, the generic function dispatches on the type of the first
102 >>> fun("Hello, world.")
104 >>> fun("test.", verbose=True)
105 Let me just say, test.
106 >>> fun(42, verbose=True)
107 Strength in numbers, eh? 42
108 >>> fun(['spam', 'spam', 'eggs', 'spam'], verbose=True)
119 Where there is no registered implementation for a specific type, its
120 method resolution order is used to find a more generic implementation.
121 The original function decorated with ``@singledispatch is registered
122 for the base object`` type, which means it is used if no better
123 implementation is found.
125 To check which implementation will the generic function choose for
126 a given type, use the ``dispatch()`` attribute::
128 >>> fun.dispatch(float)
129 <function fun_num at 0x1035a2840>
130 >>> fun.dispatch(dict) # note: default implementation
131 <function fun at 0x103fe0000>
133 To access all registered implementations, use the read-only registry
138 ca602b0a8389aa93e3b183f57f29edc6af202bef718c2ec53a38ef25ccc5867e 9496 singledispatch-3.6.0-py2.py3-none-any.whl