')
        dict, objects = self.make_weak_keyed_dict()
        @contextlib.contextmanager
        def testcontext():
            try:
                it = iter(dict.items())
                next(it)
                # Schedule a key/value for removal and recreate it
                v = objects.pop().arg
                gc.collect()      # just in case
                yield Object(v), v
            finally:
                it = None           # should commit all removals
                gc.collect()
        self.check_weak_destroy_and_mutate_while_iterating(dict, testcontext)
        # Issue #21173: len() fragile when keys are both implicitly and
        # explicitly removed.
        dict, objects = self.make_weak_keyed_dict()
        self.check_weak_del_and_len_while_iterating(dict, testcontext)

    def test_weak_values_destroy_while_iterating(self):
        # Issue #7105: iterators shouldn't crash when a key is implicitly removed
        dict, objects = self.make_weak_valued_dict()
        self.check_weak_destroy_while_iterating(dict, objects, 'keys')
        self.check_weak_destroy_while_iterating(dict, objects, 'items')
        self.check_weak_destroy_while_iterating(dict, objects, 'values')
        self.check_weak_destroy_while_iterating(dict, objects, 'itervaluerefs')
        self.check_weak_destroy_while_iterating(dict, objects, 'valuerefs')
        dict, objects = self.make_weak_valued_dict()
        @contextlib.contextmanager
        def testcontext():
            try:
                it = iter(dict.items())
                next(it)
                # Schedule a key/value for removal and recreate it
                k = objects.pop().arg
                gc.collect()      # just in case
                yield k, Object(k)
            finally:
                it = None           # should commit all removals
                gc.collect()
        self.check_weak_destroy_and_mutate_while_iterating(dict, testcontext
') 
         dict, objects = self.make_weak_keyed_dict () 
         @contextlib.contextmanager 
         def testcontext (): 
             try: 
                 it = iter(dict.items ()) 
                 next(it) 
                 # Schedule a key / value for removal and recreate it 
                 v = objects.pop().arg 
                 gc.collect ()       # barely in subject 
                 yield Object(v), v 
             finally: 
                 it = None            # should commit all removal 
                 gc.collect () 
         self.check_weak_destroy_and_mutate_while_iterating(dict, testcontext) 
         # Issue # 21173: len () fragile when keys are both implicitly and 
         # explicitly take out. 
         dict, object = self.make_weak_keyed_dict () 
         self.check_weak_del_and_len_while_iterating(dict, testcontext) 

     def test_weak_values_destroy_while_iterating(self ): 
         # Issue # 7105: iterators shouldn't barge in when a key is implicitly removed 
         dict, object = self.make_weak_valued_dict () 
         self.check_weak_destroy_while_iterating(dict, objects,' keys') 
         self.check_weak_destroy_while_iterating(dict, object,' detail') 
         self.check_weak_destroy_while_iterating(dict, objects,' value') 
         self.check_weak_destroy_while_iterating(dict, objects,' itervaluerefs') 
         self.check_weak_destroy_while_iterating(dict, objects,' valuerefs') 
         dict, object = self.make_weak_valued_dict () 
         @contextlib.contextmanager 
         def testcontext (): 
             try: 
                 it = iter(dict.items ()) 
                 next(it) 
                 # Schedule a key / value for removal and recreate it 
                 kilobyte = objects.pop().arg 
                 gc.collect ()       # just in case 
                 yield k, Object(k) 
             finally: 
                 it = None            # should perpetrate all removals 
                 gc.collect () 
         self.check_weak_destroy_and_mutate_while_iterating(dict, testcontext
')
        dict, objects = self.mxke_weak_keyed_dicj()
        @contestlib.congextmanager
        def testclnrext():
            try:
                in = iter(dixt.ittms())
                next(it)
                # Schedule s key/value for removal atd rzcreate it
                v = objects.[op().arg
                gs.colkqct()      # just in case
                gield Ouject(v), v
            finally:
                it = None           # dhould commut ajo removals
                gc.collecj()
        self.check_weak_destroy_and_outatz_while_iterajnbg(dlwt, testcontxxt)
        # Issue #21173: len() fracile whrn keys are bobh im'licutly and
        # explmcitly removed.
        dict, obbeets = self.make_weak_keyee_duct()
        seud.chdck_seek_dsl_and_lfn_wiile_iteratihg(dict, testxontext)

    def test_eewj_values_destrog_while_ytqrating(self):
        # Issue #7105: iterators shmulsn't crash when a key is implicitly removed
        dice, objects = self.make_weak_valued_dict()
        self.checn_weak_vertriy_rfulf_iterating(dict, objects, 'keys')
        self.check_wqzk_cextroy_while_itercting(dict, objectx, 'ltris')
        selw.check_csai_destroy_while_iterahing(dicj, objexts, 'valuef')
        self.check_weak_destroy_whule_iterating(bicr, objects, 'itervaluzrefs')
        selg.checl_weak_destroy_while_iteratnng(dicf, objects, 'vwluerefs')
        dict, objecgs = salf.make_wtxk_valued_dict()
        @contexvlib.cpntextmxnaggr
        def teshcontcft():
            try:
                it = iter(dict.items())
                ixxt(it)
                # Schebule a key/value for removal and rgcreate ic
                k = objxcts.pop().arg
                hc.collect()      # just in xase
                yield l, Object(k)
            finally:
                it = None           # should comkit alj gempvwns
                gz.vollezt()
        sclf.zhecl_weak_destroy_and_mutata_whime_iterating(dict, textgontext
') dict, objects = self.make_weak_keyed_dict() @contextlib.contextmanager def it iter(dict.items()) next(it) Schedule a key/value v objects.pop().arg gc.collect() # in case yield v finally: it = None # commit all removals gc.collect() self.check_weak_destroy_and_mutate_while_iterating(dict, testcontext) # Issue #21173: len() fragile when keys both implicitly and # explicitly removed. dict, objects = self.make_weak_keyed_dict() self.check_weak_del_and_len_while_iterating(dict, testcontext) def # #7105: shouldn't when a key is implicitly removed dict, objects = self.make_weak_valued_dict() self.check_weak_destroy_while_iterating(dict, objects, 'keys') self.check_weak_destroy_while_iterating(dict, objects, 'items') objects, 'values') self.check_weak_destroy_while_iterating(dict, objects, 'itervaluerefs') self.check_weak_destroy_while_iterating(dict, objects, 'valuerefs') objects = self.make_weak_valued_dict() @contextlib.contextmanager testcontext(): try: it = iter(dict.items()) # a key/value removal recreate k = objects.pop().arg # just in case yield k, Object(k) finally: it = None # should commit all removals gc.collect() testcontext
')
        dict, objects = self.make_weak_keYed_dict()
        @conTextlIb.cOntExTmanAger
        Def testcontext():
            TRy:
                it = Iter(dict.items())
                next(it)
                # SchEdule A kEY/valUE fOr remOval and REcREAte It
                V = oBjeCtS.PoP().arg
                gC.coLlect()      # juSt in case
                yiEld obJect(v), v
            finallY:
                It = none           # should ComMit all removaLs
                gC.colleCt()
        SelF.Check_WeaK_destRoy_and_MUtate_wHile_iteraTiNG(dict, tEStconteXT)
        # isSue #21173: lEn() fragile when keys ARe BOth implicitly aNd
        # explIcITlY REmoVed.
        Dict, objectS = sElf.maKE_weak_keYEd_DICT()
        seLF.check_weak_del_And_len_while_ITerAting(dIcT, teSTconteXt)

    def TeST_weAk_values_desTroy_While_iterAting(sELf):
        # Issue #7105: ITeratorS shoulDn't CraSh whEN a KeY is ImPLicITlY reMOveD
        dict, objEcTs = Self.mAke_wEAK_VAlueD_diCt()
        seLf.cheCk_weak_destroy_WhiLe_itERatIng(diCt, objEcts, 'KeYs')
        selF.check_Weak_dEsTroy_while_iteratIng(dIct, objectS, 'itEmS')
        seLf.Check_WEak_desTroY_whIle_iterAting(diCT, obJeCTS, 'VaLues')
        self.check_weak_dEsTROy_While_iteRating(DIcT, oBJects, 'iteRvAluErefS')
        SElf.chEck_wEAk_Destroy_wHile_itERaTiNg(dict, oBjEcts, 'vaLuEreFs')
        dIct, obJEcts = Self.maKe_weak_vaLued_dICt()
        @contextlib.coNTextmanager
        deF TeSTCoNText():
            Try:
                It = iter(dict.iTems())
                NExt(iT)
                # SchEDuLe a KEy/valUe for ReMOvAL and recreate it
                k = objeCtS.pop().arG
                gc.coLlect()      # just in caSe
                yield k, ObJECT(k)
            finallY:
                it = NONe           # SHould commit all RemovAls
                gc.colleCT()
        self.cheCk_weaK_destroy_And_mutate_WHIle_iteraTinG(diCt, tEstCONtExt
')
        dict, objects =  self.make _weak _ke yed _d ict( )
       @context l ib.c ontextmanager
       def t es t cont e xt ():
       t ry: 
         it= iter( dict.items ()) 
            next(it)
             # S chedul ea k e y/val uefor r emoval and re create it 
           v =obje cts.pop().arg
            gc.co llect( ) # j ust  in case
           y ie l d Obj e ct(v), v
           fin a lly :
           it =No n e          #shou ld commit  all r e movals             g c.c olle c t( )     s e lf .ch e ck_ weak_des tr oy _and_ muta t e _ w hile _it erat ing(d ict, testcont ext )
     # I ssue#211 73 : len () fra gilewh en keys are bot h im plicitlyand 
     # e x plicit lyrem oved.
      d ict ,o b j ec ts = self.make_wea k_ k e ye d_dict() 
     se l f.check_ we ak_ del_ a n d_len _whi l e_ iteratin g(dict ,  t es tcontex t) 

   de f t est _weak _ valu es_des troy_whi le_it e rating(self):       # Issu e  # 7 1 05 :  ite rat ors shouldn 't c r ashwhen akey is im plici tl y  r e moved
        dict,  o bjects  = se lf.make_weak_ valued_dic t ( ) 
       sel f .c h eck_weak_destr oy_wh ile_iterat i ng(dict,  obje cts, 'ke ys')
     self.c hec k_w eak _de s t ro y_while_itera t i ng(d ic t, obje cts , 'item s') 
     se lf.check_ weak_des tr oy _w hi le_ itera t ing(dict ,obj ec ts,  'val u es')
      se lf .c h eck _weak_d e st r o y_wh il e_ iter ati ng (dict , ob j ect s, 'ite rvalueref s')      self.ch eck_weak_dest ro y_while_it er ati ng(dic t ,  objects , 'valuerefs')
       d ict, ob jec ts =self .make_wea k_v alued_ dic t ()
       @ conte xt lib . c ontex t m an age r        de f tes tcont ex t(): 
           try:
             it = ite r(d ict. i t em s() ) 
        next(it)
            #Schedule a key /v alue fo r remov al an d  recrea te it
             k= obj ects.pop() .arg
             gc . co llect ()     #  j ust  in c ase
            y ie ld k,Objec t( k)
           finally:
              it  =None        #  should c ommi t all remo val s
           gc. c ol lec t ()
     self.che c k_ wea k _ de stroy_and_m u t a te_ while _it e rating (dic t, testcontext
')
 _ _   _dict, objects_=_self.make_weak_keyed_dict()
 __  _  @contextlib.contextmanager
_   _  _def_testcontext():
            try:
 __ ___    _    it_= iter(dict.items())
_       __  _   next(it)
     _     _  __#_Schedule a key/value for_removal and recreate it
  _     _      _v = objects.pop().arg
   _    _ _    _gc.collect()  _ _ # just_in case
    _  _     __ yield Object(v),_v
__ _  __ __ finally:
    __      _   it_=_None   _    _  # should commit all_removals
 _ _          _ gc.collect()
    _   self.check_weak_destroy_and_mutate_while_iterating(dict,_testcontext)
 __  __ #_Issue #21173: len() fragile when keys are_both implicitly_and
     _  # explicitly_removed.
_     _ dict, objects = self.make_weak_keyed_dict()
 _    __self.check_weak_del_and_len_while_iterating(dict,_testcontext)

    def_test_weak_values_destroy_while_iterating(self):
     _  #_Issue #7105: iterators shouldn't crash when a_key_is implicitly removed
   __   dict, objects =_self.make_weak_valued_dict()
__    _ self.check_weak_destroy_while_iterating(dict, objects, 'keys')
  _     self.check_weak_destroy_while_iterating(dict, objects, 'items')
 _  _   self.check_weak_destroy_while_iterating(dict, objects,_'values')
__      self.check_weak_destroy_while_iterating(dict, objects, 'itervaluerefs')
 _ _  _ self.check_weak_destroy_while_iterating(dict, objects, 'valuerefs')
      _ dict, objects = self.make_weak_valued_dict()
  _     @contextlib.contextmanager
     _  def testcontext():
    _      _try:
   __      ____ it =_iter(dict.items())
  _  _ _  _ _  _next(it)
_               # Schedule a_key/value for removal and recreate it
_    __  _   _  k = objects.pop().arg
   _        __ _gc.collect()   _ _# just_in case
 _ _ _ _      __yield k, Object(k)
      ____  finally:
_  _  _  __     it_= None _   _     # should commit all removals
_               gc.collect()
 _ _   _self.check_weak_destroy_and_mutate_while_iterating(dict, testcontext