Skip to content

Commit 71f1471

Browse files
Update
[ghstack-poisoned]
1 parent 52cde77 commit 71f1471

24 files changed

+957
-237
lines changed

test/dynamo/cpython/3_13/test_bool.diff

Lines changed: 136 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/test/dynamo/cpython/3_13/test_bool.py b/test/dynamo/cpython/3_13/test_bool.py
2-
index 34ecb45f161..8989785eb75 100644
2+
index 34ecb45f161..12b719c432b 100644
33
--- a/test/dynamo/cpython/3_13/test_bool.py
44
+++ b/test/dynamo/cpython/3_13/test_bool.py
55
@@ -1,3 +1,23 @@
@@ -26,7 +26,7 @@ index 34ecb45f161..8989785eb75 100644
2626
# Test properties of bool promised by PEP 285
2727

2828
import unittest
29-
@@ -5,7 +25,7 @@ from test.support import os_helper
29+
@@ -5,12 +25,13 @@ from test.support import os_helper
3030

3131
import os
3232

@@ -35,7 +35,140 @@ index 34ecb45f161..8989785eb75 100644
3535

3636
def test_subclass(self):
3737
try:
38-
@@ -418,4 +438,4 @@ class BoolTest(unittest.TestCase):
38+
- class C(bool):
39+
- pass
40+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
41+
+ class C(bool):
42+
+ pass
43+
except TypeError:
44+
pass
45+
else:
46+
@@ -307,40 +328,46 @@ class BoolTest(unittest.TestCase):
47+
# from __bool__(). This isn't really a bool test, but
48+
# it's related.
49+
check = lambda o: self.assertRaises(TypeError, bool, o)
50+
- class Foo(object):
51+
- def __bool__(self):
52+
- return self
53+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
54+
+ class Foo(object):
55+
+ def __bool__(self):
56+
+ return self
57+
check(Foo())
58+
59+
- class Bar(object):
60+
- def __bool__(self):
61+
- return "Yes"
62+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
63+
+ class Bar(object):
64+
+ def __bool__(self):
65+
+ return "Yes"
66+
check(Bar())
67+
68+
- class Baz(int):
69+
- def __bool__(self):
70+
- return self
71+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
72+
+ class Baz(int):
73+
+ def __bool__(self):
74+
+ return self
75+
check(Baz())
76+
77+
# __bool__() must return a bool not an int
78+
- class Spam(int):
79+
- def __bool__(self):
80+
- return 1
81+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
82+
+ class Spam(int):
83+
+ def __bool__(self):
84+
+ return 1
85+
check(Spam())
86+
87+
- class Eggs:
88+
- def __len__(self):
89+
- return -1
90+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
91+
+ class Eggs:
92+
+ def __len__(self):
93+
+ return -1
94+
self.assertRaises(ValueError, bool, Eggs())
95+
96+
def test_interpreter_convert_to_bool_raises(self):
97+
- class SymbolicBool:
98+
- def __bool__(self):
99+
- raise TypeError
100+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
101+
+ class SymbolicBool:
102+
+ def __bool__(self):
103+
+ raise TypeError
104+
105+
- class Symbol:
106+
- def __gt__(self, other):
107+
- return SymbolicBool()
108+
+ class Symbol:
109+
+ def __gt__(self, other):
110+
+ return SymbolicBool()
111+
112+
x = Symbol()
113+
114+
@@ -361,9 +388,10 @@ class BoolTest(unittest.TestCase):
115+
# this test just tests our assumptions about __len__
116+
# this will start failing if __len__ changes assertions
117+
for badval in ['illegal', -1, 1 << 32]:
118+
- class A:
119+
- def __len__(self):
120+
- return badval
121+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
122+
+ class A:
123+
+ def __len__(self):
124+
+ return badval
125+
try:
126+
bool(A())
127+
except (Exception) as e_bool:
128+
@@ -373,14 +401,16 @@ class BoolTest(unittest.TestCase):
129+
self.assertEqual(str(e_bool), str(e_len))
130+
131+
def test_blocked(self):
132+
- class A:
133+
- __bool__ = None
134+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
135+
+ class A:
136+
+ __bool__ = None
137+
self.assertRaises(TypeError, bool, A())
138+
139+
- class B:
140+
- def __len__(self):
141+
- return 10
142+
- __bool__ = None
143+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
144+
+ class B:
145+
+ def __len__(self):
146+
+ return 10
147+
+ __bool__ = None
148+
self.assertRaises(TypeError, bool, B())
149+
150+
def test_real_and_imag(self):
151+
@@ -394,12 +424,13 @@ class BoolTest(unittest.TestCase):
152+
self.assertIs(type(False.imag), int)
153+
154+
def test_bool_called_at_least_once(self):
155+
- class X:
156+
- def __init__(self):
157+
- self.count = 0
158+
- def __bool__(self):
159+
- self.count += 1
160+
- return True
161+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
162+
+ class X:
163+
+ def __init__(self):
164+
+ self.count = 0
165+
+ def __bool__(self):
166+
+ self.count += 1
167+
+ return True
168+
169+
def f(x):
170+
if x or True:
171+
@@ -418,4 +449,4 @@ class BoolTest(unittest.TestCase):
39172

