+
    BiW                         ^ RI t ^ RIt^ RIHtHt ^ RIHt  ! R R] P                  4      t]R8X  d   ] P                  ! 4        R# R# )    N)check_syntax_errorcpython_only)
gc_collectc                   4  a  ] tR t^t o R tR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR t]R 4       tR t]R 4       tR t R t!R t"R t#R  t$R! t%R" t&R# t'R$ t(R% t)R& t*R' t+]R( 4       t,R) t-R*t.V t/R+# ),
ScopeTestsc                    R  pV! ^4      pV! ^
4      pV P                  V! ^4      ^4       V P                  V! R4      ^4       R# )c                    a  V 3R  lpV# )c                    < SV ,           # N yxs   &&/usr/lib/python3.14/test/test_scope.pyadder?ScopeTests.testSimpleNesting.<locals>.make_adder.<locals>.adder       1u    r   r   r   s   f r   
make_adder0ScopeTests.testSimpleNesting.<locals>.make_adder   s    Lr   NassertEqual)selfr   incplus10s   &   r   testSimpleNestingScopeTests.testSimpleNesting
   sC    	
 mBQ#Q'r   c                    R  pV! ^4      pV! ^
4      pV P                  V! ^4      ^4       V P                  V! R4      ^4       R# )c                    a  V 3R  lpV! 4       # )c                     < V3R  lp V # )c                    < SV ,           # r   r   r   s   &r   r   NScopeTests.testExtraNesting.<locals>.make_adder2.<locals>.extra.<locals>.adder       q5Lr   r   )r   r   s    r   extra?ScopeTests.testExtraNesting.<locals>.make_adder2.<locals>.extra   s    !r   r   )r   r&   s   f r   make_adder20ScopeTests.testExtraNesting.<locals>.make_adder2   s     7Nr   Nr   r   )r   r(   r   r   s   &   r   testExtraNestingScopeTests.testExtraNesting   sC    	 !nRQ#Q'r   c                    R  pV! ^ 4      pV! ^	4      pV P                  V! ^4      ^4       V P                  V! R4      ^4       R# )c                 &   a  V 3R  lpS ^,           o V# )c                    < SV ,           # r   r   r   s   &r   r   EScopeTests.testSimpleAndRebinding.<locals>.make_adder3.<locals>.adder)   r   r   r   r   s   f r   make_adder36ScopeTests.testSimpleAndRebinding.<locals>.make_adder3(   s    AALr   Nr   r   )r   r0   r   r   s   &   r   testSimpleAndRebinding!ScopeTests.testSimpleAndRebinding&   sC    	 !nQQ#Q'r   c                   a V3R  lp^oV! 4       pV P                  V! ^4      ^4       ^
oV P                  V! R4      ^4       R# )c                     < V3R  lp V ! 4       # )c                     < V3R  lp V ! 4       # )c                     < V3R  lp V # )c                    < SV ,           # r   r   r   global_xs   &r   r   bScopeTests.testNestingGlobalNoFree.<locals>.make_adder4.<locals>.nest.<locals>.nest.<locals>.adder9   s    '!|+r   r   )r   r:   s    r   nestSScopeTests.testNestingGlobalNoFree.<locals>.make_adder4.<locals>.nest.<locals>.nest8   s    , Lr   r   r<   r:   s    r   r<   EScopeTests.testNestingGlobalNoFree.<locals>.make_adder4.<locals>.nest7   s    ! vr   r   r>   s    r   make_adder47ScopeTests.testNestingGlobalNoFree.<locals>.make_adder46   s     6Mr   Nr   r   )r   r@   r   r:   s   &  @r   testNestingGlobalNoFree"ScopeTests.testNestingGlobalNoFree4   sC    	 q1%rA&r   c                    R  pV! ^4      pV! ^
4      pV P                  V! ^4      ^4       V P                  V! R4      ^4       R# )c                 ,   a   ! V 3R  lR4      pV! 4       # )c                   .   <a  ] tR t^It o V3R ltRtV tR# )FScopeTests.testNestingThroughClass.<locals>.make_adder5.<locals>.Adderc                   < SV,           # r   r   )r   r   r   s   &&r   __call__OScopeTests.testNestingThroughClass.<locals>.make_adder5.<locals>.Adder.__call__J   r%   r   r   N)__name__
__module____qualname____firstlineno__rI   __static_attributes____classdictcell____classdict__r   s   @r   AdderrG   I   s     ! !r   rS   r   )r   rS   s   f r   make_adder57ScopeTests.testNestingThroughClass.<locals>.make_adder5H   s    ! ! 7Nr   Nr   r   )r   rT   r   r   s   &   r   testNestingThroughClass"ScopeTests.testNestingThroughClassF   sC    	 !nRQ#Q'r   c                    R  pV! ^4      pV! ^
4      pV P                  V! ^4      ^4       V P                  V! R4      ^4       R# )c                     R  pV s V# )c                     \         V ,           # r   global_nest_xr   s   &r   r   MScopeTests.testNestingPlusFreeRefToGlobal.<locals>.make_adder6.<locals>.adderX   s    $q((r   r[   r   s   & r   make_adder6>ScopeTests.testNestingPlusFreeRefToGlobal.<locals>.make_adder6V   s    )MLr   Nr   r   )r   r_   r   r   s   &   r   testNestingPlusFreeRefToGlobal)ScopeTests.testNestingPlusFreeRefToGlobalT   sC    	 !nRQ$Q'r   c                L    R  pV! ^
4      pV P                  V! ^4      ^/4       R# )c                     R  pV! ^4      # )c                    a ^*oV3R lpV# )*   c                    < SV ,           # r   r   )zr   s   &r   hEScopeTests.testNearestEnclosingScope.<locals>.f.<locals>.g.<locals>.hh   r%   r   r   )r   ri   r   s   & @r   g:ScopeTests.testNearestEnclosingScope.<locals>.f.<locals>.gf   s    !r   r   r   rk   s   & r   f/ScopeTests.testNearestEnclosingScope.<locals>.fe   s    
 Q4Kr   Nr   )r   rn   	test_funcs   &  r   testNearestEnclosingScope$ScopeTests.testNearestEnclosingScopec   s&    	 bE	1r*r   c                p   a R  oV3R lpV! ^^^4      pV! ^^^4      pV P                  V! 4       ^'4       R# )c                     V # r   r   r   s   &r   identity9ScopeTests.testMixedFreevarsAndCellvars.<locals>.identityr   s    Hr   c                    <a a VV V3R  lpV# )c                 B   <aa V S,           p VVVV3R  lpVS,           oV# )c                  0   < S! SS S,           ,          4      # r   r   )brv   r   rh   s   r   ri   HScopeTests.testMixedFreevarsAndCellvars.<locals>.f.<locals>.g.<locals>.hx   s     $AQK00r   r   )ar{   cri   r   rv   r   rh   s   &f& @r   rk   =ScopeTests.testMixedFreevarsAndCellvars.<locals>.f.<locals>.gv   s&    E1 1 Er   r   )r   r   rh   rk   rv   s   f&f r   rn   2ScopeTests.testMixedFreevarsAndCellvars.<locals>.fu   s     Hr   Nr   )r   rn   rk   ri   rv   s   &   @r   testMixedFreevarsAndCellvars'ScopeTests.testMixedFreevarsAndCellvarsp   s;    			 aAJaAJb!r   c                  a R  pV! 4       pV P                  VP                  4       R4       V P                  VP                  4       R4       V P                  VP                  4       R4       Ro ! V3R lR4      pV! 4       pV P                  VP                  4       R4       V P                  VP                  4       R4       V P                  VP                  4       R4       R# )c                  0   a R o ! V3R lR4      p V ! 4       # )varc                   @   <a  ] tR t^t o R tV3R ltR tR tRtV t	R# ):ScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Testc                    R # methodr   r   s   &r   method_and_varIScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Test.method_and_var   s    #r   c                   < S# r   r   r   r   s   &r   test?ScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Test.test   s	    ))r   c                    \        R 4      # globalstrr   s   &r   actual_globalHScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Test.actual_global   s    x=(r   c                    \        V 4      # r   r   r   s   &r   r   >ScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Test.str   s    t9$r   r   N
