
    0hh ^                         S SK r S SKrS SKrS SKrS SKrS SKJr  Sr " S S\R                  5      r	S\0r
S r\S:X  a  \R                  " 5         gg)	    N)
BrokenItera  
########### Tests borrowed from or inspired by test_genexps.py ############

Test simple loop with conditional

    >>> sum([i*i for i in range(100) if i&1 == 1])
    166650

Test simple nesting

    >>> [(i,j) for i in range(3) for j in range(4)]
    [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3)]

Test nesting with the inner expression dependent on the outer

    >>> [(i,j) for i in range(4) for j in range(i)]
    [(1, 0), (2, 0), (2, 1), (3, 0), (3, 1), (3, 2)]

Test the idiom for temporary variable assignment in comprehensions.

    >>> [j*j for i in range(4) for j in [i+1]]
    [1, 4, 9, 16]
    >>> [j*k for i in range(4) for j in [i+1] for k in [j+1]]
    [2, 6, 12, 20]
    >>> [j*k for i in range(4) for j, k in [(i+1, i+2)]]
    [2, 6, 12, 20]

Not assignment

    >>> [i*i for i in [*range(4)]]
    [0, 1, 4, 9]
    >>> [i*i for i in (*range(4),)]
    [0, 1, 4, 9]

Make sure the induction variable is not exposed

    >>> i = 20
    >>> sum([i*i for i in range(100)])
    328350

    >>> i
    20

Verify that syntax error's are raised for listcomps used as lvalues

    >>> [y for y in (1,2)] = 10          # doctest: +IGNORE_EXCEPTION_DETAIL
    Traceback (most recent call last):
       ...
    SyntaxError: ...

    >>> [y for y in (1,2)] += 10         # doctest: +IGNORE_EXCEPTION_DETAIL
    Traceback (most recent call last):
       ...
    SyntaxError: ...


########### Tests borrowed from or inspired by test_generators.py ############

Make a nested list comprehension that acts like range()

    >>> def frange(n):
    ...     return [i for i in range(n)]
    >>> frange(10)
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Same again, only as a lambda expression instead of a function definition

    >>> lrange = lambda n:  [i for i in range(n)]
    >>> lrange(10)
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Generators can call other generators:

    >>> def grange(n):
    ...     for x in [i for i in range(n)]:
    ...         yield x
    >>> list(grange(5))
    [0, 1, 2, 3, 4]


Make sure that None is a valid return value

    >>> [None for i in range(10)]
    [None, None, None, None, None, None, None, None, None, None]

c                     ^  \ rS rSrSSSS\4S jrS rS rS rU 4S jr	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S  r!S! r"S" r#S# r$S$ r%S% r&S& r'S' r(S( r)S) r*S* r+S+ r,S, r-S- r.S. r/S/ r0S0 r1S1 r2S2 r3S3 r4S4 r5S5 r6S6 r7S7 r8S8 r9S9 r:S: r;S; r<S< r=S= r>S> r?S? r@SrAU =rB$ )@ListComprehensionTestb   N c           	         [         R                  " U5      nU=(       d    / SQnU GH  nU R                  US9   US:X  a<  [         R                  " S5      R                  [         R                  " US5      S9nS n	OGUS:X  a<  [         R                  " S	5      R                  [         R                  " US5      S9nS
 n	OUnS n	U(       a  UR                  5       O0 n
 U" X5        U=(       d    0 R                  5        H  u  pU R                  U	" X5      X5        M     S S S 5        GM     g ! U a%  nU R                  [        U5      U5         S nAN4S nAff = f! , (       d  f       GME  = f)N)moduleclassfunction)scoper
   zZ
                        class _C:
                            {code}
                    z    )codec                      [        U S   U5      $ )N_C)getattrmoddictnames     </opt/python-3.13.8/usr/lib/python3.13/test/test_listcomps.py
