Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_scope.cpython-311.opt-1.pyc
�

�Ke�T���ddlZddlZddlmZmZddlmZGd�dej��Zedkrej	��dSdS)�N)�check_syntax_error�cpython_only)�
gc_collectc�.�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed���Zd�Zed���Zd�Zd�Z d�Z!d�Z"d �Z#d!�Z$d"�Z%d#�Z&d$�Z'd%�Z(d&�Z)d'�Z*ed(���Z+d)S)*�
ScopeTestsc��d�}|d��}|d��}|�|d��d��|�|d��d��dS)Nc����fd�}|S)Nc����|zS�N���y�xs ��9/usr/local/apps/python3/lib/python3.11/test/test_scope.py�adderz?ScopeTests.testSimpleNesting.<locals>.make_adder.<locals>.adder
�����1�u��r�rrs` r�
make_adderz0ScopeTests.testSimpleNesting.<locals>.make_adders!���
�
�
�
�
��Lr��
�������assertEqual)�selfr�inc�plus10s    r�testSimpleNestingzScopeTests.testSimpleNesting
so��	�	�	�
�j��m�m����B���������Q����#�#�#���������Q�'�'�'�'�'rc��d�}|d��}|d��}|�|d��d��|�|d��d��dS)Nc�"���fd�}|��S)Nc����fd�}|S)Nc����|zSrrr
s �rrzNScopeTests.testExtraNesting.<locals>.make_adder2.<locals>.extra.<locals>.adder�����q�5�Lrr)rrs �r�extraz?ScopeTests.testExtraNesting.<locals>.make_adder2.<locals>.extras!���!�!�!�!�!��rr)rr&s` r�make_adder2z0ScopeTests.testExtraNesting.<locals>.make_adder2s)���
�
�
�
�
��5�7�7�Nrrrrrrr)rr'rrs    r�testExtraNestingzScopeTests.testExtraNestingso��	�	�	��k�!�n�n����R���������Q����#�#�#���������Q�'�'�'�'�'rc��d�}|d��}|d��}|�|d��d��|�|d��d��dS)Nc����fd�}�dz�|S)Nc����|zSrrr
s �rrzEScopeTests.testSimpleAndRebinding.<locals>.make_adder3.<locals>.adder)rrrrrs` r�make_adder3z6ScopeTests.testSimpleAndRebinding.<locals>.make_adder3(s*���
�
�
�
�
��A��A��Lrr�	rrrrr)rr,rrs    r�testSimpleAndRebindingz!ScopeTests.testSimpleAndRebinding&so��	�	�	��k�!�n�n����Q���������Q����#�#�#���������Q�'�'�'�'�'rc����fd�}d�|��}|�|d��d��d�|�|d��d��dS)Nc�"���fd�}|��S)Nc�"���fd�}|��S)Nc����fd�}|S)Nc����|zSrr�r�global_xs �rrzbScopeTests.testNestingGlobalNoFree.<locals>.make_adder4.<locals>.nest.<locals>.nest.<locals>.adder9s
���'�!�|�+rr)rr5s �r�nestzSScopeTests.testNestingGlobalNoFree.<locals>.make_adder4.<locals>.nest.<locals>.nest8s!���,�,�,�,�,� �Lrr�r6r5s �rr6zEScopeTests.testNestingGlobalNoFree.<locals>.make_adder4.<locals>.nest7s)���!�!�!�!�!��t�v�v�
rrr7s �r�make_adder4z7ScopeTests.testNestingGlobalNoFree.<locals>.make_adder46s)���
�
�
�
�
��4�6�6�Mrrrrrrr)rr8rr5s   @r�testNestingGlobalNoFreez"ScopeTests.testNestingGlobalNoFree4su���	�	�	�	�	�����
�
�������q���1�%�%�%��������r���A�&�&�&�&�&rc��d�}|d��}|d��}|�|d��d��|�|d��d��dS)Nc�6��G�fd�d��}|��S)Nc���eZdZ�fd�ZdS)�FScopeTests.testNestingThroughClass.<locals>.make_adder5.<locals>.Adderc����|zSrr)rrrs  �r�__call__zOScopeTests.testNestingThroughClass.<locals>.make_adder5.<locals>.Adder.__call__Jr%rN)�__name__�
__module__�__qualname__r?�rs�r�Adderr=Is.�������!�!�!�!�!�!�!rrDr)rrDs` r�make_adder5z7ScopeTests.testNestingThroughClass.<locals>.make_adder5HsB���
!�
!�
!�
!�
!�
!�
!�
!�
!�
!��5�7�7�Nrrrrrrr)rrErrs    r�testNestingThroughClassz"ScopeTests.testNestingThroughClassFso��	�	�	��k�!�n�n����R���������Q����#�#�#���������Q�'�'�'�'�'rc��d�}|d��}|d��}|�|d��d��|�|d��d��dS)Nc��d�}|a|S)Nc��t|zSr��
global_nest_x�rs rrzMScopeTests.testNestingPlusFreeRefToGlobal.<locals>.make_adder6.<locals>.adderXs
��$�q�(�(rrJrs  r�make_adder6z>ScopeTests.testNestingPlusFreeRefToGlobal.<locals>.make_adder6Vs��
)�
)�
)��M��Lrrr�rrr)rrMrrs    r�testNestingPlusFreeRefToGlobalz)ScopeTests.testNestingPlusFreeRefToGlobalTso��	�	�	��k�!�n�n����R���������Q����$�$�$���������Q�'�'�'�'�'rc�`�d�}|d��}|�|d��d��dS)Nc��d�}|d��S)Nc���d��fd�}|S)N�*c����|zSrr)�zrs �r�hzEScopeTests.testNearestEnclosingScope.<locals>.f.<locals>.g.<locals>.hhr%rr)rrVrs  @r�gz:ScopeTests.testNearestEnclosingScope.<locals>.f.<locals>.gfs&�����!�!�!�!�!��rrr�rrWs  r�fz/ScopeTests.testNearestEnclosingScope.<locals>.fes ��
�
�
�
�1�Q�4�4�Krr��/r)rrY�	test_funcs   r�testNearestEnclosingScopez$ScopeTests.testNearestEnclosingScopecsD��	�	�	��A�b�E�E�	������1���r�*�*�*�*�*rc���d���fd�}|ddd��}|ddd��}|�|��d��dS)	Nc��|SrrrCs r�identityz9ScopeTests.testMixedFreevarsAndCellvars.<locals>.identityrs���Hrc��������fd�}|S)Nc�0����|�z}����fd�}|�z�|S)Nc�&������zz��Srr)�br`rrUs����rrVzHScopeTests.testMixedFreevarsAndCellvars.<locals>.f.<locals>.g.<locals>.hxs���$�8�A��Q��K�0�0�0rr)�ard�crVrr`rrUs `  @���rrWz=ScopeTests.testMixedFreevarsAndCellvars.<locals>.f.<locals>.gvsF�������E��1�1�1�1�1�1�1�1���E���rr)rrrUrWr`s` ` �rrYz2ScopeTests.testMixedFreevarsAndCellvars.<locals>.fus/�����
�
�
�
�
�
�
��Hrrr����'r)rrYrWrVr`s    @r�testMixedFreevarsAndCellvarsz'ScopeTests.testMixedFreevarsAndCellvarspsq���	�	�	�		�		�		�		�		�
�A�a��A�J�J��
�A�a��A�J�J���������b�!�!�!�!�!rc�8��d�}|��}|�|���d��|�|���d��|�|���d��d�G�fd�d��}|��}|�|���d��|�|���d��|�|���d��dS)Nc�:��d�G�fd�d��}|��S)N�varc�,��eZdZd�Z�fd�Zd�Zd�ZdS)�:ScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Testc��dS�N�methodr�rs r�method_and_varzIScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Test.method_and_var�s��#�8rc����Srr�rrus �r�testz?ScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Test.test�s	���)�)rc� �td��S�N�global��strrts r�
actual_globalzHScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Test.actual_global�s���x�=�=�(rc� �t|��Srr|rts rr}z>ScopeTests.testFreeVarInMethod.<locals>.test.<locals>.Test.str�s���t�9�9�$rN�r@rArBrurxr~r}�rus�r�Testrp�s[�������$�$�$�*�*�*�*�*�)�)�)�%�%�%�%�%rr�r)r�rus @rrxz,ScopeTests.testFreeVarInMethod.<locals>.test�sG���"�N�
%�
%�
%�
%�
%�
%�
%�
%�
%�
%��4�6�6�Mrrnrsr{c�,��eZdZd�Z�fd�Zd�Zd�ZdS)�,ScopeTests.testFreeVarInMethod.<locals>.Testc��dSrrrrts rruz;ScopeTests.testFreeVarInMethod.<locals>.Test.method_and_var�s���xrc����Srrrws �rrxz1ScopeTests.testFreeVarInMethod.<locals>.Test.test�s	���%�%rc� �td��Srzr|rts rr~z:ScopeTests.testFreeVarInMethod.<locals>.Test.actual_global�s���8�}�}�$rc� �t|��Srr|rts rr}z0ScopeTests.testFreeVarInMethod.<locals>.Test.str�s���4�y�y� rNr�r�s�rr�r��s[�������
 �
 �
 �
&�
&�
&�
&�
&�
%�
%�
%�
!�
!�
!�
!�
!rr�)rrxrur~)rrx�tr�rus    @r�testFreeVarInMethodzScopeTests.testFreeVarInMethod�s)���	�	�	�
�D�F�F����������5�)�)�)�����)�)�+�+�X�6�6�6�������*�*�H�5�5�5���		!�		!�		!�		!�		!�		!�		!�		!�		!�		!�
�D�F�F����������5�)�)�)�����)�)�+�+�X�6�6�6�������*�*�H�5�5�5�5�5rc��dd�d�}|�|d���d��|�|��d��dS)N��rec�(���fd�}|��dzS)Nc����dzS)NrZrr�s�r�barz8ScopeTests.testCellIsKwonlyArg.<locals>.foo.<locals>.bar�rrrgr)rer�s` r�fooz+ScopeTests.testCellIsKwonlyArg.<locals>.foo�s,���
�
�
�
�
��3�5�5�1�9�rrS�2�r)rr�s  r�testCellIsKwonlyArgzScopeTests.testCellIsKwonlyArg�sd���	�	�	�	�	�
	
�����r����B�'�'�'���������#�#�#�#�#rc��d�}|��}d�}||��}|j\}|��}|�||��|�||��dS)Nc�(��d��fd�}|j\}|S)NrSc����Srr��values�r�innerzCScopeTests.testCellIsArgAndEscapes.<locals>.external.<locals>.inner������r��__closure__�r��cellr�s  @r�externalz4ScopeTests.testCellIsArgAndEscapes.<locals>.external��0����E�
�
�
�
�
��%�E�D��Krc����fd�}|S)Nc����Srr)�args�r�eggsz>ScopeTests.testCellIsArgAndEscapes.<locals>.spam.<locals>.eggs������
rr)r�r�s` r�spamz0ScopeTests.testCellIsArgAndEscapes.<locals>.spam�s!���
�
�
�
�
��Kr�r��assertIs�assertIsNot�rr��cell_extr�r��cell_closure�	cell_eggss       r�testCellIsArgAndEscapesz"ScopeTests.testCellIsArgAndEscapes�s���
	�	�	��8�:�:��	�	�	�
�t�H�~�~���(�
���D�F�F�	��
�
�i��*�*�*�����L�1�1�1�1�1rc��d�}|��}d�}||��}|j\}|��}|�||��|�||��dS)Nc�(��d��fd�}|j\}|S)NrSc����Srrr�s�rr�zEScopeTests.testCellIsLocalAndEscapes.<locals>.external.<locals>.inner�r�rr�r�s  @rr�z6ScopeTests.testCellIsLocalAndEscapes.<locals>.external�r�rc���|��fd�}|S)Nc����Srr)r�s�rr�z@ScopeTests.testCellIsLocalAndEscapes.<locals>.spam.<locals>.eggs�s����rr)r�r�r�s  @rr�z2ScopeTests.testCellIsLocalAndEscapes.<locals>.spam�s&����D�
�
�
�
�
��Krr�r�s       r�testCellIsLocalAndEscapesz$ScopeTests.testCellIsLocalAndEscapes�s���
	�	�	��8�:�:��	�	�	��t�H�~�~���(�
���D�F�F�	��
�
�i��*�*�*�����L�1�1�1�1�1rc�J�d�}|�|d��d��dS)Nc�N���fd��|dkr�|��Std���)Nc�6��|dkrdS|�|dz
��zS)Nrrr)�n�facts �rr�z1ScopeTests.testRecursion.<locals>.f.<locals>.fact�s'�����6�6��1��t�t�A��E�{�{�?�*rrzx must be >= 0)�
ValueError)rr�s @rrYz#ScopeTests.testRecursion.<locals>.f�sC���
+�
+�
+�
+�
+�
�A�v�v��t�A�w�w�� �!1�2�2�2rrii�r�rrYs  r�
testRecursionzScopeTests.testRecursion�s7��		3�		3�		3�	
�����1���s�#�#�#�#�#rc��t|d��t|d��t|d��t|d��dS)Nz�if 1:
            def unoptimized_clash1(strip):
                def f(s):
                    from sys import *
                    return getrefcount(s) # ambiguity: free or local
                return f
            z�if 1:
            def unoptimized_clash2():
                from sys import *
                def f(s):
                    return getrefcount(s) # ambiguity: global or local
                return f
            z�if 1:
            def unoptimized_clash2():
                from sys import *
                def g():
                    def f(s):
                        return getrefcount(s) # ambiguity: global or local
                    return f
            z�if 1:
            def f():
                def g():
                    from sys import *
                    return getrefcount # global or local?
            )rrts r�testUnoptimizedNamespacesz$ScopeTests.testUnoptimizedNamespaces�sv���4�"�	�	�	�	�4�"�	�	�	�	�4�"�	�	�	�	�4�"�	�	�	�	�	rc�<�	�d�}|d��}|d��}|�|d��d��|�|d��d��d�}|d��}|d��}|�|d��d��|�|d��d���	fd�}d�	|d��}|�|d��d	��d