rK   rL   rM   rN   r   r   r   r   rO   rP   rR   r   s   @r   Testr      s     $*)% %r   r   r   )r   r   s    @r   r   ,ScopeTests.testFreeVarInMethod.<locals>.test   s    "N% % 6Mr   r   r   r   c                   @   <a  ] tR t^t o R tV3R ltR tR tRtV t	R# ),ScopeTests.testFreeVarInMethod.<locals>.Testc                    R # r   r   r   s   &r   r   ;ScopeTests.testFreeVarInMethod.<locals>.Test.method_and_var   s    r   c                   < S# r   r   r   s   &r   r   1ScopeTests.testFreeVarInMethod.<locals>.Test.test   s	    %%r   c                    \        R 4      # r   r   r   s   &r   r   :ScopeTests.testFreeVarInMethod.<locals>.Test.actual_global   s    8}$r   c                    \        V 4      # r   r   r   s   &r   r   0ScopeTests.testFreeVarInMethod.<locals>.Test.str   s    4y r   r   Nr   r   s   @r   r   r      s      &%! !r   r   N)r   r   r   r   )r   r   tr   r   s   &   @r   testFreeVarInMethodScopeTests.testFreeVarInMethod   s    	 F5)))+X6*H5		! 		! F5)))+X6*H5r   c                t    R ^/R lpV P                  V! ^*R7      ^24       V P                  V! 4       ^4       R# )r}   c                 ,   a  V 3R  lpV! 4       ^,           # )c                     < S ^,           # )   r   r}   s   r   bar8ScopeTests.testCellIsKwonlyArg.<locals>.foo.<locals>.bar   r   r   r   )r}   r   s   d r   foo+ScopeTests.testCellIsKwonlyArg.<locals>.foo   s    519r   r   Nr   )r   r   s   & r   testCellIsKwonlyArgScopeTests.testCellIsKwonlyArg   s6    	R 	
 	rB'#r   c                    R  pV! 4       pR pV! V4      pVP                   w  pV! 4       pV P                  Wb4       V P                  We4       R# )c                  4   a ^*oV3R lp V P                   w  pV# )rf   c                     < S # r   r   values   r   innerCScopeTests.testCellIsArgAndEscapes.<locals>.external.<locals>.inner       r   __closure__r   cellr   s     @r   external4ScopeTests.testCellIsArgAndEscapes.<locals>.external       E%%EDKr   c                    a  V 3R  lpV# )c                     < S # r   r   )args   r   eggs>ScopeTests.testCellIsArgAndEscapes.<locals>.spam.<locals>.eggs       