get_output:ListComprehensionTest._check_in_scopes.<locals>.get_outputn   s    &wt}d;;    r   z
                        def _f():
                            {code}
                            return locals()
                        _out = _f()
                    c                     U S   U   $ )N_outr   r   s     r   r   r   w   s    &vt44r   c                 
    X   $ Nr   r   s     r   r   r   {   s
    &},r   )
textwrapdedentsubTestformatindentcopyitemsassertEqualassertIstype)selfr   outputsnsscopesraises	exec_funcr   newcoder   newnskves                 r   _check_in_scopes&ListComprehensionTest._check_in_scopesc   s<   t$::EE*G#&oo /   X__T6%BC <j(&oo / 
  X__T6%BC 5 #G-%'	REg-
 ")B 5 5 7((E)=qD !89 +* 2  3MM$q'62231 +*s6   B#ED-%:E-E3EEEE
E+	c                 6    SnS/ SQ0nU R                  X5        g )Nzf
            items = [(lambda i=i: i) for i in range(5)]
            y = [x() for x in items]
        y)r               r1   r&   r   r'   s      r   *test_lambdas_with_iteration_var_as_default@ListComprehensionTest.test_lambdas_with_iteration_var_as_default   #     (d,r   c                 6    SnS/ SQ0nU R                  X5        g )Nzb
            items = [(lambda: i) for i in range(5)]
            y = [x() for x in items]
        r4   r8   r8   r8   r8   r8   r9   r:   s      r   test_lambdas_with_free_var0ListComprehensionTest.test_lambdas_with_free_var   r=   r   c                      " S S5      nU R                  UR                  / SQ5        U R                  U" 5       R                  5       U5        g )Nc                      ^^ \ rS rSrU4S jr\" S5       V V^s/ s H	  mU4S jPM     snn r\ V Vs/ s H	  o"" 5       PM     snn rSrU=r	$ s  snn f s  snn f )JListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.C   c                    > [        5         T$ r   )super)r&   	__class__s    r   methodQListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.C.method   s      r      c                     > T $ r   r   )is   r   <lambda>SListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.C.<lambda>   s    ar   r   )
