@@ -42,8 +42,7 @@ def test_keyword_args(self):
4242 with self .assertRaisesRegex (TypeError , 'keyword argument' ):
4343 tuple (sequence = ())
4444
45- # TODO: RUSTPYTHON
46- @unittest .expectedFailure
45+ @unittest .expectedFailure # TODO: RUSTPYTHON
4746 def test_keywords_in_subclass (self ):
4847 class subclass (tuple ):
4948 pass
@@ -292,12 +291,18 @@ def test_repr(self):
292291 self .assertEqual (repr (a0 ), "()" )
293292 self .assertEqual (repr (a2 ), "(0, 1, 2)" )
294293
294+ # Checks that t is not tracked without any GC collections.
295+ def _not_tracked_instantly (self , t ):
296+ self .assertFalse (gc .is_tracked (t ), t )
297+
298+ # Checks that t is not tracked after GC collection.
295299 def _not_tracked (self , t ):
296300 # Nested tuples can take several collections to untrack
297301 gc .collect ()
298302 gc .collect ()
299303 self .assertFalse (gc .is_tracked (t ), t )
300304
305+ # Checks that t continues to be tracked even after GC collection.
301306 def _tracked (self , t ):
302307 self .assertTrue (gc .is_tracked (t ), t )
303308 gc .collect ()
@@ -309,13 +314,19 @@ def test_track_literals(self):
309314 # Test GC-optimization of tuple literals
310315 x , y , z = 1.5 , "a" , []
311316
312- self ._not_tracked (())
313- self ._not_tracked ((1 ,))
314- self ._not_tracked ((1 , 2 ))
315- self ._not_tracked ((1 , 2 , "a" ))
316- self ._not_tracked ((1 , 2 , (None , True , False , ()), int ))
317- self ._not_tracked ((object (),))
317+ # We check that those objects aren't tracked at all.
318+ # It's essential for the GC performance, see gh-139951.
319+ self ._not_tracked_instantly (())
320+ self ._not_tracked_instantly ((1 ,))
321+ self ._not_tracked_instantly ((1 , 2 ))
322+ self ._not_tracked_instantly ((1 , 2 , "a" ))
323+ self ._not_tracked_instantly ((1 , 2 ) * 5 )
324+ self ._not_tracked_instantly ((12 , 10 ** 10 , 'a_' * 100 ))
325+ self ._not_tracked_instantly ((object (),))
326+
318327 self ._not_tracked (((1 , x ), y , (2 , 3 )))
328+ self ._not_tracked ((1 , 2 , (None , True , False , ()), int ))
329+ self ._not_tracked ((object (), ()))
319330
320331 # Tuples with mutable elements are always tracked, even if those
321332 # elements are not tracked right now.
@@ -345,6 +356,12 @@ def check_track_dynamic(self, tp, always_track):
345356 self ._tracked (tp (tuple ([obj ]) for obj in [x , y , z ]))
346357 self ._tracked (tuple (tp ([obj ]) for obj in [x , y , z ]))
347358
359+ t = tp ([1 , x , y , z ])
360+ self .assertEqual (type (t ), tp )
361+ self ._tracked (t )
362+ self .assertEqual (type (t [:]), tuple )
363+ self ._tracked (t [:])
364+
348365 @support .cpython_only
349366 def test_track_dynamic (self ):
350367 # Test GC-optimization of dynamically constructed tuples.
0 commit comments