r   r   )r   r   s   f r   spam0ScopeTests.testCellIsArgAndEscapes.<locals>.spam   s    Kr   Nr   assertIsassertIsNotr   r   cell_extr   r   cell_closure	cell_eggss   &      r   testCellIsArgAndEscapes"ScopeTests.testCellIsArgAndEscapes   sN    
	 :	
 H~((F	i*1r   c                    R  pV! 4       pR pV! V4      pVP                   w  pV! 4       pV P                  Wb4       V P                  We4       R# )c                  4   a ^*oV3R lp V P                   w  pV# )rf   c                     < S # r   r   r   s   r   r   EScopeTests.testCellIsLocalAndEscapes.<locals>.external.<locals>.inner   r   r   r   r   s     @r   r   6ScopeTests.testCellIsLocalAndEscapes.<locals>.external   r   r   c                    a V oV3R  lpV# )c                     < S # r   r   )r   s   r   r   @ScopeTests.testCellIsLocalAndEscapes.<locals>.spam.<locals>.eggs   s    r   r   )r   r   r   s   & @r   r   2ScopeTests.testCellIsLocalAndEscapes.<locals>.spam   s    DKr   Nr   r   s   &      r   testCellIsLocalAndEscapes$ScopeTests.testCellIsLocalAndEscapes   sN    
	 :	 H~((F	i*1r   c                <    R  pV P                  V! ^4      R4       R# )c                 D   a V3R  loV ^ 8  d	   S! V 4      # \        R4      h)c                 B   < V ^ 8X  d   ^# V S! V ^,
          4      ,          # )r   r   )nfacts   &r   r   1ScopeTests.testRecursion.<locals>.f.<locals>.fact   s    6tAE{?*r   zx must be >= 0)
ValueError)r   r   s   &@r   rn   #ScopeTests.testRecursion.<locals>.f   s&    +
 AvAw !122r   i  Nr   r   rn   s   & r   testRecursionScopeTests.testRecursion   s    		3 	1s#r   c                f    \        V R 4       \        V R4       \        V R4       \        V R4       R# )zif 1:
            def unoptimized_clash1(strip):
                def f(s):
                    from sys import *
                    return getrefcount(s) # ambiguity: free or local
                return f
            zif 1:
            def unoptimized_clash2():
                from sys import *
                def f(s):
                    return getrefcount(s) # ambiguity: global or local
                return f
            zif 1:
            def unoptimized_clash2():
                from sys import *
                def g():
                    def f(s):
                        return getrefcount(s) # ambiguity: global or local
                    return f
            zif 1:
            def f():
                def g():
                    from sys import *
                    return getrefcount # global or local?
            N)r   r   s   &r   testUnoptimizedNamespaces$ScopeTests.testUnoptimizedNamespaces   sD    4 " 	 	4 " 	 	4 " 	 	4 " 	r   c                  a	 R  pV! ^4      pV! ^
4      pV P                  V! ^4      ^4       V P                  V! ^4      ^4       R pV! ^4      pV! ^
4      pV P                  V! ^4      ^4       V P                  V! ^4      ^4       V	3R lp^o	V! R4      pV P                  V! ^4      ^4       R pV! ^^^4      pV! ^^^4      pV P                  V! 4       ^4       R# )c                    a  V 3R  l# )c                    < SV ,           # r   r   r   s   &r   <lambda>:ScopeTests.testLambdas.<locals>.<lambda>.<locals>.<lambda>  s	    Qr   r   ru   s   fr   r   (ScopeTests.testLambdas.<locals>.<lambda>  s    r   c                    a  V 3R  l! 4       # )c                     < V 3R  l# )c                    < SV ,           # r   r   r   s   &r   r   LScopeTests.testLambdas.<locals>.<lambda>.<locals>.<lambda>.<locals>.<lambda>!  s	    1q5r   r   ru   s   r   r   r   !  s    r   r   ru   s   fr   r   r   !  s	    03r   c                    < V3R  l# )c                    < SV ,           # r   r   r9   s   &r   r   r   '  s	    Ar   r   )r   r:   s   &r   r   r   '  s    -r   Nc                    aa VV3R  l# )c                    <a VVV3R  l# )c                  $   < SS S,           ,          # r   r   )r{   r   rh   s   r   r   r   ,  s    a1q5kr   r   )r}   r{   r~   r   rh   s   &f&r   r   r   ,  s    -Ar   r   )r   r   rh   s   &ffr   r   r   ,  s    Ar   r   )
r   f1r   r   f2f3f8rk   ri   r:   s
   &        @r   testLambdasScopeTests.testLambdas  s    &eBQ#B'3eBQ#B'-hQ#Aq!QKaAJb!r   c                j    R  pR pV P                  \        V4       V P                  \        V4       R# )c                  .   a \        S4       V3R  lp ^oR# )c                     < S # r   r   r]   s   r   r   @ScopeTests.testUnboundLocal.<locals>.errorInOuter.<locals>.inner5      r   Nprintr   r   s    @r   errorInOuter1ScopeTests.testUnboundLocal.<locals>.errorInOuter3  s    !HAr   c                  &   a V3R  lp V ! 4        ^oR# )c                     < S # r   r   r]   s   r   r   @ScopeTests.testUnboundLocal.<locals>.errorInInner.<locals>.inner:  r	  r   Nr   r  s    @r   errorInInner1ScopeTests.testUnboundLocal.<locals>.errorInInner9  s    GAr   NassertRaisesUnboundLocalError	NameErrorr   r  r  s   &  r   testUnboundLocalScopeTests.testUnboundLocal1  s/    		 	+\:)\2r   c                j    R  pR pV P                  \        V4       V P                  \        V4       R# )c                  0   a ^o>\        S4       V3R lp R# )   c                     < S # r   r   r]   s   r   r   IScopeTests.testUnboundLocal_AfterDel.<locals>.errorInOuter.<locals>.innerJ  r	  r   Nr
  r  s    @r   r  :ScopeTests.testUnboundLocal_AfterDel.<locals>.errorInOuterF  s    A!Hr   c                  (   a V3R  lp ^o>V ! 4        R# )c                     < S # r   r   r]   s   r   r   IScopeTests.testUnboundLocal_AfterDel.<locals>.errorInInner.<locals>.innerN  r	  r   Nr   r  s    @r   r  :ScopeTests.testUnboundLocal_AfterDel.<locals>.errorInInnerM  s    AGr   Nr  r  s   &  r   testUnboundLocal_AfterDel$ScopeTests.testUnboundLocal_AfterDelB  s/    		 	+\:)\2r   c                6    \        R RV P                  /4       R# )a  if 1:
            global_x = 1
            def f():
                global_x += 1
            try:
                f()
            except UnboundLocalError:
                pass
            else:
                fail('scope of global_x not correctly determined')
            failN)execr(  r   s   &r   testUnboundLocal_AugAssign%ScopeTests.testUnboundLocal_AugAssignW  s     
 $))$
	&r   c                    R  pV P                  V! ^^^4      ! 4       R4       R pV P                  V! ^R7      ! 4       R,          ^4       R# )c                     a  V 3R  lpV# )c                     < S # r   r   )lsts   r   returnerIScopeTests.testComplexDefinitions.<locals>.makeReturner.<locals>.returnerh  r   r   r   )r/  r0  s   j r   makeReturner7ScopeTests.testComplexDefinitions.<locals>.makeReturnerg  s    Or   c                     a  V 3R  lpV# )c                     < S # r   r   )kwargss   r   r0  JScopeTests.testComplexDefinitions.<locals>.makeReturner2.<locals>.returnero  s    r   r   )r6  r0  s   l r   makeReturner28ScopeTests.testComplexDefinitions.<locals>.makeReturner2n  s    Or   r   r}   N)r        r   )r   r2  r8  s   &  r   testComplexDefinitions!ScopeTests.testComplexDefinitionse  sI    	
 	a!,.8	
 	,.s3R8r   c                    \        R 4       R# )a;  if 1:
            # I
            x = 7
            def f():
                x = 1
                def g():
                    global x
                    def i():
                        def h():
                            return x
                        return h()
                    return i()
                return g()
            self.assertEqual(f(), 7)
            self.assertEqual(x, 7)

            # II
            x = 7
            def f():
                x = 1
                def g():
                    x = 2
                    def i():
                        def h():
                            return x
                        return h()
                    return i()
                return g()
            self.assertEqual(f(), 2)
            self.assertEqual(x, 7)

            # III
            x = 7
            def f():
                x = 1
                def g():
                    global x
                    x = 2
                    def i():
                        def h():
                            return x
                        return h()
                    return i()
                return g()
            self.assertEqual(f(), 2)
            self.assertEqual(x, 2)

            # IV
            x = 7
            def f():
                x = 3
                def g():
                    global x
                    x = 2
                    def i():
                        def h():
                            return x
                        return h()
                    return i()
                return g()
            self.assertEqual(f(), 2)
            self.assertEqual(x, 2)

            # XXX what about global statements in class blocks?
            # do they affect methods?

            x = 12
            class Global:
                global x
                x = 13
                def set(self, val):
                    x = val
                def get(self):
                    return x

            g = Global()
            self.assertEqual(g.get(), 13)
            g.set(15)
            self.assertEqual(g.get(), 13)
            Nr)  r   s   &r   testScopeOfGlobalStmt ScopeTests.testScopeOfGlobalStmtu  s     	 O O	r   c                   a  ! V3R  lR4      oV3R lp\        ^d4       F
  pV! 4        K  	  \        4        V P                  SP                  ^ 4       R# )c                   >   <a  ] tR tRt o ^ tV3R ltV3R ltRtV tR# )!ScopeTests.testLeaks.<locals>.Fooi  c                :   < S;P                   ^,          un         R# r  Ncountr   Foos   &r   __init__*ScopeTests.testLeaks.<locals>.Foo.__init__      		Q	r   c                :   < S;P                   ^,          un         R# rF  rG  rI  s   &r   __del__)ScopeTests.testLeaks.<locals>.Foo.__del__  rM  r   r   N)	rK   rL   rM   rN   rH  rK  rO  rO   rP   )rR   rJ  s   @r   rJ  rD    s     E r   rJ  c                  2   <a S! 4       oV3R  lp V ! 4        R# )c                     < S # r   r   ru   s   r   r   ,ScopeTests.testLeaks.<locals>.f1.<locals>.f2  r	  r   Nr   )r   r   rJ  s    @r   r    ScopeTests.testLeaks.<locals>.f1  s    ADr   N)ranger   r   rH  )r   r   irJ  s   &  @r   	testLeaksScopeTests.testLeaks  sB    	 		 sAD  	A&r   c                    \        R 4       R# )a  if 1:
            def test(x):
                class Foo:
                    global x
                    def __call__(self, y):
                        return x + y
                return Foo()

            x = 0
            self.assertEqual(test(6)(2), 8)
            x = -1
            self.assertEqual(test(3)(2), 5)

            looked_up_by_load_name = False
            class X:
                # Implicit globals inside classes are be looked up by LOAD_NAME, not
                # LOAD_GLOBAL.
                locals()['looked_up_by_load_name'] = True
                passed = looked_up_by_load_name

            self.assertTrue(X.passed)
            Nr?  r   s   &r   testClassAndGlobalScopeTests.testClassAndGlobal  s      	r   c           	         R  pV! ^4      ! ^4      pV P                  RV4       VR V P                  VR^R^R^/4       R# )c                    a  V 3R  lpV# )c                 J   <a  V 3R  lpSS ,           pS ^,          o \        4       # )c                    < SV ,           # r   r   )rh   r   s   &r   ri   >ScopeTests.testLocalsFunction.<locals>.f.<locals>.g.<locals>.h  r%   r   )locals)r   ri   wr   s   f  r   rk   3ScopeTests.testLocalsFunction.<locals>.f.<locals>.g  s!    !EQxr   r   rm   s   f r   rn   (ScopeTests.testLocalsFunction.<locals>.f  s      Hr   ri   r   r   rb  N)assertInr   )r   rn   ds   &  r   testLocalsFunctionScopeTests.testLocalsFunction  sH    	 aDGc1cFS!S!S!45r   c                    R  pV P                  V! ^4      P                  ^4       R pV! ^4      P                  pV P                  RV4       V P	                  RV4       R# )c                 "   a   ! V 3R  lR4      pV# )c                   @   <a  ] tR tRt o ^tV3R lt]! 4        RtV tR# )0ScopeTests.testLocalsClass.<locals>.f.<locals>.Ci  c                   < S# r   r   r   r   s   &r   m2ScopeTests.testLocalsClass.<locals>.f.<locals>.C.m      Hr   r   N)	rK   rL   rM   rN   r   ro  ra  rO   rP   rQ   s   @r   Crl    s     r   rr  r   r   rr  s   f r   rn   %ScopeTests.testLocalsClass.<locals>.f  s     
 Hr   c                 "   a   ! V 3R  lR4      pV# )c                   N   <a  ] tR tRt o  ZtV3R lt]! ]! 4       4      tRt	V t