__name__
__module____qualname____firstlineno__rI   ranger"   r4   __static_attributes____classcell__).0rM   xrH   s   0p0@r   CrD      s@    ! +0(3(Qi(3E#$ee$A 4$s
   AArY   r?   )r#   r4   r$   rI   )r&   rY   s     r   )test_class_scope_free_var_with_class_cell?ListComprehensionTest.test_class_scope_free_var_with_class_cell   s8    	% 	% 	o.acjjlA&r   c                 8   > SnU R                  US[        /0S9  g )Nz0
            res = [super for x in [1]]
        res)r'   )r1   rG   )r&   r   rH   s     r   test_references_super+ListComprehensionTest.test_references_super   s&     	dUUG,<=r   c                 0    SnU R                  U[        S9  g )Nz4
            res = [__class__ for x in [1]]
        r*   r1   	NameErrorr&   r   s     r   test_references___class__/ListComprehensionTest.test_references___class__   s     	d95r   c                 `    SnU R                  USS/0SS/S9  U R                  U[        S/S9  g )	NzN
            __class__ = 2
            res = [__class__ for x in [1]]
        r]   r6   r	   r   )r'   r)   r
   r*   r)   rb   rd   s     r   !test_references___class___defined7ListComprehensionTest.test_references___class___defined   sH     	uqclHj3I 	 	Kd9gYGr   c                 0    SnU R                  U[        S9  g )Nz
            __class__ = 2
            class C:
                res = [__class__ for x in [1]]
            res = C.res
        ra   rb   rd   s     r   #test_references___class___enclosing9ListComprehensionTest.test_references___class___enclosing   s     	d95r   c                 0    SnU R                  U[        S9  g )NzO
            [super for _ in [1]]
            [__class__ for _ in [1]]
        ra   rb   rd   s     r   *test_super_and_class_cell_in_sibling_comps@ListComprehensionTest.test_super_and_class_cell_in_sibling_comps   s     	d95r   c                 8    Sn/ SQSS.nU R                  X5        g )Nzu
            items = [(lambda: i) for i in range(5)]
            i = 20
            y = [x() for x in items]
        r?      )r4   rM   r9   r:   s      r   test_inner_cell_shadows_outer3ListComprehensionTest.test_inner_cell_shadows_outer   s#    
 (b1d,r   c                 8    SnSS/SS.nU R                  X5        g )Nz
            def f(x):
                return [lambda: x for x in range(x)], x
            fns, x = f(2)
            y = [fn() for fn in fns]
        r5   r6   r4   rX   r9   r:   s      r   &test_inner_cell_shadows_outer_no_store<ListComprehensionTest.test_inner_cell_shadows_outer_no_store   s'     AQ'd,r   c                 8    SnS/ SQ0nU R                  XSS/S9  g )Nzt
            items = [(lambda: y) for i in range(5)]
            y = 2
            z = [x() for x in items]
        z)r6   r6   r6   r6   r6   r	   r   r)   r9   r:   s      r   %test_closure_can_jump_over_comp_scope;ListComprehensionTest.test_closure_can_jump_over_comp_scope   s-    
 (dXz4JKr   c                 6    SnSS/0nU R                  XSS/S9  g )Nz
            def f():
                return [lambda: x for x in (x, [1])[1]]
            x = ...
            y = [fn() for fn in f()]
        r4   r5   r	   r   r{   r9   r:   s      r   test_cell_inner_free_outer0ListComprehensionTest.test_cell_inner_free_outer   s.     *dXz4JKr   c                 b    SnSS/0nU R                  XSS/S9  U R                  US/[        S9  g )	Nzj
            g = 2
            def f():
                return g
            y = [g for x in [1]]
        r4   r6   r	   r   r{   r
   r)   r*   rb   r:   s      r   test_free_inner_cell_outer0ListComprehensionTest.test_free_inner_cell_outer   sE     *dXz4JKdG9YGr   c                 8    SnS/ SQS.nU R                  X5        g )Nz
            y = 10
            items = [(lambda: y) for y in range(5)]
            x = y
            y = 20
            out = [z() for z in items]
        
   r?   )rX   outr9   r:   s      r   'test_inner_cell_shadows_outer_redefined=ListComprehensionTest.test_inner_cell_shadows_outer_redefined   s#     ?3d,r   c                 4    SnSS0nU R                  XSS0S9  g )Nzu
            def inner():
                return g
            [g for g in range(5)]
            x = inner()
        rX   gr(   r9   r:   s      r   test_shadows_outer_cell-ListComprehensionTest.test_shadows_outer_cell  s+     )db	:r   c                 :    SnSSS/S.nU R                  XSS0S9  g )Nzy
            global g
            x = g
            g = 2
            items = [g for g in [1]]
            y = g
        r5   r6   rX   r4   r"   r   r   r9   r:   s      r   test_explicit_global*ListComprehensionTest.test_explicit_global  0     QC0da9r   c                 :    SnSSS/S.nU R                  XSS0S9  g )Nzy
            global g
            x = g
            g = 2
            items = [g for x in [1]]
            y = g
        r5   r6   r   r   r   r9   r:   s      r   test_explicit_global_2,ListComprehensionTest.test_explicit_global_2  r   r   c                 6    SnSS/0nU R                  XSS0S9  g )Nzr
            global g
            fns = [lambda: g for g in [2]]
            items = [fn() for fn in fns]
        r"   r6   r   r5   r   r9   r:   s      r   test_explicit_global_3,ListComprehensionTest.test_explicit_global_3#  s-    
 QC.da9r   c                 4    SnSS0nU R                  XSS/S9  g )NzK
            x = -1
            items = [(x:=y) for y in range(3)]
        rX   r6   r	   r   r{   r9   r:   s      r   test_assignment_expression0ListComprehensionTest.test_assignment_expression,  s,     (dXz4JKr   c                 2    SnSS0nU R                  X5        g )Nz
            lst = range(3)
            funcs = [lambda: x for x in lst]
            inc = [x + 1 for x in lst]
            [x for x in inc]
            x = funcs[0]()
        rX   r6   r9   r:   s      r   test_free_var_in_comp_child1ListComprehensionTest.test_free_var_in_comp_child5  s"     (d,r   c                 2    SnSS0nU R                  X5        g )Nz
            lst = range(3)
            x = -1
            funcs = [lambda: x for x in lst]
            items = [x + 1 for x in lst]
        rX   r   r9   r:   s      r   test_shadow_with_free_and_local5ListComprehensionTest.test_shadow_with_free_and_local@  "     )d,r   c                 4    SnSS/0nU R                  X5        g )Nz<
            x = [1]
            y = [x for x in x]
        rX   r5   r9   r:   s      r   test_shadow_comp_iterable_name4ListComprehensionTest.test_shadow_comp_iterable_nameJ  s$     *d,r   c                 4    SnSS0nU R                  XSS/S9  g )Nz
            x = 1
            def g():
                [x for x in range(3)]
                return x
            g()
        rX   r5   r	   r   r{   r9   r:   s      r   test_nested_free&ListComprehensionTest.test_nested_freeR  s,     (dXz4JKr   c                 2    SnSS0nU R                  X5        g )Nzz
            import sys
            [i for i in range(2)]
            i = 20
            sys._getframe().f_locals
        rM   rr   r9   r:   s      r   test_introspecting_frame_locals5ListComprehensionTest.test_introspecting_frame_locals]  r   r   c                 >    SnSSS// SQ/0nU R                  X5        g )NzX
            l = [2, 3]
            y = [[x ** 2 for x in range(x)] for x in l]
        r4   r   r5   )r   r5   r8   r9   r:   s      r   test_nested!ListComprehensionTest.test_nestedg  s,     !Q+,d,r   c                 d    SnS/ SQ0nU R                  XSS/S9  U R                  US/[        S9  g )	Nzt
            l = [1, 2, 3]
            x = 3
            y = [x for [x ** x for x in range(x)][x - 1] in l]
        r4   )r7   r7   r7   r	   r   r{   r
   r   rb   r:   s      r   test_nested_2#ListComprehensionTest.test_nested_2o  sD    
 	"dXz4JKdG9YGr   c                 6    SnS/ SQ0nU R                  X5        g )Nzv
            l = [(1, 2), (3, 4), (5, 6)]
            y = [x for (x, [x ** x for x in range(x)][x - 1]) in l]
        r4   )r5   r7   rK   r9   r:   s      r   test_nested_3#ListComprehensionTest.test_nested_3y  s#     	"d,r   c                 P    SnSSS/S4SS/S4SS/S4/0nU R                  X5        g )Nz
            items = [([lambda: x for x in range(2)], lambda: x) for x in range(3)]
            out = [([fn() for fn in fns], fn()) for fns, fn in items]
        r   r5   r6   r9   r:   s      r   test_nested_4#ListComprehensionTest.test_nested_4  sB     QFA;!Qq!fa[ABd,r   c                 0    SnU R                  U[        S9  g )Nz4
            [x for x in [1]]
            x
        ra   rb   rd   s     r   test_nameerror$ListComprehensionTest.test_nameerror  s    
 	d95r   c                 4    SnSS/0nU R                  X5        g )Nz.
            y = [__x for __x in [1]]
        r4   r5   r9   r:   s      r   test_dunder_name&ListComprehensionTest.test_dunder_name  s$     *d,r   c                 v    S nU R                  [        5         U" 5         S S S 5        g ! , (       d  f       g = f)Nc                  4     S V s/ s H  o PM       n W $ s  sn f )N)r5   r   )rX   s    r   fGListComprehensionTest.test_unbound_local_after_comprehension.<locals>.f  s!    1QH s   assertRaisesUnboundLocalErrorr&   r   s     r   &test_unbound_local_after_comprehension<ListComprehensionTest.test_unbound_local_after_comprehension  s)    	 01C 211   *
8c                 v    S nU R                  [        5         U" 5         S S S 5        g ! , (       d  f       g = f)Nc                  J    S /n SS/4 V s/ s H  u  W S'   n SPM     sn $ s  sn f )Nr5   r6   r   r   )ls    r   r   HListComprehensionTest.test_unbound_local_inside_comprehension.<locals>.f  s/    A)*Ax0x)1Q4Ax000s    r   r   s     r   'test_unbound_local_inside_comprehension=ListComprehensionTest.test_unbound_local_inside_comprehension  s)    	1 01C 211r   c                 d    SnU R                  USS0SS0SS/S9  U R                  U[        S	/S
9  g )Nz
            a = 1
            def f():
                func, = [(lambda: b) for b in [a]]
                return b, func()
            x = f()
        rX   )r6   r5   br6   r   r	   r(   r)   r
   rh   rb   rd   s     r   /test_global_outside_cellvar_inside_plus_freevarEListComprehensionTest.test_global_outside_cellvar_inside_plus_freevar  sN     	3-S!Hj(5K 	 	M 	d9gYGr   c                 d    SnU R                  USS0SS0SS/S9  U R                  U[        S	/S
9  g )Nz
            a = 1
            def f():
                (func, inner_b), = [[lambda: b for b in c] + [b] for c in [[a]]]
                return b, inner_b, func()
            x = f()
        rX   )r6   r6   r5   r   r6   r   r	   r   r
   rh   rb   rd   s     r   !test_cell_in_nested_comprehension7ListComprehensionTest.test_cell_in_nested_comprehension  sO     	3	"QxX8N 	 	P 	d9gYGr   c                 4    SnU R                  U[        S/S9  g )NzA
            y = 1
            [x + y for x in range(2)]
        r
   rh   rb   rd   s     r   test_name_error_in_class_scope4ListComprehensionTest.test_name_error_in_class_scope  s"     	d9gYGr   c                 <    SnSSS/0nU R                  XSS0S/S9  g )	NzI
            y = 2
            vals = [(x, y) for x in range(2)]
        valsr   r5   r5   r5   r4   r5   r
   r   r9   r:   s      r   test_global_in_class_scope0ListComprehensionTest.test_global_in_class_scope  s5     FF+,da'Kr   c                 <    SnSSS/0nU R                  XSS0S/S9  g )	Nz
            class C:
                y = 2
                vals = [(x, y) for x in range(2)]
            vals = C.vals
        r   r   r   r4   r5   r   r   r9   r:   s      r   %test_in_class_scope_inside_function_1;ListComprehensionTest.test_in_class_scope_inside_function_1  s5     FF+,da*Nr   c                 6    SnSSS/0nU R                  XS/S9  g )Nz
            y = 1
            class C:
                y = 2
                vals = [(x, y) for x in range(2)]
            vals = C.vals
        r   r   r   r   r{   r9   r:   s      r   %test_in_class_scope_inside_function_2;ListComprehensionTest.test_in_class_scope_inside_function_2  s/     FF+,dZLAr   c                 f    SnSSS/0nU R                  XSS/S9  SSS	/0nU R                  XS
/S9  g )Na;  
            y = 1
            class C:
                global y
                y = 2
                # Ensure the listcomp uses the global, not the value in the
                # class namespace
                locals()['y'] = 3
                vals = [(x, y) for x in range(2)]
            vals = C.vals
        r   r   r6   r5   r6   r	   r
   r{   r   r   r   r9   r:   s      r   test_in_class_scope_with_global5ListComprehensionTest.test_in_class_scope_with_global  sV    
 FF+,dXw4GHFF+,dZLAr   c                 6    SnSSS/0nU R                  XS/S9  g )Na=  
            y = 1
            class C:
                nonlocal y
                y = 2
                # Ensure the listcomp uses the global, not the value in the
                # class namespace
                locals()['y'] = 3
                vals = [(x, y) for x in range(2)]
            vals = C.vals
        r   r   r   r   r{   r9   r:   s      r   !test_in_class_scope_with_nonlocal7ListComprehensionTest.test_in_class_scope_with_nonlocal  s/    
 FF+,dZLAr   c                 4    SnSS/0nU R                  XS/S9  g )NzB
            items = [a for a in [1] if [a for _ in [0]]]
        r"   r5   r
   r{   r9   r:   s      r   test_nested_has_free_var.ListComprehensionTest.test_nested_has_free_var  s+     QC.dWI>r   c                 b    SnU R                  USS/0SS/S9  U R                  US/ 0SS0S	/S
9  g )NzY
            z = 1
            items = [a for a in [1] if [x for x in [1] if z]]
        r"   r5   r	   r   r{   rz   r   r
   r   r9   rd   s     r   ,test_nested_free_var_not_bound_in_outer_compBListComprehensionTest.test_nested_free_var_not_bound_in_outer_comp  sL     	dWqcNHj;QRdWbMsAhyQr   c                 2    SnU R                  USS/05        g )Nz]
            items = [_C for _C in [1] for [0, 1][[x for x in [1] if _C][0]] in [2]]
        r"   r5   r9   rd   s     r   test_nested_free_var_in_iter2ListComprehensionTest.test_nested_free_var_in_iter  s!     	dWqcN3r   c                 >    SnU R                  USS/ 4SS/4/05        g )NzM
            items = [(_C, [x for x in [1] if _C]) for _C in [0, 1]]
        r"   r   r5   r9   rd   s     r   test_nested_free_var_in_expr2ListComprehensionTest.test_nested_free_var_in_expr  s/     	dW2wQC.A$BCr   c                 4    SnU R                  USS/S.5        g )Nz
            f = [(z, lambda y: [(x, y, z) for x in [3]]) for z in [1]]
            (z, func), = f
            out = func(2)
        r5   )r7   r6   r5   )rz   r   r9   rd   s     r   test_nested_listcomp_in_lambda4ListComprehensionTest.test_nested_listcomp_in_lambda#  s"    
 	d!YK$@Ar   c                 2    SnU R                  USS S.5        g )Nz
            (func, c), = [(a, b) for b in [1] for a in [lambda : a]]
            d = func()
            assert d is func
            # must use "a" in this scope
            e = a if False else None
        r5   )cr0   r9   rd   s     r   test_lambda_in_iter)ListComprehensionTest.test_lambda_in_iter+  s      	d!$$78r   c                 2    SnU R                  USS/0S/S9  g )Nz*
            a = [1 for a in [0]]
        ar5   r   r{   r9   rd   s     r   .test_assign_to_comp_iter_var_in_outer_functionDListComprehensionTest.test_assign_to_comp_iter_var_in_outer_function5  s(     	dS1#J
|Dr   c                     SnU R                  US/ S.S/S9  U R                  USS/S.S/S9  U R                  U[        S/S	9  g )
Nz
            def b():
                [a for b in [1] for _ in []]
                return b, locals()
            r, s = b()
            x = r is b
            y = list(s.keys())
        TrX   r4   r	   r{   r   r   r
   rh   rb   rd   s     r   test_no_leakage_to_locals/ListComprehensionTest.test_no_leakage_to_locals;  s\     	d$R$8(Ld$cU$;ZLQd9gYGr   c           	      H    SnU R                  USS/SS/SS/SS/SS.5        g )NaJ  
            l = [1, 2]
            y = 0
            items = [locals()["x"] for x in l]
            items2 = [vars()["x"] for x in l]
            items3 = [("x" in dir()) for x in l]
            items4 = [eval("x") for x in l]
            # x is available, and does not overwrite y
            [exec("y = x") for x in l]
        r5   r6   Tr   )r"   items2items3items4r4   r9   rd   s     r   !test_iter_var_available_in_locals7ListComprehensionTest.test_iter_var_available_in_localsH  s@    	 	Qa&,a&		
r   c                     SnUR                  SS9nU R                  US/S/S S.5        UR                  SS9nU R                  US/S S/S.[        S9  g )	Nz
            value = ["ab"]
            result = snapshot = None
            try:
                result = [{func}(value) for value in value]
            except:
                snapshot = value
                raise
        lenfuncabr6   valueresultsnapshotintra   r   r1   
ValueErrorr&   templater   s      r   test_comp_in_try_except-ListComprehensionTest.test_comp_in_try_except^  sn     E*dtfQU$VWE*dtfSWRX$Y%/ 	 	1r   c                     SnUR                  SS9nU R                  US/S/S/S.5        UR                  SS9nU R                  US/S S/S.[        S9  g )	Nz
            value = ["ab"]
            result = snapshot = None
            try:
                result = [{func}(value) for value in value]
            finally:
                snapshot = value
        r  r  r  r6   r  r  ra   r  r  s      r   test_comp_in_try_finally.ListComprehensionTest.test_comp_in_try_finallyp  sq     E*dtfRVQW$XYE*dtfSWRX$Y%/ 	 	1r   c                 4    SnU R                  USSS /05        g )Nz
            value = [1, None]
            try:
                [v for v in value].sort()
            except:
                pass
        r  r5   r9   rd   s     r    test_exception_in_post_comp_call6ListComprehensionTest.test_exception_in_post_comp_call  s$     	dWq$i$89r   c                 h    SnSS K nU R                  USS0SU0S9  SnU R                  USS0SU0S9  g )NzM
            val = "a" in [sys._getframe().f_locals for a in [0]][0]
        r   valFsysr   zK
            val = [sys._getframe().f_locals["a"] for a in [0]][0]
        )r)  r1   )r&   r   r)  s      r   test_frame_locals'ListComprehensionTest.test_frame_locals  sQ     	dUENs|D 	dUAJE3<@r   c                    ^  [        U[        R                  5      (       d  U$ UR                  [	        U 4S jUR
                   5       5      S9$ )Nc              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )_recursive_replace)rW   r   r&   s     r   	<genexpr>;ListComprehensionTest._recursive_replace.<locals>.<genexpr>  s#      2
0D1D##A&&0Ds   !)	co_consts)
isinstancetypesCodeTypereplacetupler1  )r&   
maybe_codes   ` r   r.  (ListComprehensionTest._recursive_replace  sJ    *enn55!!E 2
0:0D0D2
 -
!  	r   c                 V    [        USS5      nU R                  U5      n[        X25        g )Nz<string>exec)compiler.  r:  )r&   code_stringr(   cos       r   _replacing_exec%ListComprehensionTest._replacing_exec  s'    [*f5$$R(Rr   c                 r    SnU R                  US/SS.5        U R                  US/SS.U R                  S9  g )Nza
            x = 3
            [x for x in (1, 2)]
            dir()
            y = [x]
        r7   rv   r+   )r1   r>  rd   s     r   test_code_replace'ListComprehensionTest.test_code_replace  sD     	d1#A$67d1#A$6$BVBVWr   c           	      v   SnSR                  S [        U5       5       5      nSR                  S [        U5       5       5      nS[        [        U5      5      0[        U5       Vs0 s H	  nSU 3U_M     snEnSU S	U S
