blob: f8b816a4e647f24bd9ed909c22aee6cc8bdf5c82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# pylint: disable=missing-docstring,import-error,unused-import,assignment-from-no-return
from __future__ import print_function
from UNINFERABLE import uninferable_decorator, uninferable_func
try:
from functools import singledispatch
except ImportError:
from singledispatch import singledispatch
my_single_dispatch = singledispatch # pylint: disable=invalid-name
@singledispatch
def func(arg):
return arg
@func.register(str)
def _(arg):
return 42
@func.register(float)
@func.register(int)
def _(arg):
return 42
@my_single_dispatch
def func2(arg):
return arg
@func2.register(int)
def _(arg):
return 42
@singledispatch
def with_extra_arg(arg, verbose=False):
if verbose:
print(arg)
return arg
@with_extra_arg.register(str)
def _(arg, verbose=False):
return arg[::-1]
@uninferable_decorator
def uninferable(arg):
return 2*arg
@uninferable.register(str)
def bad_single_dispatch(arg):
return arg
@uninferable_func.register(str)
def test(arg):
return arg
|