R# )rl  i  c                   < S# r   r   rn  s   &r   ro  rp  !  rq  r   r   N)rK   rL   rM   rN   r   ro  listra  rh   rO   rP   rQ   s   @r   rr  rl    s     Nr   rr  r   rs  s   f r   rn   rt    s    # #
 Hr   r   r   N)r   r   rh   assertNotInre  )r   rn   varnamess   &  r   testLocalsClassScopeTests.testLocalsClass	  sS    	 	1$	 Q466h'c8$r   c                   a ^ RI pV P                  VP                  VP                  4       4       VP                  R 4       ^o ! V3R lR4      pV P	                  S^4       R# )r   Nc                     R # r   r   )r}   r{   r~   s   &&&r   r   6ScopeTests.testLocalsClass_WithTrace.<locals>.<lambda>2  s    $r   c                   .   <a  ] tR tRt o V3R ltRtV tR# )/ScopeTests.testLocalsClass_WithTrace.<locals>.Ci5  c                   < S# r   r   rn  s   &r   rn   1ScopeTests.testLocalsClass_WithTrace.<locals>.C.f6  r	  r   r   N)rK   rL   rM   rN   rn   rO   rP   rQ   s   @r   rr  r  5  s      r   rr  )sys
addCleanupsettracegettracer   )r   r  rr  r   s   &  @r   testLocalsClass_WithTrace$ScopeTests.testLocalsClass_WithTrace*  sN     	clln5&'	 	 	Br   c                z    R  pV! ^4      ! 4       pV P                  VP                  VP                  4       4       R# )c                 "   a   ! V 3R  lR4      pV# )c                   4   <a  ] tR tRt o V3R lt ZtRtV tR# )1ScopeTests.testBoundAndFree.<locals>.f.<locals>.Ci?  c                   < S# r   r   rn  s   &r   ro  3ScopeTests.testBoundAndFree.<locals>.f.<locals>.C.m@  rq  r   r   N)rK   rL   rM   rN   ro  r}   rO   rP   rQ   s   @r   rr  r  ?  s     r   rr  r   rs  s   f r   rn   &ScopeTests.testBoundAndFree.<locals>.f>  s      Hr   N)r   r}   ro  )r   rn   insts   &  r   testBoundAndFreeScopeTests.testBoundAndFree;  s.    	 tv*r   c                "  a ^ RI pV3R loR p ! R R4      pV P                  VP                  VP                  4       4       VP                  S4       V! RVR4       VP                  R4       V P	                  \
        VP                  4       R# )r   Nc                    < S# r   r   )r}   r{   r~   tracers   &&&r   r  7ScopeTests.testInteractionWithTraceFunc.<locals>.tracerL  s    Mr   c                 b   a Vw  poV^8X  d"   SR8X  d   RVP                   : RV : 2oV3R l# R# )r   ___c                    < \        V S4      # r   )getattr)objdess   &r   r   NScopeTests.testInteractionWithTraceFunc.<locals>.adaptgetter.<locals>.<lambda>T  s    73#4r   N)rK   )nameklassgetterkindr  s   &&& @r   adaptgetter<ScopeTests.testInteractionWithTraceFunc.<locals>.adaptgetterO  s3    ID#qy"9',~~t<C44 r   c                       ] tR tRtRtR# ):ScopeTests.testInteractionWithTraceFunc.<locals>.TestClassiV  r   N)rK   rL   rM   rN   rO   r   r   r   	TestClassr  V  s    r   r  r   )r  r  )r  r  r  r  r  	TypeError)r   r  r  r  r  s   &   @r   testInteractionWithTraceFunc'ScopeTests.testInteractionWithTraceFuncH  sn     			5	 	 	clln5VE9g.T)S\\2r   c                    R  pV! ^4      pV P                  \        \        VP                  4        \	        VP                  / 4       V P                  R4       R#   \         d     R# i ; i)c                    a  V 3R  l# )c                     < S ^,           # r  r   ru   s   r   r   <ScopeTests.testEvalExecFreeVars.<locals>.f.<locals>.<lambda>c  s	    1q5r   r   ru   s   fr   rn   *ScopeTests.testEvalExecFreeVars.<locals>.fb  s	      r   z9exec should have failed, because code contained free varsN)r  r  eval__code__r)  r(  r   rn   rk   s   &  r   testEvalExecFreeVarsScopeTests.testEvalExecFreeVars`  s_    	! aD)T1::6	SR  IIQR  		s   A A*)A*c                     \        \        4       \        R 4       R pV! 4         \        \        4       R#   \         d     L)i ; i  \         d     R# i ; i)zbad should not be definedc                  b    R  U Uu. uF  q P                  4        F  qNK  	  K  	   p pR# u upp i )za bN)split)sbads     r   r   +ScopeTests.testListCompLocalVars.<locals>.xx  s#    5%Q779CS9S%55s    +N)r  r  r  rn  s   & r   testListCompLocalVars ScopeTests.testListCompLocalVarso  sX    	/#J -.	6 	
	#J  		  		s    8 A	 AA	AAc                &    R  pV! ^4      ! 4        R# )c                    a  V 3R  lpV# )c                  "   < S  \        R 4       R# )zx + 1N)r  ru   s   r   rk   1ScopeTests.testEvalFreeVars.<locals>.f.<locals>.g  s    Wr   r   rm   s   f r   rn   &ScopeTests.testEvalFreeVars.<locals>.f  s     Hr   Nr   r   s   & r   testEvalFreeVarsScopeTests.testEvalFreeVars  s    	 	