U SU S3	nU R                  Xe5        U R                  XeU R                  S9  g s  snf )Ni,  z; c              3   2   #    U  H  nS U SU 3v   M     g7f)rX   z = Nr   rW   rM   s     r   r/  GListComprehensionTest.test_code_replace_extended_arg.<locals>.<genexpr>  s     H7G!!A3c!7Gs   z, c              3   ,   #    U  H
  nS U 3v   M     g7f)rX   Nr   rF  s     r   r/  rG    s     @/?!!g/?s   r4   rX   z
            z
            [(z) for z6 in (range(300),)]
            dir()
            y = [z
]
        rA  )joinrT   listr1   r>  )r&   	num_namesassignments	name_listrM   expectedr   s          r   test_code_replace_extended_arg4ListComprehensionTest.test_code_replace_extended_arg  s    	iiHuY7GHHII@uY/?@@	eI&'
#(#34#3a1#wz#34
M k	{ + 		 	d-d8L8LM 5s   'B6c                     SnU R                  USS/0SS0S9  SnU R                  USS/S.SS0S	/S
9  U R                  USS/S.SS0SS/S
9  g )NzG
            [x for x in [1]]
            y = [x for _ in [1]]
        r4   r7   rX   r   zY
            x = 2
            [x for x in [1]]
            y = [x for _ in [1]]
        r6   r  r
   r   r   r	   r9   rd   s     r   &test_multiple_comprehension_name_reuse<ListComprehensionTest.test_multiple_comprehension_name_reuse  s     	dS1#JC8<
 	d!1#$6C8WIVd!1#$6C8ZYaLbcr   c                    S nS nS nUS4US4US44 H  u  pEU R                  U5         U" 5       n[        R                  " UR                  5      S   nSnUR                  n	U R                  UR                  U	R                  S	-   5        U R                  UR                  U	R                  S	-   5        U R                  UR                  UR                  U-
  UR                  U-
   U5        S S S 5        M     g ! , (       d  f       M  = f)
