Skip to content

Commit dad3385

Browse files
Wrap class definitions in set_fullgraph(False) in test_list/tuple
ghstack-source-id: e23cbda Pull-Request: #160277
1 parent 2eda9ce commit dad3385

19 files changed

+589
-129
lines changed

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

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/test/dynamo/cpython/3_13/list_tests.py b/test/dynamo/cpython/3_13/list_tests.py
2-
index dbc5ef4f9f2..70e24036f74 100644
2+
index dbc5ef4f9f2..af717703053 100644
33
--- a/test/dynamo/cpython/3_13/list_tests.py
44
+++ b/test/dynamo/cpython/3_13/list_tests.py
55
@@ -1,3 +1,56 @@
@@ -79,3 +79,81 @@ index dbc5ef4f9f2..70e24036f74 100644
7979
def test_delitem(self):
8080
a = self.type2test([0, 1])
8181
del a[1]
82+
@@ -270,13 +319,14 @@ class CommonTest(seq_tests.CommonTest):
83+
self.assertRaises(TypeError, a.extend)
84+
85+
# overflow test. issue1621
86+
- class CustomIter:
87+
- def __iter__(self):
88+
- return self
89+
- def __next__(self):
90+
- raise StopIteration
91+
- def __length_hint__(self):
92+
- return sys.maxsize
93+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
94+
+ class CustomIter:
95+
+ def __iter__(self):
96+
+ return self
97+
+ def __next__(self):
98+
+ raise StopIteration
99+
+ def __length_hint__(self):
100+
+ return sys.maxsize
101+
a = self.type2test([1,2,3,4])
102+
a.extend(CustomIter())
103+
self.assertEqual(a, [1,2,3,4])
104+
@@ -337,21 +387,23 @@ class CommonTest(seq_tests.CommonTest):
105+
a = self.type2test([NEVER_EQ])
106+
self.assertRaises(ValueError, a.remove, ALWAYS_EQ)
107+
108+
- class BadExc(Exception):
109+
- pass
110+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
111+
+ class BadExc(Exception):
112+
+ pass
113+
114+
- class BadCmp:
115+
- def __eq__(self, other):
116+
- if other == 2:
117+
- raise BadExc()
118+
- return False
119+
+ class BadCmp:
120+
+ def __eq__(self, other):
121+
+ if other == 2:
122+
+ raise BadExc()
123+
+ return False
124+
125+
a = self.type2test([0, 1, 2, 3])
126+
self.assertRaises(BadExc, a.remove, BadCmp())
127+
128+
- class BadCmp2:
129+
- def __eq__(self, other):
130+
- raise BadExc()
131+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
132+
+ class BadCmp2:
133+
+ def __eq__(self, other):
134+
+ raise BadExc()
135+
136+
d = self.type2test('abcdefghcij')
137+
d.remove('c')
138+
@@ -376,13 +428,14 @@ class CommonTest(seq_tests.CommonTest):
139+
self.assertRaises(ValueError, a.index, 2, 0, 4)
140+
self.assertEqual(a, self.type2test([-2, -1, 0, 1, 2]))
141+
142+
- # Test modifying the list during index's iteration
143+
- class EvilCmp:
144+
- def __init__(self, victim):
145+
- self.victim = victim
146+
- def __eq__(self, other):
147+
- del self.victim[:]
148+
- return False
149+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
150+
+ # Test modifying the list during index's iteration
151+
+ class EvilCmp:
152+
+ def __init__(self, victim):
153+
+ self.victim = victim
154+
+ def __eq__(self, other):
155+
+ del self.victim[:]
156+
+ return False
157+
a = self.type2test()
158+
a[:] = [EvilCmp(a) for _ in range(100)]
159+
# This used to seg fault before patch #1005778

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,14 @@ def test_extend(self):
319319
self.assertRaises(TypeError, a.extend)
320320

321321
# overflow test. issue1621
322-
class CustomIter:
323-
def __iter__(self):
324-
return self
325-
def __next__(self):
326-
raise StopIteration
327-
def __length_hint__(self):
328-
return sys.maxsize
322+
with torch._dynamo.set_fullgraph(fullgraph=False):
323+
class CustomIter:
324+
def __iter__(self):
325+
return self
326+
def __next__(self):
327+
raise StopIteration
328+
def __length_hint__(self):
329+
return sys.maxsize
329330
a = self.type2test([1,2,3,4])
330331
a.extend(CustomIter())
331332
self.assertEqual(a, [1,2,3,4])
@@ -386,21 +387,23 @@ def test_remove(self):
386387
a = self.type2test([NEVER_EQ])
387388
self.assertRaises(ValueError, a.remove, ALWAYS_EQ)
388389

389-
class BadExc(Exception):
390-
pass
390+
with torch._dynamo.set_fullgraph(fullgraph=False):
391+
class BadExc(Exception):
392+
pass
391393

392-
class BadCmp:
393-
def __eq__(self, other):
394-
if other == 2:
395-
raise BadExc()
396-
return False
394+
class BadCmp:
395+
def __eq__(self, other):
396+
if other == 2:
397+
raise BadExc()
398+
return False
397399

398400
a = self.type2test([0, 1, 2, 3])
399401
self.assertRaises(BadExc, a.remove, BadCmp())
400402

401-
class BadCmp2:
402-
def __eq__(self, other):
403-
raise BadExc()
403+
with torch._dynamo.set_fullgraph(fullgraph=False):
404+
class BadCmp2:
405+
def __eq__(self, other):
406+
raise BadExc()
404407