!r   c                     ! R  R4      pR# )c                   &   a  ] tR tRt o R tRtV tR# )+ScopeTests.testFreeingCell.<locals>.Speciali  c                    \        4        R # r   )nestedcell_getr   s   &r   rO  3ScopeTests.testFreeingCell.<locals>.Special.__del__  s     r   r   N)rK   rL   rM   rN   rO  rO   rP   rR   s   @r   Specialr    s     ! !r   r  Nr   )r   r  s   & r   testFreeingCellScopeTests.testFreeingCell  s    	! 	!r   c                    R  pV! ^ 4      w  r#V P                  V! 4       ^4       V P                  V! 4       ^4       V P                  V! 4       ^4       V P                  V! 4       ^ 4       R# )c                 "   a  V 3R  lpV 3R lpW3# )c                     < S ^,          o S # r  r   ru   s   r   r   7ScopeTests.testNonLocalFunction.<locals>.f.<locals>.inc      Qr   c                     < S ^,          o S # r  r   ru   s   r   dec7ScopeTests.testNonLocalFunction.<locals>.f.<locals>.dec  r  r   r   )r   r   r  s   f  r   rn   *ScopeTests.testNonLocalFunction.<locals>.f  s     8Or   Nr   )r   rn   r   r  s   &   r   testNonLocalFunctionScopeTests.testNonLocalFunction  s\    		 Q4""""r   c                   R  pV! ^ 4      pV P                  VP                  4       ^4       V P                  VP                  4       ^4       V P                  VP                  4       ^4       V P                  VP                  4       ^ 4       R# )c                 ,   a   ! V 3R  lR4      pV! 4       # )c                   :   <a  ] tR tRt o V3R ltV3R ltRtV tR# )3ScopeTests.testNonLocalMethod.<locals>.f.<locals>.ci  c                   < S^,          oS# r  r   rn  s   &r   r   7ScopeTests.testNonLocalMethod.<locals>.f.<locals>.c.inc      FAHr   c                   < S^,          oS# r  r   rn  s   &r   r  7ScopeTests.testNonLocalMethod.<locals>.f.<locals>.c.dec  r  r   r   N)rK   rL   rM   rN   r   r  rO   rP   rQ   s   @r   r~   r    s      r   r~   r   r   r~   s   f r   rn   (ScopeTests.testNonLocalMethod.<locals>.f  s      3Jr   N)r   r   r  r   rn   r~   s   &  r   testNonLocalMethodScopeTests.testNonLocalMethod  sj    
	 aD!$!$!$!$r   c                    / p/ p\        R W4       V P                  ^VR,          4       V P                  ^	VR,          4       R# )aC  if 1:
            def f():
                y = 1
                def g():
                    global y
                    return y
                def h():
                    return y + 1
                return g, h
            y = 9
            g, h = f()
            result9 = g()
            result2 = h()
            result2result9N)r)  r   )r   local_ns	global_nss   &  r   #testGlobalInParallelNestedFunctions.ScopeTests.testGlobalInParallelNestedFunctions  sL    
 	  	& 	Ii01Ii01r   c                    R  pV! ^ 4      pV P                  VP                  4       ^4       V P                  RVP                  P                  4       R# )c                 ,   a   ! V 3R  lR4      pV! 4       # )c                   B   <a  ] tR tRt o  Z^,          oV3R ltRtV tR# )2ScopeTests.testNonLocalClass.<locals>.f.<locals>.ci  c                   < S# r   r   rn  s   &r   get6ScopeTests.testNonLocalClass.<locals>.f.<locals>.c.get  rq  r   r   N)rK   rL   rM   rN   r  rO   rP   rQ   s   @r   r~   r    s     Q r   r~   r   r  s   f r   rn   'ScopeTests.testNonLocalClass.<locals>.f  s     
 3Jr   r   N)r   r  ry  	__class____dict__r  s   &  r   testNonLocalClassScopeTests.testNonLocalClass  sB    	 aD!$akk223r   c                b    R  pV! ^ 4      pV P                  \        V! ^4      4      . RO4       R# )c                    a  V 3R  lpV# )c              3   N   <"   \        V 4       F  pS^,          oSx  K  	  R# 5irF  )rU  )r   rV  r   s   & r   rk   6ScopeTests.testNonLocalGenerator.<locals>.f.<locals>.g  s"     qAFAG "s   "%r   rm   s   f r   rn   +ScopeTests.testNonLocalGenerator.<locals>.f  s    
 Hr   N)r  r:  r;     r   )r   rx  r  s   &  r   testNonLocalGenerator ScopeTests.testNonLocalGenerator  s*    	 aDad_5r   c                X    R  pV! ^4      pV! 4       pV P                  V! 4       ^4       R# )c                    a  V 3R  lpV# )c                  &   < S^,          oV3R lp V # )r:  c                     < S ^,          o S # )r  r   ru   s   r   ri   >ScopeTests.testNestedNonLocal.<locals>.f.<locals>.g.<locals>.h  r  r   r   )ri   r   s    r   rk   3ScopeTests.testNestedNonLocal.<locals>.f.<locals>.g  s    Q r   r   rm   s   f r   rn   (ScopeTests.testNestedNonLocal.<locals>.f  s     Hr   Nr   )r   rn   rk   ri   s   &   r   testNestedNonLocalScopeTests.testNestedNonLocal  s+    		 aDCa r   c                    R  pR pR# )c                     R # r   r   r   s   &r   top/ScopeTests.testTopIsNotSignificant.<locals>.top  s    r   c                      R # r   r   r   r   r   r{   -ScopeTests.testTopIsNotSignificant.<locals>.b   s    r   Nr   )r   r  r{   s   &  r   testTopIsNotSignificant"ScopeTests.testTopIsNotSignificant  s    		r   c                   a ^*o ! V3R lR4      pV P                  VP                  ^+4        ! R R4      pV P                  VR4       V P                  S^*4       R# )rf   c                   2   < ] tR tRt^+]! 4       R&    Z tRtR# )8ScopeTests.testClassNamespaceOverridesClosure.<locals>.Xi  r   r   N)rK   rL   rM   rN   ra  r   rO   ru   s   r   Xr    s    FHSMAr   r  c                   ,    ] tR tRt^+]! 4       R&   ARtR# )r  i
  r   r   N)rK   rL   rM   rN   ra  r   rO   r   r   r   r  r  
  s    FHSMr   r   N)r   r   assertNotHasAttr)r   r  r   s   & @r   "testClassNamespaceOverridesClosure-ScopeTests.testClassNamespaceOverridesClosure  sT    	 	 	b!	 	 	a%Br   c                     ! R  R4      pV! 4       pVP                  4        \        P                  ! V4      p?\        4        V P	                  V! 4       4       R# )c                   &   a  ] tR tRt o R tRtV tR# )'ScopeTests.testCellLeak.<locals>.Testeri  c                f   a    ^^ ,           Ro R#   \          d   pTS n         Rp?Ro R# Rp?ii ; i)r   N)	Exceptionexc)r   r#  s   f r   dig+ScopeTests.testCellLeak.<locals>.Tester.dig  s9    #aC  ! #"DHH#s   	 0+0)r#  N)rK   rL   rM   rN   r$  rO   rP   r  s   @r   Testerr     s      r   r&  N)r$  weakrefrefr   assertIsNone)r   r&  testerr(  s   &   r   testCellLeakScopeTests.testCellLeak  sD    	 	 

