File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,3 +99,25 @@ def gen7():
9999 g .close ()
100100except RuntimeError :
101101 print ('RuntimeError' )
102+
103+ # case where close is propagated up to a built-in iterator
104+ def gen8 ():
105+ g = reversed ([2 , 1 ])
106+ yield from g
107+ g = gen8 ()
108+ print (next (g ))
109+ g .close ()
110+
111+ # case with a user-defined close method
112+ class Iter :
113+ def __iter__ (self ):
114+ return self
115+ def __next__ (self ):
116+ return 1
117+ def close (self ):
118+ print ('close' )
119+ def gen9 ():
120+ yield from Iter ()
121+ g = gen9 ()
122+ print (next (g ))
123+ g .close ()
Original file line number Diff line number Diff line change 1+ # tests transition from small to large int representation by addition
2+
3+ # 31-bit overflow
4+ i = 0x3fffffff
5+ print (i + i )
6+ print (- i + - i )
7+
8+ # 63-bit overflow
9+ i = 0x3fffffffffffffff
10+ print (i + i )
11+ print (- i + - i )
Original file line number Diff line number Diff line change @@ -9,6 +9,15 @@ class NotIterable:
99except TypeError :
1010 print ('TypeError' )
1111
12+ # this class has no __next__ implementation
13+ class NotIterable :
14+ def __iter__ (self ):
15+ return self
16+ try :
17+ print (all (NotIterable ()))
18+ except TypeError :
19+ print ('TypeError' )
20+
1221class MyStopIteration (StopIteration ):
1322 pass
1423
Original file line number Diff line number Diff line change 2222except NameError :
2323 print ("except 1" )
2424
25+ # raised exception not contained in except tuple
26+ try :
27+ try :
28+ raise Exception
29+ except (RuntimeError , SyntaxError ):
30+ print ('except 2' )
31+ except Exception :
32+ print ('except 1' )
33+
2534# Check that exceptions across function boundaries work as expected
2635def func1 ():
2736 try :
Original file line number Diff line number Diff line change 7575except TypeError :
7676 print ("TypeError" )
7777
78+ #small int on LHS, complex on RHS, unsupported op
79+ try :
80+ print (1 | 1j )
81+ except TypeError :
82+ print ('TypeError' )
83+
7884# zero division
7985try :
8086 1j / 0
Original file line number Diff line number Diff line change 8787except TypeError :
8888 print ("TypeError" )
8989
90+ # small int on LHS, float on RHS, unsupported op
91+ try :
92+ print (1 | 1.0 )
93+ except TypeError :
94+ print ('TypeError' )
95+
9096# can't convert list to float
9197try :
9298 float ([])
You can’t perform that action at this time.
0 commit comments