Ravenports generated: 08 Oct 2019 11:13
[ravenports.git] / bucket_73 / python-singledispatch
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               python-singledispatch
4 VERSION=                3.4.0.3
5 KEYWORDS=               python devel
6 VARIANTS=               py27 py36 py37
7 SDESC[py36]=            Backport of single-dispatch functions (PY 36)
8 SDESC[py37]=            Backport of single-dispatch functions (PY 37)
9 SDESC[py27]=            Backport of single-dispatch functions (PY 27)
10 HOMEPAGE=               http://docs.python.org/3/library/functools.html#functools.singledispatch
11 CONTACT=                Python_Automaton[python@ironwolf.systems]
12
13 DOWNLOAD_GROUPS=        main
14 SITES[main]=            PYPI/s/singledispatch
15 DISTFILE[1]=            singledispatch-3.4.0.3.tar.gz:main
16 DF_INDEX=               1
17 SPKGS[py36]=            single
18 SPKGS[py37]=            single
19 SPKGS[py27]=            single
20
21 OPTIONS_AVAILABLE=      PY27 PY36 PY37
22 OPTIONS_STANDARD=       none
23 VOPTS[py36]=            PY27=OFF PY36=ON PY37=OFF
24 VOPTS[py37]=            PY27=OFF PY36=OFF PY37=ON
25 VOPTS[py27]=            PY27=ON PY36=OFF PY37=OFF
26
27 DISTNAME=               singledispatch-3.4.0.3
28
29 GENERATED=              yes
30
31 [PY36].BUILDRUN_DEPENDS_ON=             python-six:single:py36
32 [PY36].USES_ON=                         python:py36
33
34 [PY37].BUILDRUN_DEPENDS_ON=             python-six:single:py37
35 [PY37].USES_ON=                         python:py37
36
37 [PY27].BUILDRUN_DEPENDS_ON=             python-six:single:py27
38 [PY27].USES_ON=                         python:py27
39
40 [FILE:3046:descriptions/desc.single]
41 ==============
42 singledispatch
43 ==============
44
45 `PEP 443 <http://www.python.org/dev/peps/pep-0443/>`_ proposed to expose
46 a mechanism in the ``functools`` standard library module in Python 3.4
47 that provides a simple form of generic programming known as
48 single-dispatch generic functions.
49
50 This library is a backport of this functionality to Python 2.6 - 3.3.
51
52 To define a generic function, decorate it with the ``@singledispatch``
53 decorator. Note that the dispatch happens on the type of the first
54 argument, create your function accordingly::
55
56   >>> from singledispatch import singledispatch
57   >>> @singledispatch
58   ... def fun(arg, verbose=False):
59   ...     if verbose:
60   ...         print("Let me just say,", end=" ")
61   ...     print(arg)
62
63 To add overloaded implementations to the function, use the
64 ``register()`` attribute of the generic function. It is a decorator,
65 taking a type parameter and decorating a function implementing the
66 operation for that type::
67
68   >>> @fun.register(int)
69   ... def _(arg, verbose=False):
70   ...     if verbose:
71   ...         print("Strength in numbers, eh?", end=" ")
72   ...     print(arg)
73   ...
74   >>> @fun.register(list)
75   ... def _(arg, verbose=False):
76   ...     if verbose:
77   ...         print("Enumerate this:")
78   ...     for i, elem in enumerate(arg):
79   ...         print(i, elem)
80
81 To enable registering lambdas and pre-existing functions, the
82 ``register()`` attribute can be used in a functional form::
83
84   >>> def nothing(arg, verbose=False):
85   ...     print("Nothing.")
86   ...
87   >>> fun.register(type(None), nothing)
88
89 The ``register()`` attribute returns the undecorated function which
90 enables decorator stacking, pickling, as well as creating unit tests for
91 each variant independently::
92
93   >>> @fun.register(float)
94   ... @fun.register(Decimal)
95   ... def fun_num(arg, verbose=False):
96   ...     if verbose:
97   ...         print("Half of your number:", end=" ")
98   ...     print(arg / 2)
99   ...
100   >>> fun_num is fun
101   False
102
103 When called, the generic function dispatches on the type of the first
104 argument::
105
106   >>> fun("Hello, world.")
107   Hello, world.
108   >>> fun("test.", verbose=True)
109   Let me just say, test.
110   >>> fun(42, verbose=True)
111   Strength in numbers, eh? 42
112   >>> fun(['spam', 'spam', 'eggs', 'spam'], verbose=True)
113   Enumerate this:
114   0 spam
115   1 spam
116   2 eggs
117   3 spam
118   >>> fun(None)
119   Nothing.
120   >>> fun(1.23)
121   0.615
122
123 Where there is no registered implementation for a specific type, its
124 method resolution order is used to find a more generic implementation.
125 The original function decorated with ``@singledispatch`` is registered
126 for the base ``object`` type, which means it is used if no better
127 implementation is found.
128
129 To check which implementation will the generic function choose for
130 a given type, use the ``dispatch()`` attribute::
131
132   >>> fun.dispatch(float)
133   <function fun_num at 0x1035a2840>
134   >>> fun.dispatch(dict)    # note: default implementation
135   <function fun at 0x103fe0000>
136
137 To access all registered implementations, use the read-only ``registry``
138 attribute::
139
140   >>> fun.registry.keys()
141
142
143 [FILE:108:distinfo]
144 5b06af87df13818d14f08a028e42f566640aef80805c3b50c5056b086e3c2b9c         9529 singledispatch-3.4.0.3.tar.gz
145