Skip to content

Commit e7f0b6e

Browse files
authored
Merge pull request #13 from seequent/add-overload-method
Retire register() function in favour of Base.foo.register()
2 parents aad8cc2 + 3ed6ed4 commit e7f0b6e

File tree

6 files changed

+622
-180
lines changed

6 files changed

+622
-180
lines changed

README.rst

Lines changed: 186 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,190 @@ argument, create your function accordingly.
1616

1717
>>> from methoddispatch import singledispatch, register, SingleDispatch
1818

19+
>>> @singledispatch
20+
... def fun(arg, verbose=False):
21+
... if verbose:
22+
... print("Let me just say,", end=" ")
23+
... print(arg)
24+
25+
To add overloaded implementations to the function, use the
26+
27+
>>> @singledispatchmethod
28+
... def fun(arg, verbose=False):
29+
... if verbose:
30+
... print("Let me just say,", end=" ")
31+
... print(arg)
32+
33+
To add overloaded implementations to the function, use the
34+
35+
>>> @singledispatchmethod
36+
... def fun(arg, verbose=False):
37+
... if verbose:
38+
... print("Let me just say,", end=" ")
39+
... print(arg)
40+
41+
To add overloaded implementations to the function, use the
42+
43+
>>> @singledispatch
44+
... def fun(arg, verbose=False):
45+
... if verbose:
46+
... print("Let me just say,", end=" ")
47+
... print(arg)
48+
49+
To add overloaded implementations to the function, use the
50+
51+
>>> @singledispatch
52+
... def fun(arg, verbose=False):
53+
... if verbose:
54+
... print("Let me just say,", end=" ")
55+
... print(arg)
56+
57+
To add overloaded implementations to the function, use the
58+
59+
>>> @singledispatch
60+
... def fun(arg, verbose=False):
61+
... if verbose:
62+
... print("Let me just say,", end=" ")
63+
... print(arg)
64+
65+
To add overloaded implementations to the function, use the
66+
67+
>>> @singledispatchmethod
68+
... def fun(arg, verbose=False):
69+
... if verbose:
70+
... print("Let me just say,", end=" ")
71+
... print(arg)
72+
73+
To add overloaded implementations to the function, use the
74+
75+
>>> @singledispatch
76+
... def fun(arg, verbose=False):
77+
... if verbose:
78+
... print("Let me just say,", end=" ")
79+
... print(arg)
80+
81+
To add overloaded implementations to the function, use the
82+
83+
>>> @singledispatch
84+
... def fun(arg, verbose=False):
85+
... if verbose:
86+
... print("Let me just say,", end=" ")
87+
... print(arg)
88+
89+
To add overloaded implementations to the function, use the
90+
91+
>>> @singledispatch
92+
... def fun(arg, verbose=False):
93+
... if verbose:
94+
... print("Let me just say,", end=" ")
95+
... print(arg)
96+
97+
To add overloaded implementations to the function, use the
98+
99+
>>> @singledispatchmethod
100+
... def fun(arg, verbose=False):
101+
... if verbose:
102+
... print("Let me just say,", end=" ")
103+
... print(arg)
104+
105+
To add overloaded implementations to the function, use the
106+
107+
>>> @singledispatch
108+
... def fun(arg, verbose=False):
109+
... if verbose:
110+
... print("Let me just say,", end=" ")
111+
... print(arg)
112+
113+
To add overloaded implementations to the function, use the
114+
115+
>>> @singledispatch
116+
... def fun(arg, verbose=False):
117+
... if verbose:
118+
... print("Let me just say,", end=" ")
119+
... print(arg)
120+
121+
To add overloaded implementations to the function, use the
122+
123+
>>> @singledispatchmethod
124+
... def fun(arg, verbose=False):
125+
... if verbose:
126+
... print("Let me just say,", end=" ")
127+
... print(arg)
128+
129+
To add overloaded implementations to the function, use the
130+
131+
>>> @singledispatch
132+
... def fun(arg, verbose=False):
133+
... if verbose:
134+
... print("Let me just say,", end=" ")
135+
... print(arg)
136+
137+
To add overloaded implementations to the function, use the
138+
139+
>>> @singledispatch
140+
... def fun(arg, verbose=False):
141+
... if verbose:
142+
... print("Let me just say,", end=" ")
143+
... print(arg)
144+
145+
To add overloaded implementations to the function, use the
146+
147+
>>> @singledispatch
148+
... def fun(arg, verbose=False):
149+
... if verbose:
150+
... print("Let me just say,", end=" ")
151+
... print(arg)
152+
153+
To add overloaded implementations to the function, use the
154+
155+
>>> @singledispatchmethod
156+
... def fun(arg, verbose=False):
157+
... if verbose:
158+
... print("Let me just say,", end=" ")
159+
... print(arg)
160+
161+
To add overloaded implementations to the function, use the
162+
163+
>>> @singledispatch
164+
... def fun(arg, verbose=False):
165+
... if verbose:
166+
... print("Let me just say,", end=" ")
167+
... print(arg)
168+
169+
To add overloaded implementations to the function, use the
170+
171+
>>> @singledispatch
172+
... def fun(arg, verbose=False):
173+
... if verbose:
174+
... print("Let me just say,", end=" ")
175+
... print(arg)
176+
177+
To add overloaded implementations to the function, use the
178+
179+
>>> @singledispatch
180+
... def fun(arg, verbose=False):
181+
... if verbose:
182+
... print("Let me just say,", end=" ")
183+
... print(arg)
184+
185+
To add overloaded implementations to the function, use the
186+
187+
>>> @singledispatchmethod
188+
... def fun(arg, verbose=False):
189+
... if verbose:
190+
... print("Let me just say,", end=" ")
191+
... print(arg)
192+
193+
To add overloaded implementations to the function, use the
194+
195+
>>> @singledispatchmethod
196+
... def fun(arg, verbose=False):
197+
... if verbose:
198+
... print("Let me just say,", end=" ")
199+
... print(arg)
200+
201+
To add overloaded implementations to the function, use the
202+
19203
>>> @singledispatch
20204
... def fun(arg, verbose=False):
21205
... if verbose:
@@ -191,11 +375,11 @@ shown below::
191375
... def foo_float(self, bar: float):
192376
... return 'float'
193377

194-
In Python 3.6 and earlier, the ``SingleDispatch`` class uses a
378+
In Python 3.5 and earlier, the ``SingleDispatch`` class uses a
195379
meta-class ``SingleDispatchMeta`` to manage the dispatch registries.
196380
However in Python 3.6 and later the ``__init_subclass__`` method is used
197381
instead. If your class also inherits from an ABC interface you can use
198-
the ``SingleDispatchABCMeta`` metaclass in Python 3.6 and earlier.
382+
the ``SingleDispatchABCMeta`` metaclass in Python 3.5 and earlier.
199383

200384
Finally, accessing the method ``foo`` via a class will use the dispatch
201385
registry for that class::

0 commit comments

Comments
 (0)