-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest_typecheck.py
More file actions
110 lines (76 loc) · 2.39 KB
/
Copy pathtest_typecheck.py
File metadata and controls
110 lines (76 loc) · 2.39 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from ..compat import PY3
from ..typecheck import compatible
from ..typed_signature import TypedSignature
def test_compatible_when_equal():
@TypedSignature
def foo(a, b, c): # pragma: nocover
pass
assert compatible(foo, foo)
@TypedSignature
def bar(): # pragma: nocover
pass
assert compatible(bar, bar)
def test_disallow_new_or_missing_positionals():
@TypedSignature
def foo(a, b): # pragma: nocover
pass
@TypedSignature
def bar(a): # pragma: nocover
pass
assert not compatible(foo, bar)
assert not compatible(bar, foo)
def test_disallow_remove_defaults():
@TypedSignature
def iface(a, b=3): # pragma: nocover
pass
@TypedSignature
def impl(a, b): # pragma: nocover
pass
assert not compatible(impl, iface)
def test_disallow_reorder_positionals():
@TypedSignature
def foo(a, b): # pragma: nocover
pass
@TypedSignature
def bar(b, a): # pragma: nocover
pass
assert not compatible(foo, bar)
assert not compatible(bar, foo)
def test_allow_new_params_with_defaults_no_kwonly():
@TypedSignature
def iface(a, b, c): # pragma: nocover
pass
@TypedSignature
def impl(a, b, c, d=3, e=5, f=5): # pragma: nocover
pass
assert compatible(impl, iface)
assert not compatible(iface, impl)
def test_first_argument_name():
assert TypedSignature(lambda x, y, z: x).first_argument_name == "x"
assert TypedSignature(lambda: 0).first_argument_name is None
def test_typed_signature_repr():
@TypedSignature
def foo(a, b, c): # pragma: nocover
pass
expected = "<TypedSignature type=function, signature=(a, b, c)>"
assert repr(foo) == expected
@TypedSignature
@property
def bar(a, b, c): # pragma: nocover
pass
expected = "<TypedSignature type=property, signature=(a, b, c)>"
assert repr(bar) == expected
@TypedSignature
@classmethod
def baz(a, b, c): # pragma: nocover
pass
expected = "<TypedSignature type=classmethod, signature=(a, b, c)>"
assert repr(baz) == expected
@TypedSignature
@staticmethod
def fizz(a, b, c): # pragma: nocover
pass
expected = "<TypedSignature type=staticmethod, signature=(a, b, c)>"
assert repr(fizz) == expected
if PY3: # pragma: nocover-py2
from ._py3_typecheck_tests import * # noqa