40173

41174
if __name__ == "__main__":

test/dynamo/cpython/3_13/test_bool.py

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ class BoolTest(__TestCase):
2929

3030
def test_subclass(self):
3131
try:
32-
class C(bool):
33-
pass
32+
with torch._dynamo.set_fullgraph(fullgraph=False):
33+
class C(bool):
34+
pass
3435
except TypeError:
3536
pass
3637
else:
@@ -327,40 +328,46 @@ def test_convert_to_bool(self):
327328
# from __bool__(). This isn't really a bool test, but
328329
# it's related.
329330
check = lambda o: self.assertRaises(TypeError, bool, o)
330-
class Foo(object):
331-
def __bool__(self):
332-
return self
331+
with torch._dynamo.set_fullgraph(fullgraph=False):
332+
class Foo(object):
333+
def __bool__(self):
334+
return self
333335
check(Foo())
334336

335-
class Bar(object):
336-
def __bool__(self):
337-
return "Yes"
337+
with torch._dynamo.set_fullgraph(fullgraph=False):
338+
class Bar(object):
339+
def __bool__(self):
340+
return "Yes"
338341
check(Bar())
339342

340-
class Baz(int):
341-
def __bool__(self):
342-
return self
343+
with torch._dynamo.set_fullgraph(fullgraph=False):
344+
class Baz(int):
345+
def __bool__(self):
346+
return self
343347
check(Baz())
344348

345349
# __bool__() must return a bool not an int
346-
class Spam(int):
347-
def __bool__(self):
348-
return 1
350+
with torch._dynamo.set_fullgraph(fullgraph=False):
351+
class Spam(int):
352+
def __bool__(self):
353+
return 1
349354
check(Spam())
350355

351-
class Eggs:
352-
def __len__(self):
353-
return -1
356+
with torch._dynamo.set_fullgraph(fullgraph=False):
357+
class Eggs:
358+
def __len__(self):
359+
return -1
354360
self.assertRaises(ValueError, bool, Eggs())
355361

356362
def test_interpreter_convert_to_bool_raises(self):
357-
class SymbolicBool:
358-
def __bool__(self):
359-
raise TypeError
363+
with torch._dynamo.set_fullgraph(fullgraph=False):
364+
class SymbolicBool:
365+
def __bool__(self):
366+
raise TypeError
360367

361-
class Symbol:
362-
def __gt__(self, other):
363-
return SymbolicBool()
368+
class Symbol:
369+
def __gt__(self, other):
370+
return SymbolicBool()
364371

365372
x = Symbol()
366373

@@ -381,9 +388,10 @@ def test_sane_len(self):
381388
# this test just tests our assumptions about __len__
382389
# this will start failing if __len__ changes assertions
383390
for badval in ['illegal', -1, 1 << 32]:
384-
class A:
385-
def __len__(self):
386-
return badval
391+
with torch._dynamo.set_fullgraph(fullgraph=False):
392+
class A:
393+
def __len__(self):
394+
return badval
387395
try:
388396
bool(A())
389397
except (Exception) as e_bool:
@@ -393,14 +401,16 @@ def __len__(self):
393401
self.assertEqual(str(e_bool), str(e_len))
394402

395403
def test_blocked(self):
396-
class A:
397-
__bool__ = None
404+
with torch._dynamo.set_fullgraph(fullgraph=False):
405+
class A:
406+
__bool__ = None
398407
self.assertRaises(TypeError, bool, A())
399408

400-
class B:
401-
def __len__(self):
402-
return 10
403-
__bool__ = None
409+
with torch._dynamo.set_fullgraph(fullgraph=False):
410+
class B:
411+
def __len__(self):
412+
return 10
413+
__bool__ = None
404414
self.assertRaises(TypeError, bool, B())
405415

