@@ -11,138 +11,97 @@ print('hello, world')
1111[out]
1212hello, world
1313
14- [case testReversed]
14+ [case testMiscStdlibFeatures]
15+ # Various legacy tests merged together to speed up test runtimes.
16+
17+ def f(x: object) -> None: pass
18+
19+ # testReversed
1520from typing import Reversible
16- class A (Reversible):
21+ class R (Reversible):
1722 def __iter__(self): return iter('oof')
1823 def __reversed__(self): return iter('foo')
19- print(list(reversed(range(5))))
20- print(list(reversed([1,2,3])))
21- print(list(reversed('abc')))
22- print(list(reversed(A())))
23- [out]
24- -- Escape bracket at line beginning
25- \[4, 3, 2, 1, 0]
26- \[3, 2, 1]
27- \['c', 'b', 'a']
28- \['f', 'o', 'o']
29-
30- [case testIntAndFloatConversion]
24+ f(list(reversed(range(5))))
25+ f(list(reversed([1,2,3])))
26+ f(list(reversed('abc')))
27+ f(list(reversed(R())))
28+
29+ # testIntAndFloatConversion
3130from typing import SupportsInt, SupportsFloat
3231class A(SupportsInt):
3332 def __int__(self): return 5
3433class B(SupportsFloat):
3534 def __float__(self): return 1.2
36- print(int(1))
37- print(int(6.2))
38- print(int('3'))
39- print(int(b'4'))
40- print(int(A()))
41- print(float(-9))
42- print(float(B()))
43- [out]
44- 1
45- 6
46- 3
47- 4
48- 5
49- -9.0
50- 1.2
51-
52- [case testAbs]
35+ f(int(1))
36+ f(int(6.2))
37+ f(int('3'))
38+ f(int(b'4'))
39+ f(int(A()))
40+ f(float(-9))
41+ f(float(B()))
42+
43+ # testAbs
5344from typing import SupportsAbs
54- class A (SupportsAbs[float]):
45+ class Ab (SupportsAbs[float]):
5546 def __abs__(self) -> float: return 5.5
5647
57- print(abs(-1))
58- print(abs(-1.2))
59- print(abs(A()))
60- [out]
61- 1
62- 1.2
63- 5.5
64-
65- [case testAbs2]
66- n: int
67- f: float
68- n = abs(1)
69- abs(1) + 'x' # Error
70- f = abs(1.1)
71- abs(1.1) + 'x' # Error
72- [out]
73- _program.py:4: error: Unsupported operand types for + ("int" and "str")
74- _program.py:6: error: Unsupported operand types for + ("float" and "str")
48+ f(abs(-1))
49+ f(abs(-1.2))
50+ f(abs(Ab()))
7551
76- [case testRound]
52+ # testRound
7753from typing import SupportsRound
78- class A (SupportsRound):
54+ class Ro (SupportsRound):
7955 def __round__(self, ndigits=0): return 'x%d' % ndigits
80- print(round(1.6))
81- print(round(A()))
82- print(round(A(), 2))
83- [out]
84- 2
85- x0
86- x2
56+ f(round(1.6))
57+ f(round(Ro()))
58+ f(round(Ro(), 2))
8759
88- [case testCallMethodViaTypeObject]
89- import typing
90- print(list.__add__([1, 2], [3, 4]))
91- [out]
92- \[1, 2, 3, 4]
60+ # testCallMethodViaTypeObject
61+ list.__add__([1, 2], [3, 4])
9362
94- [case testInheritedClassAttribute]
63+ # testInheritedClassAttribute
9564import typing
96- class A :
65+ class AA :
9766 x = 1
98- def f(self: typing.Optional["A "]) -> None: print('f')
99- class B(A ):
67+ def f(self: typing.Optional["AA "]) -> None: pass
68+ class BB(AA ):
10069 pass
101- B.f(None)
102- print(B.x)
103- [out]
104- f
105- 1
106-
107- [case testModuleAttributes]
108- import math
109- import typing
110- print(type(__spec__))
111- print(math.__name__)
112- print(math.__spec__.name)
113- print(type(math.__dict__))
114- print(type(math.__doc__ or ''))
115- print(type(math.__spec__).__name__)
116- print(math.__class__)
117- [out]
118- <class 'NoneType'>
119- math
120- math
121- <class 'dict'>
122- <class 'str'>
123- ModuleSpec
124- <class 'module'>
70+ BB.f(None)
71+ f(BB.x)
12572
126- [case testSpecialAttributes]
127- import typing
128- class A:
73+ # testSpecialAttributes
74+ class Doc:
12975 """A docstring!"""
130- print(A().__doc__)
131- print(A().__class__)
132- [out]
133- A docstring!
134- <class '__main__.A'>
76+ f(Doc().__doc__)
77+ f(Doc().__class__)
13578
136- [case testFunctionAttributes]
137- import typing
138- ord.__class__
139- print(type(ord.__doc__ or '' + ''))
140- print(ord.__name__)
141- print(ord.__module__)
79+ # testFunctionAttributes
80+ f(ord.__class__)
81+ f(type(ord.__doc__ or '' + ''))
82+ f(ord.__name__)
83+ f(ord.__module__)
84+
85+ # testModuleAttributes
86+ import math
87+ f(type(__spec__))
88+ f(math.__name__)
89+ f(math.__spec__.name)
90+ f(type(math.__dict__))
91+ f(type(math.__doc__ or ''))
92+ f(type(math.__spec__).__name__)
93+ f(math.__class__)
94+
95+ [case testAbs2]
96+ n: int
97+ f: float
98+ n = abs(1)
99+ abs(1) + 'x' # Error
100+ f = abs(1.1)
101+ abs(1.1) + 'x' # Error
142102[out]
143- <class 'str'>
144- ord
145- builtins
103+ _program.py:4: error: Unsupported operand types for + ("int" and "str")
104+ _program.py:6: error: Unsupported operand types for + ("float" and "str")
146105
147106[case testTypeAttributes]
148107import typing
0 commit comments