forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandline.test
180 lines (137 loc) · 3.75 KB
/
commandline.test
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
-- Test cases for invoking mypyc on the command line
--
-- These are slow -- do not add test cases unless you have a very good reason to do so.
[case testCompileMypyc]
# cmd: a.py b.py p/__init__.py p/q.py
import os.path
import p
import p.q
import a
import b
print('<main>', b.g(a.A()))
try:
a.f('')
except TypeError:
pass
else:
assert False
for x in [a, b, p, p.q]:
assert os.path.splitext(x.__file__)[1] != '.py'
[file z.py]
[file a.py]
import b
import c
from p import s
print('<a>', ord('A') == 65) # Test full builtins
class A:
def __init__(self) -> None:
self.x = 4
def f(x: int) -> b.B:
return b.B(x)
class B:
def __init__(self, x: int, y: str) -> None:
self.x = x
print('<a>', f(5).x)
print('<c>', c.foo())
assert s.bar(10) == 20
[file b.py]
import a
import p.q
class B:
def __init__(self, x: int) -> None:
self.x = x
def g(z: 'a.A') -> int:
return p.q.foo(z.x)
print('<b>', 'here')
[file c.py]
def foo() -> int:
return 10
[file p/__init__.py]
[file p/q.py]
import p.r
def foo(x: int) -> int:
return x*p.r.foo(x)
[file p/r.py]
def foo(x: int) -> int:
return x
[file p/s.py]
def bar(x: int) -> int:
return x*2
[out]
<b> here
<a> True
<a> 5
<c> 10
<main> 16
-- This test is here so we can turn it on when we get nervous about
-- this case, but is disabled for speed reasons.
[case testCompileMypycOne-skip]
# cmd: a.py
import os.path
import a
assert os.path.splitext(a.__file__)[1] != '.py'
assert a.f(10) == 100
[file a.py]
def f(x: int) -> int:
return x*x
[case testErrorOutput]
# cmd: test.py foo/__init__.py foo/bar.py
[file test.py]
from typing import List, Any
from typing_extensions import Final
from mypy_extensions import trait
def busted(b: bool) -> None:
for i in range(1, 10, 0): # E: range() step can't be zero
try:
if i == 5:
break # E: break inside try/finally block is unimplemented
elif i == 4:
continue # E: continue inside try/finally block is unimplemented
finally:
print('oops')
print(sum([1,2,3]))
x = [1,2]
class Foo:
a, b = (10, 20) # E: Only assignment to variables is supported in class bodies
x[0] = 10 # E: Only assignment to variables is supported in class bodies
lol = 20
l = [10] # W: Unsupported default attribute value
c = d = 50 # E: Multiple assignment in class bodies not supported
if 1+1 == 2: # E: Unsupported statement in class body
x = 10
Foo.lol = 50 # E: Only class variables defined as ClassVar can be assigned to
def decorator(x: Any) -> Any:
return x
class NeverMetaclass(type): # E: Inheriting from most builtin types is unimplemented
pass
@decorator
class Wrong(metaclass=NeverMetaclass): # E: Metaclasses are not supported \
# E: Class decorators are not supported
pass
class Concrete1:
pass
@trait
class Trait1(Concrete1):
pass
class Concrete2:
pass
@trait
class Trait2(Concrete2):
pass
def warning(x: List[int] = []) -> None: # W: Unsupported default argument value
pass
class Nope(Trait1, Concrete2): # E: Non-trait bases must appear first in parent list # E: Non-trait MRO must be linear
pass
iterator_warning = (i+1 for i in range(10)) # W: Treating generator comprehension as list
# But we don't want warnings for these cases:
tup = tuple(i+1 for i in range(10))
a_str = " ".join(str(i) for i in range(10))
wtvr = next(i for i in range(10) if i == 5)
d1 = {1: 2}
async def aio(x: Any) -> Any: # E: async functions are unimplemented
await x # E: await is unimplemented
a, *b, c = [1, 2, 3, 4] # E: Unpacking with * is unimplemented
[file foo/__init__.py]
x = 20
[file foo/bar.py]
from . import x # E: Relative imports are unimplemented