Nc                  r     [        SS9 V s/ s H  o PM       n g s  sn f ! [         a  nUs S nA$ S nAff = f)NT)init_raisesr   	ExceptionrX   r0   s     r   rV  CListComprehensionTest.test_exception_locations.<locals>.init_raises  8    &4898q899           
6166c                  r     [        SS9 V s/ s H  o PM       n g s  sn f ! [         a  nUs S nA$ S nAff = f)NT)next_raisesrW  rY  s     r   r^  CListComprehensionTest.test_exception_locations.<locals>.next_raises  r[  r\  c                  r     [        SS9 V s/ s H  o PM       n g s  sn f ! [         a  nUs S nA$ S nAff = f)NT)iter_raisesrW  rY  s     r   ra  CListComprehensionTest.test_exception_locations.<locals>.iter_raises  r[  r\  zBrokenIter(init_raises=True)zBrokenIter(next_raises=True)zBrokenIter(iter_raises=True)r      r6   )r   	traceback
extract_tb__traceback____code__r#   linenoco_firstlineno
end_linenolinecolno	end_colno)
r&   rV  r^  ra  r  rN  excr   r    r=  s
             r   test_exception_locations.ListComprehensionTest.test_exception_locations  s    			 !,-KL +-KL +-KL ND d#f(():):;A>]]  2+<+<q+@A  r/@/@1/DE  &(81;;;O!P!)+ $#	  $#s   CC<<
D	)CrP   rQ   rR   rS   r:  r1   r;   r@   rZ   r^   re   ri   rl   ro   rs   rw   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r"  r%  r*  r.  r>  rB  rO  rR  ro  rU   rV   )rH   s   @r   r   r   b   s[   -1d4PR#'"EH--	'>6H66--LL	H	-;	:	::L	---	L--H--6-HHHLO	BB"B?R4DB9EH
,1$1":
A
XN"d"+ "+r   r   doctestsc                 N    UR                  [        R                  " 5       5        U$ r   )addTestdoctestDocTestSuite)loadertestspatterns      r   
load_testsry    s    	MM'&&()Lr   __main__)rt  r   rd  r3  unittesttest.supportr   rq  TestCaser   __test__ry  rP   mainr   r   r   <module>r     s^         #UpM
+H-- M
+^ "
 zMMO r   