@@ -880,115 +880,6 @@ class C(object):
880880 gc .collect ()
881881 self .assertIs (ref (), None , "Cycle was not collected" )
882882
883- def _not_tracked (self , t ):
884- # Nested containers can take several collections to untrack
885- gc .collect ()
886- gc .collect ()
887- self .assertFalse (gc .is_tracked (t ), t )
888-
889- def _tracked (self , t ):
890- self .assertTrue (gc .is_tracked (t ), t )
891- gc .collect ()
892- gc .collect ()
893- self .assertTrue (gc .is_tracked (t ), t )
894-
895- def test_string_keys_can_track_values (self ):
896- # Test that this doesn't leak.
897- for i in range (10 ):
898- d = {}
899- for j in range (10 ):
900- d [str (j )] = j
901- d ["foo" ] = d
902-
903- @support .cpython_only
904- def test_track_literals (self ):
905- # Test GC-optimization of dict literals
906- x , y , z , w = 1.5 , "a" , (1 , None ), []
907-
908- self ._not_tracked ({})
909- self ._not_tracked ({x :(), y :x , z :1 })
910- self ._not_tracked ({1 : "a" , "b" : 2 })
911- self ._not_tracked ({1 : 2 , (None , True , False , ()): int })
912- self ._not_tracked ({1 : object ()})
913-
914- # Dicts with mutable elements are always tracked, even if those
915- # elements are not tracked right now.
916- self ._tracked ({1 : []})
917- self ._tracked ({1 : ([],)})
918- self ._tracked ({1 : {}})
919- self ._tracked ({1 : set ()})
920-
921- @support .cpython_only
922- def test_track_dynamic (self ):
923- # Test GC-optimization of dynamically-created dicts
924- class MyObject (object ):
925- pass
926- x , y , z , w , o = 1.5 , "a" , (1 , object ()), [], MyObject ()
927-
928- d = dict ()
929- self ._not_tracked (d )
930- d [1 ] = "a"
931- self ._not_tracked (d )
932- d [y ] = 2
933- self ._not_tracked (d )
934- d [z ] = 3
935- self ._not_tracked (d )
936- self ._not_tracked (d .copy ())
937- d [4 ] = w
938- self ._tracked (d )
939- self ._tracked (d .copy ())
940- d [4 ] = None
941- self ._not_tracked (d )
942- self ._not_tracked (d .copy ())
943-
944- # dd isn't tracked right now, but it may mutate and therefore d
945- # which contains it must be tracked.
946- d = dict ()
947- dd = dict ()
948- d [1 ] = dd
949- self ._not_tracked (dd )
950- self ._tracked (d )
951- dd [1 ] = d
952- self ._tracked (dd )
953-
954- d = dict .fromkeys ([x , y , z ])
955- self ._not_tracked (d )
956- dd = dict ()
957- dd .update (d )
958- self ._not_tracked (dd )
959- d = dict .fromkeys ([x , y , z , o ])
960- self ._tracked (d )
961- dd = dict ()
962- dd .update (d )
963- self ._tracked (dd )
964-
965- d = dict (x = x , y = y , z = z )
966- self ._not_tracked (d )
967- d = dict (x = x , y = y , z = z , w = w )
968- self ._tracked (d )
969- d = dict ()
970- d .update (x = x , y = y , z = z )
971- self ._not_tracked (d )
972- d .update (w = w )
973- self ._tracked (d )
974-
975- d = dict ([(x , y ), (z , 1 )])
976- self ._not_tracked (d )
977- d = dict ([(x , y ), (z , w )])
978- self ._tracked (d )
979- d = dict ()
980- d .update ([(x , y ), (z , 1 )])
981- self ._not_tracked (d )
982- d .update ([(x , y ), (z , w )])
983- self ._tracked (d )
984-
985- @support .cpython_only
986- def test_track_subtypes (self ):
987- # Dict subtypes are always tracked
988- class MyDict (dict ):
989- pass
990- self ._tracked (MyDict ())
991-
992883 def make_shared_key_dict (self , n ):
993884 class C :
994885 pass
0 commit comments