�}|ddd	��}|ddd��}|�|��d
��dS)Nc����fd�S)Nc����|zSrrr
s �r�<lambda>z:ScopeTests.testLambdas.<locals>.<lambda>.<locals>.<lambda>s����Q��rrrCs`rr�z(ScopeTests.testLambdas.<locals>.<lambda>s
�������rrrrrZ�c����fd���S)Nc����fd�S)Nc����|zSrrr
s �rr�zLScopeTests.testLambdas.<locals>.<lambda>.<locals>.<lambda>.<locals>.<lambda>!s���1�q�5�rrrCs�rr�z:ScopeTests.testLambdas.<locals>.<lambda>.<locals>.<lambda>!s
�������rrrCs`rr�z(ScopeTests.testLambdas.<locals>.<lambda>!s���0�0�0�0�0�3�3�rc����fd�S)Nc����|zSrrr4s �rr�z:ScopeTests.testLambdas.<locals>.<lambda>.<locals>.<lambda>'s����A��rr)rr5s �rr�z(ScopeTests.testLambdas.<locals>.<lambda>'s���-�-�-�-�rrgc������fd�S)Nc�������fd�S)Nc������zzSrr)rdrrUs���rr�zLScopeTests.testLambdas.<locals>.<lambda>.<locals>.<lambda>.<locals>.<lambda>,s���a�1�q�5�k�rr)rerdrfrrUs ` ��rr�z:ScopeTests.testLambdas.<locals>.<lambda>.<locals>.<lambda>,s����-A�-A�-A�-A�-A�-A�rr)rrrUs ``rr�z(ScopeTests.testLambdas.<locals>.<lambda>,s����A�A�A�A�A�rrhri�r)
r�f1rr�f2�f3�f8rWrVr5s
         @r�testLambdaszScopeTests.testLambdassI���
&�
&���b��e�e����B���������Q����#�#�#���������B�'�'�'�
3�
3���b��e�e����B���������Q����#�#�#���������B�'�'�'�
-�
-�
-�
-�����b��h�h�������Q����#�#�#�
A�
A���B�q�!�Q�K�K��
�A�a��A�J�J���������b�!�!�!�!�!rc�~�d�}d�}|�t|��|�t|��dS)Nc�4��t����fd�}d�dS)Nc����SrrrLs�rr�z@ScopeTests.testUnboundLocal.<locals>.errorInOuter.<locals>.inner5�����rr��print�r�rs @r�errorInOuterz1ScopeTests.testUnboundLocal.<locals>.errorInOuter3s0����!�H�H�H�
�
�
�
�
��A�A�Arc�*���fd�}|��d�dS)Nc����SrrrLs�rr�z@ScopeTests.testUnboundLocal.<locals>.errorInInner.<locals>.inner:r�rrrr�s @r�errorInInnerz1ScopeTests.testUnboundLocal.<locals>.errorInInner9s0���
�
�
�
�
��E�G�G�G��A�A�Ar��assertRaises�UnboundLocalError�	NameError�rr�r�s   r�testUnboundLocalzScopeTests.testUnboundLocal1sU��	�	�	�	�	�	�	
���+�\�:�:�:����)�\�2�2�2�2�2rc�~�d�}d�}|�t|��|�t|��dS)Nc�6��d��t����fd�}dS)Nrc����SrrrLs�rr�zIScopeTests.testUnboundLocal_AfterDel.<locals>.errorInOuter.<locals>.innerJr�rr�r�s @rr�z:ScopeTests.testUnboundLocal_AfterDel.<locals>.errorInOuterFs9����A���!�H�H�H�
�
�
�
�
�
�
rc�,���fd�}d��|��dS)Nc����SrrrLs�rr�zIScopeTests.testUnboundLocal_AfterDel.<locals>.errorInInner.<locals>.innerNr�rrrr�s @rr�z:ScopeTests.testUnboundLocal_AfterDel.<locals>.errorInInnerMs3���
�
�
�
�
��A���E�G�G�G�G�Grr�r�s   r�testUnboundLocal_AfterDelz$ScopeTests.testUnboundLocal_AfterDelBsU��	�	�	�	�	�	�	
���+�\�:�:�:����)�\�2�2�2�2�2rc�4�tdd|ji��dS)Naif 1:
            global_x = 1
            def f():
                global_x += 1
            try:
                f()
            except UnboundLocalError:
                pass
            else:
                fail('scope of global_x not correctly determined')
            �fail)�execr�rts r�testUnboundLocal_AugAssignz%ScopeTests.testUnboundLocal_AugAssignWs/���
��$�)�$�
	&�
	&�
	&�
	&�
	&rc��d�}|�|ddd����d��d�}|�|d�����d	d��dS)
Nc����fd�}|S)Nc����Srr)�lsts�r�returnerzIScopeTests.testComplexDefinitions.<locals>.makeReturner.<locals>.returnerhr�rr)r�r�s` r�makeReturnerz7ScopeTests.testComplexDefinitions.<locals>.makeReturnergs!���
�
�
�
�
��Orrrrg)rrrgc����fd�}|S)Nc����Srr)�kwargss�rr�zJScopeTests.testComplexDefinitions.<locals>.makeReturner2.<locals>.returneros����
rr)r�r�s` r�
makeReturner2z8ScopeTests.testComplexDefinitions.<locals>.makeReturner2ns!���
�
�
�
�
��OrrNr�rer)rr�r�s   r�testComplexDefinitionsz!ScopeTests.testComplexDefinitionses���	�	�	�
	
���,���a��!�,�,�.�.��8�8�8�	�	�	�
	
���,����,�,�,�.�.�s�3�R�8�8�8�8�8rc�$�td��dS)Na;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)
            �r�rts r�testScopeOfGlobalStmtz ScopeTests.testScopeOfGlobalStmtus+��	
�O�O	�O	�O	�O	�O	rc���G�fd�d����fd�}td��D]}|���
t��|��jd��dS)Nc�(��eZdZdZ�fd�Z�fd�ZdS)�!ScopeTests.testLeaks.<locals>.Foorc�(���xjdz
c_dS�Nr��count�r�Foos �r�__init__z*ScopeTests.testLeaks.<locals>.Foo.__init__������	�	�Q��	�	�	�	rc�(���xjdzc_dSrrrs �r�__del__z)ScopeTests.testLeaks.<locals>.Foo.__del__�rrN)r@rArBrrr)rs�rrr��sL��������E�
�
�
�
�
�
�
�
�
�
�
�
rrc�<��������fd�}|��dS)Nc����SrrrCs�rr�z,ScopeTests.testLeaks.<locals>.f1.<locals>.f2�r�rr)r�rrs @�rr�z ScopeTests.testLeaks.<locals>.f1�s7��������A�
�
�
�
�
��B�D�D�D�D�Dr�dr)�rangerrr)rr��irs   @r�	testLeakszScopeTests.testLeaks�s����	�	�	�	�	�	�	�	�	�	�	�	�	�	�	��s���	�	�A��B�D�D�D�D����������A�&�&�&�&�&rc�$�td��dS)Na�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)
            r�rts r�testClassAndGlobalzScopeTests.testClassAndGlobal�s#����	�	�	�	�	rc��d�}|d��d��}|�d|��|d=|�|dddd���dS)Nc����fd�}|S)Nc�@����fd�}��z}�dz
�t��S)Nc����|zSrr)rUrs �rrVz>ScopeTests.testLocalsFunction.<locals>.f.<locals>.g.<locals>.h�r%rrg)�locals)rrV�wrs`  �rrWz3ScopeTests.testLocalsFunction.<locals>.f.<locals>.g�s8����!�!�!�!�!���E���Q����x�x�rrrXs` rrYz(ScopeTests.testLocalsFunction.<locals>.f�s#���
 �
 �
 �
 �
 ��HrrrhrV�ri)rrr)�assertInr)rrY�ds   r�testLocalsFunctionzScopeTests.testLocalsFunction�si��	�	�	�
�A�A�a�D�D��G�G���
�
�c�1����
�c�F�����!�!�!�4�4�5�5�5�5�5rc���d�}|�|d��jd��d�}|d��j}|�d|��|�d|��dS)Nc�&��G�fd�d��}|S)Nc�2��eZdZdZ�fd�Ze��dS)�0ScopeTests.testLocalsClass.<locals>.f.<locals>.C�c����Srr�rrs �r�mz2ScopeTests.testLocalsClass.<locals>.f.<locals>.C.m�����HrN)r@rArBrr"rrCs�r�Crs8��������������������rr$r�rr$s` rrYz%ScopeTests.testLocalsClass.<locals>.fs<���
�
�
�
�
�
�
�
�
�
�
�Hrrrc�&��G�fd�d��}|S)Nc�D��eZdZ�Z�fd�Zee����ZdS)rc����Srrr!s �rr"z2ScopeTests.testLocalsClass.<locals>.f.<locals>.C.m!r#rN)r@rArBrr"�listrrUrCs�rr$z0ScopeTests.testLocalsClass.<locals>.f.<locals>.Cs@���������������D�����N�N���rr$rr%s` rrYz%ScopeTests.testLocalsClass.<locals>.fs<���
#�
#�
#�
#�
#�
#�
#�
#�
#�
#�
�Hrrr)rrrU�assertNotInr)rrY�varnamess   r�testLocalsClasszScopeTests.testLocalsClass	s���	�	�	�	
�����1�����$�$�$�	�	�	��1�Q�4�4�6������h�'�'�'��
�
�c�8�$�$�$�$�$rc����ddl}|�|j|�����|�d���d�G�fd�d��}|��d��dS)Nrc��dSrr)rerdrfs   rr�z6ScopeTests.testLocalsClass_WithTrace.<locals>.<lambda>2s��$�rrc���eZdZ�fd�ZdS)�/ScopeTests.testLocalsClass_WithTrace.<locals>.Cc����Srrr!s �rrYz1ScopeTests.testLocalsClass_WithTrace.<locals>.C.f6r�rN)r@rArBrYrCs�rr$r05s.�������
�
�
�
�
�
�
rr$)�sys�
addCleanup�settrace�gettracer)rr2r$rs   @r�testLocalsClass_WithTracez$ScopeTests.testLocalsClass_WithTrace*s����	�
�
�
������c�l�l�n�n�5�5�5����&�&�'�'�'���	�	�	�	�	�	�	�	�	�	�	
����B�����rc��d�}|d����}|�|j|�����dS)Nc�&��G�fd�d��}|S)Nc���eZdZ�fd�Z�ZdS)�1ScopeTests.testBoundAndFree.<locals>.f.<locals>.Cc����Srrr!s �rr"z3ScopeTests.testBoundAndFree.<locals>.f.<locals>.C.m@r#rN)r@rArBr"rerCs�rr$r:?s-���������������rr$rr%s` rrYz&ScopeTests.testBoundAndFree.<locals>.f>s<���
�
�
�
�
�
�
�
�
�
��Hrrg)rrer")rrY�insts   r�testBoundAndFreezScopeTests.testBoundAndFree;sL��	�	�	��q�q��t�t�v�v������������*�*�*�*�*rc�B��ddl}�fd��d�}Gd�d��}|�|j|�����|����|d|d��|�d��|�t
|j��dS)Nrc����Srr)rerdrf�tracers   �rr@z7ScopeTests.testInteractionWithTraceFunc.<locals>.tracerLs����Mrc�N��|\}�|dkr�dkr
d|j�d|����fd�SdS)Nr��_�__c�$��t|���Sr)�getattr)�obj�dess �rr�zNScopeTests.testInteractionWithTraceFunc.<locals>.adaptgetter.<locals>.<lambda>Ts���7�3��#4�#4�r)r@)�name�klass�getter�kindrHs    @r�adaptgetterz<ScopeTests.testInteractionWithTraceFunc.<locals>.adaptgetterOsH����I�D�#��q�y�y��"�9�9�9�',�~�~�~�t�t�<�C�4�4�4�4�4��yrc��eZdZdS)�:ScopeTests.testInteractionWithTraceFunc.<locals>.TestClassN)r@rArBrrr�	TestClassrOVs�������DrrPr�)rrB)r2r3r4r5r��	TypeError)rr2rMrPr@s    @r�testInteractionWithTraceFuncz'ScopeTests.testInteractionWithTraceFuncHs����	�
�
�
�	�	�	�	�	�	5�	5�	5�	�	�	�	�	�	�	�	�	
�����c�l�l�n�n�5�5�5����V������E�9�g�.�.�.����T�������)�S�\�2�2�2�2�2rc���d�}|d��}|�tt|j��	t	|ji��|�d��dS#t$rYdSwxYw)Nc����fd�S)Nc����dzSrrrCs�rr�z<ScopeTests.testEvalExecFreeVars.<locals>.f.<locals>.<lambda>cs���1�q�5�rrrCs`rrYz*ScopeTests.testEvalExecFreeVars.<locals>.fbs��� �=�=�=� rrgz9exec should have failed, because code contained free vars)r�rQ�eval�__code__r�r��rrYrWs   r�testEvalExecFreeVarszScopeTests.testEvalExecFreeVars`s���	!�	!�	!�
�A�a�D�D�����)�T�1�:�6�6�6�	S����R� � � �
�I�I�Q�R�R�R�R�R���	�	�	��D�D�	���s�A"�"
A0�/A0c���	tt��td��n#t$rYnwxYwd�}|��	tt��dS#t$rYdSwxYw)Nzbad should not be definedc��d�dD��dS)Nc�@�g|]}|���D]}|���Sr)�split)�.0�s�bads   r�
<listcomp>z?ScopeTests.testListCompLocalVars.<locals>.x.<locals>.<listcomp>ys-��5�5�5�Q�1�7�7�9�9�5�5�C�S�5�5�5�5rza brrrrrz+ScopeTests.testListCompLocalVars.<locals>.xxs��5�5�%�5�5�5�5�5�5r)r�r`r�r!s  r�testListCompLocalVarsz ScopeTests.testListCompLocalVarsos���	/��#�J�J�J�
�-�.�.�.�.���	�	�	��D�	����
	6�	6�	6�	
�����	��#�J�J�J�J�J���	�	�	��D�D�	���s�&�
3�3�A�
A(�'A(c�2�d�}|d����dS)Nc����fd�}|S)Nc�*���td��dS)Nzx + 1)rVrCs�rrWz1ScopeTests.testEvalFreeVars.<locals>.f.<locals>.g�s������W�
�
�
�
�
rrrXs` rrYz&ScopeTests.testEvalFreeVars.<locals>.f�s#���
�
�
�
�
��Hrrhrr�s  r�testEvalFreeVarszScopeTests.testEvalFreeVars�s*��	�	�	�	
���!�������rc� �Gd�d��}dS)Nc��eZdZd�ZdS)�+ScopeTests.testFreeingCell.<locals>.Specialc�"�t��dSr)�nestedcell_getrts rrz3ScopeTests.testFreeingCell.<locals>.Special.__del__�s��� � � � � rN)r@rArBrrrr�Specialri�s#������
!�
!�
!�
!�
!rrlr)rrls  r�testFreeingCellzScopeTests.testFreeingCell�s4��	!�	!�	!�	!�	!�	!�	!�	!�	!�	!rc��d�}|d��\}}|�|��d��|�|��d��|�|��d��|�|��d��dS)Nc� ���fd�}�fd�}||fS)Nc����dz
��SrrrCs�rrz7ScopeTests.testNonLocalFunction.<locals>.f.<locals>.inc������Q����rc����dz��SrrrCs�r�decz7ScopeTests.testNonLocalFunction.<locals>.f.<locals>.dec�rqrr)rrrss`  rrYz*ScopeTests.testNonLocalFunction.<locals>.f�s@���
�
�
�
�
�
�
�
�
�
���8�Orrrrr)rrYrrss    r�testNonLocalFunctionzScopeTests.testNonLocalFunction�s���		�		�		��1�Q�4�4���S���������"�"�"���������"�"�"���������"�"�"���������"�"�"�"�"rc�b�d�}|d��}|�|���d��|�|���d��|�|���d��|�|���d��dS)Nc�6��G�fd�d��}|��S)Nc�$��eZdZ�fd�Z�fd�ZdS)�3ScopeTests.testNonLocalMethod.<locals>.f.<locals>.cc����dz
��Srrr!s �rrz7ScopeTests.testNonLocalMethod.<locals>.f.<locals>.c.inc�������F�A��Hrc����dz��Srrr!s �rrsz7ScopeTests.testNonLocalMethod.<locals>.f.<locals>.c.dec�rzrN)r@rArBrrsrCs�rrfrx�sG������������������rrfr�rrfs` rrYz(ScopeTests.testNonLocalMethod.<locals>.f�sB���
�
�
�
�
�
�
�
�
�
��1�3�3�Jrrrr)rrrs�rrYrfs   r�testNonLocalMethodzScopeTests.testNonLocalMethod�s���
	�
	�
	�
�A�a�D�D����������!�$�$�$���������!�$�$�$���������!�$�$�$���������!�$�$�$�$�$rc��i}i}td||��|�d|d��|�d|d��dS)NaCif 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()
            r�result2r-�result9)r�r)r�local_ns�	global_nss   r�#testGlobalInParallelNestedFunctionsz.ScopeTests.testGlobalInParallelNestedFunctions�sj��
���	��
��9�
	&�
	&�
	&�	
����I�i�0�1�1�1�����I�i�0�1�1�1�1�1rc��d�}|d��}|�|���d��|�d|jj��dS)Nc�6��G�fd�d��}|��S)Nc�$��eZdZ�dz
��fd�ZdS)�2ScopeTests.testNonLocalClass.<locals>.f.<locals>.crc����Srrr!s �r�getz6ScopeTests.testNonLocalClass.<locals>.f.<locals>.c.get�r#rN)r@rArBr�rCs�rrfr��s7��������Q���������rrfrr|s` rrYz'ScopeTests.testNonLocalClass.<locals>.f�sB���
�
�
�
�
�
�
�
�
�
�
�1�3�3�Jrrrr)rr�r*�	__class__�__dict__r}s   r�testNonLocalClasszScopeTests.testNonLocalClass�s_��	�	�	�
�A�a�D�D����������!�$�$�$�����a�k�2�3�3�3�3�3rc�~�d�}|d��}|�t|d����gd���dS)Nc����fd�}|S)Nc3�B�K�t|��D]}�dz
��V��dSr)r)rr
rs  �rrWz6ScopeTests.testNonLocalGenerator.<locals>.f.<locals>.g�s:������q�����A���F�A��G�G�G�G��rrrXs` rrYz+ScopeTests.testNonLocalGenerator.<locals>.f�s#���
�
�
�
�
�
�HrrrZ)rrrgrhrZ)rr)rXs   r�testNonLocalGeneratorz ScopeTests.testNonLocalGenerator�sN��	�	�	�
�A�a�D�D������a�a��d�d���_�_�_�5�5�5�5�5rc�r�d�}|d��}|��}|�|��d��dS)Nc����fd�}|S)Nc����dz��fd�}|S)Nrc����dz
��S)NrhrrCs�rrVz>ScopeTests.testNestedNonLocal.<locals>.f.<locals>.g.<locals>.h�rzrr)rVrs �rrWz3ScopeTests.testNestedNonLocal.<locals>.f.<locals>.g�s,����Q���������rrrXs` rrYz(ScopeTests.testNestedNonLocal.<locals>.f�s#���
�
�
�
�
��Hrrrgr)rrYrWrVs    r�testNestedNonLocalzScopeTests.testNestedNonLocal�sM��		�		�		�
�A�a�D�D��
�A�C�C���������a� � � � � rc��d�}d�}dS)Nc��dSrrr�s r�topz/ScopeTests.testTopIsNotSignificant.<locals>.top�s���Drc��dSrrrrrrdz-ScopeTests.testTopIsNotSignificant.<locals>.bs���rr)rr�rds   r�testTopIsNotSignificantz"ScopeTests.testTopIsNotSignificant�s*��	�	�	�	�	�	�	�	rc����d�G�fd�d��}|�|jd��Gd�d��}|�t|d����|��d��dS)NrSc�.��eZdZde��d<�ZdS��8ScopeTests.testClassNamespaceOverridesClosure.<locals>.X�+rN)r@rArBrrrCs�r�Xr�s#��������F�F�H�H�S�M��A�A�Arr�r�c�*�eZdZde��d<[dSr�)r@rArBrrrrrr�z8ScopeTests.testClassNamespaceOverridesClosure.<locals>.X
s �������F�F�H�H�S�M���rr)rr�assertFalse�hasattr)rr�rs  @r�"testClassNamespaceOverridesClosurez-ScopeTests.testClassNamespaceOverridesClosures������	�	�	�	�	�	�	�	�	�	�	
�����b�!�!�!�	�	�	�	�	�	�	�	�	
�����C���)�)�)�����B�����rc���Gd�d��}|��}|���tj|��}~t��|�|����dS)Nc��eZdZd�ZdS)�'ScopeTests.testCellLeak.<locals>.Testerc�X��		ddzn#t$r}|�_Yd}~nd}~wwxYwd�dS)Nrc����Srrrts�rr�z=ScopeTests.testCellLeak.<locals>.Tester.dig.<locals>.<lambda> s���D�rr)�	Exception�exc)rr�s` r�digz+ScopeTests.testCellLeak.<locals>.Tester.digsQ���!�#��a�C�C�C�� �#�#�#�"�D�H�H�H�H�H�H�����#�������s�
�
%� �%N)r@rArBr�rrr�Testerr�s#������
�
�
�
�
rr�)r��weakref�refr�assertIsNone)rr��testerr�s    r�testCellLeakzScopeTests.testCellLeaks��	�	�	�	�	�	�	�	�������
�
�����k�&�!�!����������#�#�%�%� � � � � rN),r@rArBr r(r.r9rFrOr]rkr�r�r�r�r�r�r�r�r�r�r�r�rrrr,rr6r=rRrYrbrfrmrtr~r�r�r�r�r�r�r�rrrrrs�������(�(�(�
(�
(�
(�(�(�(�'�'�'�$(�(�(�
(�
(�
(�+�+�+�"�"�"�(#6�#6�#6�J	$�	$�	$�2�2�2�22�2�2�4
$�
$�
$�  � � �D"�"�"�03�3�3�"3�3�3�*&�&�&�9�9�9� R�R�R�h'�'�'�.���26�6�6� %�%�%�B� � ��\� � +�+�+��3�3��\�3�.
S�
S�
S����$���!�!�!�#�#�#�&%�%�%�$2�2�2�04�4�4�6�6�6�!�!�!�"��� � � ��!�!��\�!�!�!rr�__main__)
�unittestr��test.supportrrr�TestCaserr@�mainrrr�<module>r�s�����������9�9�9�9�9�9�9�9�#�#�#�#�#�#�c!�c!�c!�c!�c!��"�c!�c!�c!�L�z����H�M�O�O�O�O�O��r