kk&!#% r   c                `    ! R  R4      pV! 4       pV P                  \        4      ;_uu_ 4        VP                  4        RRR4       VP                  4       pV P                  \        4      ;_uu_ 4        V! ^R7       RRR4       R#   + '       g   i     LQ; i  + '       g   i     R# ; i)c                   ,   a  ] tR tRt o R tR tRtV tR# )8ScopeTests.test_multiple_nesting.<locals>.MultiplyNestedi/  c                H    ^p ! R R4      pV! 4       P                  ^R7      # )r  c                   &   a  ] tR tRt o R tRtV tR# )FScopeTests.test_multiple_nesting.<locals>.MultiplyNested.f1.<locals>.Di2  c                    V# r   r   r   _D__args   &&r   rk   HScopeTests.test_multiple_nesting.<locals>.MultiplyNested.f1.<locals>.D.g3      $r   r   NrK   rL   rM   rN   rk   rO   rP   r  s   @r   Dr2  2       % %r   r9  _MultiplyNested__argrk   r   r<  r9  s   &  r   r   ;ScopeTests.test_multiple_nesting.<locals>.MultiplyNested.f10  s&    % % suu!u44r   c                <    ^p ! R R4      pV! 4       P                   # )r  c                   &   a  ] tR tRt o R tRtV tR# )FScopeTests.test_multiple_nesting.<locals>.MultiplyNested.f2.<locals>.Di9  c                    V# r   r   r4  s   &&r   rk   HScopeTests.test_multiple_nesting.<locals>.MultiplyNested.f2.<locals>.D.g:  r7  r   r   Nr8  r  s   @r   r9  rB  9  r:  r   r9  r=  r>  s   &  r   r   ;ScopeTests.test_multiple_nesting.<locals>.MultiplyNested.f27  s    % % suur   r   N)rK   rL   rM   rN   r   r   rO   rP   r  s   @r   MultiplyNestedr/  /  s     5 r   rF  Nr;  )r  r  r   r   )r   rF  r  closures   &   r   test_multiple_nesting ScopeTests.test_multiple_nesting-  sx    	 	 y))GGI * '')y))+ *)	 *) *))s   B	5
B	B	B-	r   N)0rK   rL   rM   rN   r   r*   r2   rB   rV   ra   rq   r   r   r   r   r   r   r   r  r  r%  r*  r<  r@  rW  rZ  rg  r{  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r+  rH  rO   rP   r  s   @r   r   r      s
    ((('$((+"(#6J	$2224$  D"03"3*&9 Rh'.26 %B     + 3 3.S$!#&%$2046!"  ! !8, ,r   r   __main__)
unittestr'  test.supportr   r   r   TestCaser   rK   mainr   r   r   <module>rO     s>      9 #|,"" |,| zMMO r   