405408
d = self.type2test('abcdefghcij')
406409
d.remove('c')
@@ -425,13 +428,14 @@ def test_index(self):
425428
self.assertRaises(ValueError, a.index, 2, 0, 4)
426429
self.assertEqual(a, self.type2test([-2, -1, 0, 1, 2]))
427430

428-
# Test modifying the list during index's iteration
429-
class EvilCmp:
430-
def __init__(self, victim):
431-
self.victim = victim
432-
def __eq__(self, other):
433-
del self.victim[:]
434-
return False
431+
with torch._dynamo.set_fullgraph(fullgraph=False):
432+
# Test modifying the list during index's iteration
433+
class EvilCmp:
434+
def __init__(self, victim):
435+
self.victim = victim
436+
def __eq__(self, other):
437+
del self.victim[:]
438+
return False
435439
a = self.type2test()
436440
a[:] = [EvilCmp(a) for _ in range(100)]
437441
# This used to seg fault before patch #1005778

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

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/test/dynamo/cpython/3_13/seq_tests.py b/test/dynamo/cpython/3_13/seq_tests.py
2-
index 719c9434a16..2c502cda4f6 100644
2+
index 719c9434a16..290e57c04a0 100644
33
--- a/test/dynamo/cpython/3_13/seq_tests.py
44
+++ b/test/dynamo/cpython/3_13/seq_tests.py
55
@@ -1,3 +1,57 @@
@@ -69,3 +69,115 @@ index 719c9434a16..2c502cda4f6 100644
6969
# The type to be tested
7070
type2test = None
7171

72+
@@ -115,13 +169,14 @@ class CommonTest(unittest.TestCase):
73+
uu2 = self.type2test(u2)
74+
75+
v = self.type2test(tuple(u))
76+
- class OtherSeq:
77+
- def __init__(self, initseq):
78+
- self.__data = initseq
79+
- def __len__(self):
80+
- return len(self.__data)
81+
- def __getitem__(self, i):
82+
- return self.__data[i]
83+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
84+
+ class OtherSeq:
85+
+ def __init__(self, initseq):
86+
+ self.__data = initseq
87+
+ def __len__(self):
88+
+ return len(self.__data)
89+
+ def __getitem__(self, i):
90+
+ return self.__data[i]
91+
s = OtherSeq(u0)
92+
v0 = self.type2test(s)
93+
self.assertEqual(len(v0), len(s))
94+
@@ -239,11 +294,12 @@ class CommonTest(unittest.TestCase):
95+
# Sequences must test in-order. If a rich comparison has side
96+
# effects, these will be visible to tests against later members.
97+
# In this test, the "side effect" is a short-circuiting raise.
98+
- class DoNotTestEq(Exception):
99+
- pass
100+
- class StopCompares:
101+
- def __eq__(self, other):
102+
- raise DoNotTestEq
103+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
104+
+ class DoNotTestEq(Exception):
105+
+ pass
106+
+ class StopCompares:
107+
+ def __eq__(self, other):
108+
+ raise DoNotTestEq
109+
110+
checkfirst = self.type2test([1, StopCompares()])
111+
self.assertIn(1, checkfirst)
112+
@@ -283,8 +339,9 @@ class CommonTest(unittest.TestCase):
113+
self.assertEqual(u2+u2+u2, u2*3)
114+
self.assertEqual(u2+u2+u2, 3*u2)
115+
116+
- class subclass(self.type2test):
117+
- pass
118+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
119+
+ class subclass(self.type2test):
120+
+ pass
121+
u3 = subclass([0, 1])
122+
self.assertEqual(u3, u3*1)
123+
self.assertIsNot(u3, u3*1)
124+
@@ -311,9 +368,10 @@ class CommonTest(unittest.TestCase):
125+
126+
def test_getitemoverwriteiter(self):
127+
# Verify that __getitem__ overrides are not recognized by __iter__
128+
- class T(self.type2test):
129+
- def __getitem__(self, key):
130+
- return str(key) + '!!!'
131+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
132+
+ class T(self.type2test):
133+
+ def __getitem__(self, key):
134+
+ return str(key) + '!!!'
135+
self.assertEqual(next(iter(T((1,2)))), 1)
136+
137+
def test_repeat(self):
138+
@@ -361,14 +419,15 @@ class CommonTest(unittest.TestCase):
139+
140+
self.assertRaises(TypeError, a.count)
141+
142+
- class BadExc(Exception):
143+
- pass
144+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
145+
+ class BadExc(Exception):
146+
+ pass
147+
148+
- class BadCmp:
149+
- def __eq__(self, other):
150+
- if other == 2:
151+
- raise BadExc()
152+
- return False
153+
+ class BadCmp:
154+
+ def __eq__(self, other):
155+
+ if other == 2:
156+
+ raise BadExc()
157+
+ return False
158+
159+
self.assertRaises(BadExc, a.count, BadCmp())
160+
161+
@@ -394,14 +453,15 @@ class CommonTest(unittest.TestCase):
162+
163+
self.assertRaises(TypeError, u.index)
164+
165+
- class BadExc(Exception):
166+
- pass
167+
+ with torch._dynamo.set_fullgraph(fullgraph=False):
168+
+ class BadExc(Exception):
169+
+ pass
170+
171+
- class BadCmp:
172+
- def __eq__(self, other):
173+
- if other == 2:
174+
- raise BadExc()
175+
- return False
176+
+ class BadCmp:
177+
+ def __eq__(self, other):
178+
+ if other == 2:
179+
+ raise BadExc()
180+
+ return False
181+
182+
a = self.type2test([0, 1, 2, 3])
183+
self.assertRaises(BadExc, a.index, BadCmp())

0 commit comments

Comments
 (0)