forked from cython/cython
-
Notifications
You must be signed in to change notification settings - Fork 1
/
default_optional_gh5643.py
86 lines (71 loc) · 1.74 KB
/
default_optional_gh5643.py
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
# mode: run
# tag: pep484, warnings, pure3.6
# ticket: 5643
# cython: language_level=3
try:
from typing import Optional
except ImportError:
pass
# no crash
def gh5643_optional(a: Optional[int] = None):
"""
>>> gh5643_optional()
True
>>> gh5643_optional(1)
False
"""
return a is None
# no crash
def gh5643_int_untyped(a: int = 1, b = None):
"""
>>> gh5643_int_untyped(2)
(False, True)
>>> gh5643_int_untyped(2, None)
(False, True)
>>> gh5643_int_untyped(1, 3)
(True, False)
"""
return a == 1, b is None
# used to crash
def gh5643_int_int_none(a: int = 1, b: int = None): # should warn about missing "Optional[]"
"""
>>> gh5643_int_int_none()
(True, True)
>>> gh5643_int_int_none(2, 3)
(False, False)
"""
return a == 1, b is None
def gh5643_int_int_integer(a: int = 1, b: int = 3):
"""
>>> gh5643_int_int_integer()
(True, True)
>>> gh5643_int_int_integer(2, 3)
(False, True)
"""
return a == 1, b == 3
# used to crash
def gh5643_int_optional_none(a: int = 1, b: Optional[int] = None):
"""
>>> gh5643_int_optional_none()
(True, True)
>>> gh5643_int_optional_none(2)
(False, True)
>>> gh5643_int_optional_none(2, 3)
(False, False)
"""
return a == 1, b is None
def gh5643_int_optional_integer(a: int = 1, b: Optional[int] = 2):
"""
>>> gh5643_int_optional_integer()
(True, True)
>>> gh5643_int_optional_integer(2)
(False, True)
>>> gh5643_int_optional_integer(2, 3)
(False, False)
>>> gh5643_int_optional_integer(2, 2)
(False, True)
"""
return a == 1, b == 2
_WARNINGS = """
37:36: PEP-484 recommends 'typing.Optional[...]' for arguments that can be None.
"""