406416
def test_real_and_imag(self):
@@ -414,12 +424,13 @@ def test_real_and_imag(self):
414424
self.assertIs(type(False.imag), int)
415425

416426
def test_bool_called_at_least_once(self):
417-
class X:
418-
def __init__(self):
419-
self.count = 0
420-
def __bool__(self):
421-
self.count += 1
422-
return True
427+
with torch._dynamo.set_fullgraph(fullgraph=False):
428+
class X:
429+
def __init__(self):
430+
self.count = 0
431+
def __bool__(self):
432+
self.count += 1
433+
return True
423434

424435
def f(x):
425436
if x or True:

test/dynamo/cpython/3_13/test_complex.diff

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/test/dynamo/cpython/3_13/test_complex.py b/test/dynamo/cpython/3_13/test_complex.py
2-
index 6ff1a8ab29d..cda348d2f37 100644
2+
index 6ff1a8ab29d..01295e03efc 100644
33
--- a/test/dynamo/cpython/3_13/test_complex.py
44
+++ b/test/dynamo/cpython/3_13/test_complex.py
55
@@ -1,16 +1,146 @@
@@ -226,7 +226,80 @@ index 6ff1a8ab29d..cda348d2f37 100644
226226
def assertClose(self, x, y, eps=1e-9):
227227
"""Return true iff complexes x and y "are close"."""
228228
self.assertCloseAbs(x.real, y.real, eps)
229-
@@ -855,4 +1041,4 @@ class ComplexTest(ComplexesAreIdenticalMixin, unittest.TestCase):
229+
@@ -431,12 +617,13 @@ class ComplexTest(ComplexesAreIdenticalMixin, unittest.TestCase):
230+
self.assertRaises(TypeError, complex, WithComplex(1), object())
231+
self.assertRaises(TypeError, complex, WithComplex(None), object())
232+
233+
- class EvilExc(Exception):
234+
- pass
235+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
236+
+ class EvilExc(Exception):
237+
+ pass
238+
239+
- class evilcomplex:
240+
- def __complex__(self):
241+
- raise EvilExc
242+
+ class evilcomplex:
243+
+ def __complex__(self):
244+
+ raise EvilExc
245+
246+
self.assertRaises(EvilExc, complex, evilcomplex())
247+
248+
@@ -460,31 +647,33 @@ class ComplexTest(ComplexesAreIdenticalMixin, unittest.TestCase):
249+
self.assertRaises(TypeError, complex, WithIndex(None), 1.5)
250+
self.assertRaises(TypeError, complex, 1.5, WithIndex(None))
251+
252+
- class MyInt:
253+
- def __int__(self):
254+
- return 42
255+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
256+
+ class MyInt:
257+
+ def __int__(self):
258+
+ return 42
259+
260+
self.assertRaises(TypeError, complex, MyInt())
261+
self.assertRaises(TypeError, complex, MyInt(), 1.5)
262+
self.assertRaises(TypeError, complex, 1.5, MyInt())
263+
264+
- class complex0(complex):
265+
- """Test usage of __complex__() when inheriting from 'complex'"""
266+
- def __complex__(self):
267+
- return 42j
268+
-
269+
- class complex1(complex):
270+
- """Test usage of __complex__() with a __new__() method"""
271+
- def __new__(self, value=0j):
272+
- return complex.__new__(self, 2*value)
273+
- def __complex__(self):
274+
- return self
275+
-
276+
- class complex2(complex):
277+
- """Make sure that __complex__() calls fail if anything other than a
278+
- complex is returned"""
279+
- def __complex__(self):
280+
- return None
281+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
282+
+ class complex0(complex):
283+
+ """Test usage of __complex__() when inheriting from 'complex'"""
284+
+ def __complex__(self):
285+
+ return 42j
286+
+
287+
+ class complex1(complex):
288+
+ """Test usage of __complex__() with a __new__() method"""
289+
+ def __new__(self, value=0j):
290+
+ return complex.__new__(self, 2*value)
291+
+ def __complex__(self):
292+
+ return self
293+
+
294+
+ class complex2(complex):
295+
+ """Make sure that __complex__() calls fail if anything other than a
296+
+ complex is returned"""
297+
+ def __complex__(self):
298+
+ return None
299+
300+
check(complex(complex0(1j)), 0.0, 42.0)
301+
with self.assertWarns(DeprecationWarning):
302+
@@ -855,4 +1044,4 @@ class ComplexTest(ComplexesAreIdenticalMixin, unittest.TestCase):
230303

231304

232305
if __name__ == "__main__":

0 commit comments

Comments
 (0)