Ravenports generated: 21 Feb 2021 14:41
[ravenports.git] / bucket_73 / python-singledispatch
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               python-singledispatch
4 VERSION=                3.6.0
5 KEYWORDS=               python
6 VARIANTS=               py38 py39
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]
11
12 DOWNLOAD_GROUPS=        main
13 SITES[main]=            PYPIWHL/a2/7d/97e7f80c04be35ec0f73228c0b1c9a868ef5cb473101e639dd058e4106c0
14 DISTFILE[1]=            singledispatch-3.6.0-py2.py3-none-any.whl:main
15 DF_INDEX=               1
16 SPKGS[py38]=            single
17 SPKGS[py39]=            single
18
19 OPTIONS_AVAILABLE=      PY38 PY39
20 OPTIONS_STANDARD=       none
21 VOPTS[py38]=            PY38=ON PY39=OFF
22 VOPTS[py39]=            PY38=OFF PY39=ON
23
24 DISTNAME=               singledispatch-3.6.0.dist-info
25
26 GENERATED=              yes
27
28 [PY38].RUN_DEPENDS_ON=                  python-six:single:py38
29 [PY38].USES_ON=                         python:py38,wheel
30
31 [PY39].RUN_DEPENDS_ON=                  python-six:single:py39
32 [PY39].USES_ON=                         python:py39,wheel
33
34 [FILE:2963:descriptions/desc.single]
35
36
37    :alt: tests
38
39    :alt: Code style: Black
40
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.
45
46 This library is a backport of this functionality to Python 2.6 - 3.3.
47
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::
51
52   >>> from singledispatch import singledispatch
53   >>> @singledispatch
54   ... def fun(arg, verbose=False):
55   ...     if verbose:
56   ...         print("Let me just say,", end=" ")
57   ...     print(arg)
58
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::
63
64   >>> @fun.register(int)
65   ... def _(arg, verbose=False):
66   ...     if verbose:
67   ...         print("Strength in numbers, eh?", end=" ")
68   ...     print(arg)
69   ...
70   >>> @fun.register(list)
71   ... def _(arg, verbose=False):
72   ...     if verbose:
73   ...         print("Enumerate this:")
74   ...     for i, elem in enumerate(arg):
75   ...         print(i, elem)
76
77 To enable registering lambdas and pre-existing functions, the
78 ``register()`` attribute can be used in a functional form::
79
80   >>> def nothing(arg, verbose=False):
81   ...     print("Nothing.")
82   ...
83   >>> fun.register(type(None), nothing)
84
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::
88
89   >>> @fun.register(float)
90   ... @fun.register(Decimal)
91   ... def fun_num(arg, verbose=False):
92   ...     if verbose:
93   ...         print("Half of your number:", end=" ")
94   ...     print(arg / 2)
95   ...
96   >>> fun_num is fun
97   False
98
99 When called, the generic function dispatches on the type of the first
100 argument::
101
102   >>> fun("Hello, world.")
103   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)
109   Enumerate this:
110   0 spam
111   1 spam
112   2 eggs
113   3 spam
114   >>> fun(None)
115   Nothing.
116   >>> fun(1.23)
117   0.615
118
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.
124
125 To check which implementation will the generic function choose for
126 a given type, use the ``dispatch()`` attribute::
127
128   >>> fun.dispatch(float)
129   <function fun_num at 0x1035a2840>
130   >>> fun.dispatch(dict)    # note: default implementation
131   <function fun at 0x103fe0000>
132
133 To access all registered implementations, use the read-only registry
134 attribute::
135
136
137 [FILE:120:distinfo]
138 ca602b0a8389aa93e3b183f57f29edc6af202bef718c2ec53a38ef25ccc5867e         9496 singledispatch-3.6.0-py2.py3-none-any.whl
139