
    dafT                         d dl Z d dlZd dlZd dlZdZ G d dej
                        ZdeiZd Ze	dk(  r ej                          yy)    Na  
########### 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                   t    e Zd ZddddefdZd Zd Zd Z fdZd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5d5 Z6d6 Z7d7 Z8d8 Z9d9 Z:d: Z; xZ<S );ListComprehensionTestN c           	         t        j                  |      }|xs g d}|D ]  }| j                  |      5  |dk(  r=t        j                  d      j                  t        j                  |d            }d }	nG|dk(  r=t        j                  d	      j                  t        j                  |d            }d
 }	n|}d }	|r|j                         ni }
	  |||
       |xs i j                         D ]  \  }}| j                   |	|
|      ||       ! 	 d d d         y # |$ r%}| j                  t        |      |       Y d }~0d }~ww xY w# 1 sw Y   6xY w)N)moduleclassfunction)scoper   zZ
                        class _C:
                            {code}
                    z    )codec                      t        | d   |      S )N_C)getattrmoddictnames     ./root/Python-3.12.4/Lib/test/test_listcomps.py
get_outputz:ListComprehensionTest._check_in_scopes.<locals>.get_outputk   s    &wt}d;;    r	   z
                        def _f():
                            {code}
                            return locals()
                        _out = _f()
                    c                     | d   |   S )N_outr   r   s     r   r   z:ListComprehensionTest._check_in_scopes.<locals>.get_outputt   s    &vt44r   c                     | |   S Nr   r   s     r   r   z:ListComprehensionTest._check_in_scopes.<locals>.get_outputx   s    &t},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_scopesz&ListComprehensionTest._check_in_scopes`   s`   t$:: 	EEE* EG#&oo /   X__T6%BC <j(&oo / 
  X__T6%BC 5 #G-%'	REgu-
 ")B 5 5 7 E1((E1)=q!DE9E E	E2  3MM$q'62231E Es6   BE	D7EE	$E?EE		EE	c                 8    d}dg di}| j                  ||       y )Nzf
            items = [(lambda i=i: i) for i in range(5)]
            y = [x() for x in items]
        y)r               r.   r#   r   r$   s      r   *test_lambdas_with_iteration_var_as_defaultz@ListComprehensionTest.test_lambdas_with_iteration_var_as_default   %     (dG,r   c                 8    d}dg di}| j                  ||       y )Nzb
            items = [(lambda: i) for i in range(5)]
            y = [x() for x in items]
        r0   r4   r4   r4   r4   r4   r5   r6   s      r   test_lambdas_with_free_varz0ListComprehensionTest.test_lambdas_with_free_var   r8   r   c                      G d d      }| j                  |j                  g d       | j                   |       j                         |       y )Nc                       e Zd ZfdZ ed      D  cg c]  fd	 c}} ZeD  cg c]	  } |        c}} ZxZS c c}} w c c}} w )JListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.Cc                     t                S r   )super)r#   	__class__s    r   methodzQListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.C.method   s      r      c                       S r   r   )is   r   <lambda>zSListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.C.<lambda>   s    a r   )__name__
__module____qualname__rB   ranger   r0   __classcell__).0rE   xrA   s   0p0@r   Cr>      s;    ! +0(33Qi3E#$$A 4$s
   AA	rN   r:   )r    r0   r!   rB   )r#   rN   s     r   )test_class_scope_free_var_with_class_cellz?ListComprehensionTest.test_class_scope_free_var_with_class_cell   s8    	% 	% 	o.acjjlA&r   c                 >    d}| j                  |dt        gi       y )Nz0
            res = [super for x in [1]]
        res)r$   )r.   r@   )r#   r   rA   s     r   test_references_superz+ListComprehensionTest.test_references_super   s&     	dUUG,<=r   c                 6    d}| j                  |t               y )Nz4
            res = [__class__ for x in [1]]
        r'   r.   	NameErrorr#   r   s     r   test_references___class__z/ListComprehensionTest.test_references___class__   s     	d95r   c                 :    d}g ddd}| j                  ||       y )Nzu
            items = [(lambda: i) for i in range(5)]
            i = 20
            y = [x() for x in items]
        r:      )r0   rE   r5   r6   s      r   test_inner_cell_shadows_outerz3ListComprehensionTest.test_inner_cell_shadows_outer   s%    
 (b1dG,r   c                 :    d}ddgdd}| j                  ||       y )Nz
            def f(x):
                return [lambda: x for x in range(x)], x
            fns, x = f(2)
            y = [fn() for fn in fns]
        r1   r2   r0   rM   r5   r6   s      r   &test_inner_cell_shadows_outer_no_storez<ListComprehensionTest.test_inner_cell_shadows_outer_no_store   s)     AQ'dG,r   c                 @    d}dg di}| j                  ||ddg       y )Nzt
            items = [(lambda: y) for i in range(5)]
            y = 2
            z = [x() for x in items]
        z)r2   r2   r2   r2   r2   r   r	   r&   r5   r6   s      r   %test_closure_can_jump_over_comp_scopez;ListComprehensionTest.test_closure_can_jump_over_comp_scope   s/    
 (dGXz4JKr   c                 >    d}ddgi}| j                  ||ddg       y )Nz
            def f():
                return [lambda: x for x in (x, [1])[1]]
            x = ...
            y = [fn() for fn in f()]
        r0   r1   r   r	   ra   r5   r6   s      r   test_cell_inner_free_outerz0ListComprehensionTest.test_cell_inner_free_outer   s0     *dGXz4JKr   c                 p    d}ddgi}| j                  ||ddg       | j                  |dgt               y )	Nzj
            g = 2
            def f():
                return g
            y = [g for x in [1]]
        r0   r2   r   r	   ra   r   r&   r'   rU   r6   s      r   test_free_inner_cell_outerz0ListComprehensionTest.test_free_inner_cell_outer   sG     *dGXz4JKdG9YGr   c                 :    d}dg dd}| j                  ||       y )Nz
            y = 10
            items = [(lambda: y) for y in range(5)]
            x = y
            y = 20
            out = [z() for z in items]
        
   r:   )rM   outr5   r6   s      r   'test_inner_cell_shadows_outer_redefinedz=ListComprehensionTest.test_inner_cell_shadows_outer_redefined   s%     ?3dG,r   c                 <    d}ddi}| j                  ||ddi       y )Nzu
            def inner():
                return g
            [g for g in range(5)]
            x = inner()
        rM   gr%   r5   r6   s      r   test_shadows_outer_cellz-ListComprehensionTest.test_shadows_outer_cell   s-     )dGb	:r   c                 B    d}dddgd}| j                  ||ddi       y )Nzy
            global g
            x = g
            g = 2
            items = [g for g in [1]]
            y = g
        r1   r2   rM   r0   r   rn   ro   r5   r6   s      r   test_explicit_globalz*ListComprehensionTest.test_explicit_global   2     QC0dGa9r   c                 B    d}dddgd}| j                  ||ddi       y )Nzy
            global g
            x = g
            g = 2
            items = [g for x in [1]]
            y = g
        r1   r2   rr   rn   ro   r5   r6   s      r   test_explicit_global_2z,ListComprehensionTest.test_explicit_global_2   rt   r   c                 >    d}ddgi}| j                  ||ddi       y )Nzr
            global g
            fns = [lambda: g for g in [2]]
            items = [fn() for fn in fns]
        r   r2   rn   r1   ro   r5   r6   s      r   test_explicit_global_3z,ListComprehensionTest.test_explicit_global_3  s/    
 QC.dGa9r   c                 <    d}ddi}| j                  ||ddg       y )NzK
            x = -1
            items = [(x:=y) for y in range(3)]
        rM   r2   r   r	   ra   r5   r6   s      r   test_assignment_expressionz0ListComprehensionTest.test_assignment_expression  s.     (dGXz4JKr   c                 4    d}ddi}| j                  ||       y )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]()
        rM   r2   r5   r6   s      r   test_free_var_in_comp_childz1ListComprehensionTest.test_free_var_in_comp_child  s$     (dG,r   c                 4    d}ddi}| j                  ||       y )Nz
            lst = range(3)
            x = -1
            funcs = [lambda: x for x in lst]
            items = [x + 1 for x in lst]
        rM   rm   r5   r6   s      r   test_shadow_with_free_and_localz5ListComprehensionTest.test_shadow_with_free_and_local$  $     )dG,r   c                 6    d}ddgi}| j                  ||       y )Nz<
            x = [1]
            y = [x for x in x]
        rM   r1   r5   r6   s      r   test_shadow_comp_iterable_namez4ListComprehensionTest.test_shadow_comp_iterable_name.  s&     *dG,r   c                 <    d}ddi}| j                  ||ddg       y )Nz
            x = 1
            def g():
                [x for x in range(3)]
                return x
            g()
        rM   r1   r   r	   ra   r5   r6   s      r   test_nested_freez&ListComprehensionTest.test_nested_free6  s.     (dGXz4JKr   c                 4    d}ddi}| j                  ||       y )Nzz
            import sys
            [i for i in range(2)]
            i = 20
            sys._getframe().f_locals
        rE   rZ   r5   r6   s      r   test_introspecting_frame_localsz5ListComprehensionTest.test_introspecting_frame_localsA  r   r   c                 @    d}dddgg dgi}| j                  ||       y )NzX
            l = [2, 3]
            y = [[x ** 2 for x in range(x)] for x in l]
        r0   r   r1   )r   r1   r4   r5   r6   s      r   test_nestedz!ListComprehensionTest.test_nestedK  s.     !Q+,dG,r   c                 r    d}dg di}| j                  ||ddg       | j                  |dgt               y )	Nzt
            l = [1, 2, 3]
            x = 3
            y = [x for [x ** x for x in range(x)][x - 1] in l]
        r0   )r3   r3   r3   r   r	   ra   r   rf   rU   r6   s      r   test_nested_2z#ListComprehensionTest.test_nested_2S  sF    
 	"dGXz4JKdG9YGr   c                 8    d}dg di}| j                  ||       y )Nzv
            l = [(1, 2), (3, 4), (5, 6)]
            y = [x for (x, [x ** x for x in range(x)][x - 1]) in l]
        r0   )r1   r3   rC   r5   r6   s      r   test_nested_3z#ListComprehensionTest.test_nested_3]  s%     	"dG,r   c                 R    d}dddgdfddgdfddgdfgi}| j                  ||       y )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]
        rj   r1   r2   r5   r6   s      r   test_nested_4z#ListComprehensionTest.test_nested_4e  sD     QFA;!Qq!fa[ABdG,r   c                 6    d}| j                  |t               y )Nz4
            [x for x in [1]]
            x
        rT   rU   rW   s     r   test_nameerrorz$ListComprehensionTest.test_nameerrorm  s    
 	d95r   c                 6    d}ddgi}| j                  ||       y )Nz.
            y = [__x for __x in [1]]
        r0   r1   r5   r6   s      r   test_dunder_namez&ListComprehensionTest.test_dunder_nameu  s&     *dG,r   c                 l    d }| j                  t              5   |        d d d        y # 1 sw Y   y xY w)Nc                  2    	 dD  cg c]  } |  c}   S c c} w )N)r1   r   )rM   s    r   fzGListComprehensionTest.test_unbound_local_after_comprehension.<locals>.f}  s    1QH s   	assertRaisesUnboundLocalErrorr#   r   s     r   &test_unbound_local_after_comprehensionz<ListComprehensionTest.test_unbound_local_after_comprehension|  s2    	 01 	C	 	 	   *3c                 l    d }| j                  t              5   |        d d d        y # 1 sw Y   y xY w)Nc                  D    d g} ddgfD  cg c]
  \   d<   } d c} S c c} w )Nr1   r2   r   r   )ls    r   r   zHListComprehensionTest.test_unbound_local_inside_comprehension.<locals>.f  s+    A)*Ax0)1Q4A000s   r   r   s     r   'test_unbound_local_inside_comprehensionz=ListComprehensionTest.test_unbound_local_inside_comprehension  s2    	1 01 	C	 	 	r   c                 p    d}| j                  |ddiddiddg       | j                  |t        d	g
       y )Nz
            a = 1
            def f():
                func, = [(lambda: b) for b in [a]]
                return b, func()
            x = f()
        rM   )r2   r1   br2   r	   r   r%   r&   r   r'   r&   rU   rW   s     r   /test_global_outside_cellvar_inside_plus_freevarzEListComprehensionTest.test_global_outside_cellvar_inside_plus_freevar  sN     	3-S!Hj(5K 	 	M 	d9gYGr   c                 p    d}| j                  |ddiddiddg       | j                  |t        d	g
       y )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()
        rM   )r2   r2   r1   r   r2   r	   r   r   r   r   rU   rW   s     r   !test_cell_in_nested_comprehensionz7ListComprehensionTest.test_cell_in_nested_comprehension  sO     	3	"QxX8N 	 	P 	d9gYGr   c                 :    d}| j                  |t        dg       y )NzA
            y = 1
            [x + y for x in range(2)]
        r   r   rU   rW   s     r   test_name_error_in_class_scopez4ListComprehensionTest.test_name_error_in_class_scope  s"     	d9gYGr   c                 D    d}dddgi}| j                  ||ddidg       y )	NzI
            y = 2
            vals = [(x, y) for x in range(2)]
        valsr   r1   r1   r1   r0   r1   r   r   r5   r6   s      r   test_global_in_class_scopez0ListComprehensionTest.test_global_in_class_scope  s7     FF+,dGa'Kr   c                 D    d}dddgi}| j                  ||ddidg       y )	Nz
            class C:
                y = 2
                vals = [(x, y) for x in range(2)]
            vals = C.vals
        r   r   r   r0   r1   r	   r   r5   r6   s      r   %test_in_class_scope_inside_function_1z;ListComprehensionTest.test_in_class_scope_inside_function_1  s7     FF+,dGa*Nr   c                 >    d}dddgi}| j                  ||dg       y )Nz
            y = 1
            class C:
                y = 2
                vals = [(x, y) for x in range(2)]
            vals = C.vals
        r   r   r   r	   ra   r5   r6   s      r   %test_in_class_scope_inside_function_2z;ListComprehensionTest.test_in_class_scope_inside_function_2  s1     FF+,dGZLAr   c                 v    d}dddgi}| j                  ||ddg       ddd	gi}| j                  ||d
g       y )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   r2   r1   r2   r   r   ra   r   r   r	   r5   r6   s      r   test_in_class_scope_with_globalz5ListComprehensionTest.test_in_class_scope_with_global  sZ    
 FF+,dGXw4GHFF+,dGZLAr   c                 >    d}dddgi}| j                  ||dg       y )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	   ra   r5   r6   s      r   !test_in_class_scope_with_nonlocalz7ListComprehensionTest.test_in_class_scope_with_nonlocal  s1    
 FF+,dGZLAr   c                 <    d}ddgi}| j                  ||dg       y )NzB
            items = [a for a in [1] if [a for _ in [0]]]
        r   r1   r   ra   r5   r6   s      r   test_nested_has_free_varz.ListComprehensionTest.test_nested_has_free_var  s-     QC.dGWI>r   c                 n    d}| j                  |ddgiddg       | j                  |dg iddid	g
       y )NzY
            z = 1
            items = [a for a in [1] if [x for x in [1] if z]]
        r   r1   r   r	   ra   r`   r   r   r   r5   rW   s     r   ,test_nested_free_var_not_bound_in_outer_compzBListComprehensionTest.test_nested_free_var_not_bound_in_outer_comp  sL     	dWqcNHj;QRdWbMsAhyQr   c                 2    d}| j                  |ddgi       y )Nz]
            items = [_C for _C in [1] for [0, 1][[x for x in [1] if _C][0]] in [2]]
        r   r1   r5   rW   s     r   test_nested_free_var_in_iterz2ListComprehensionTest.test_nested_free_var_in_iter  s!     	dWqcN3r   c                 >    d}| j                  |ddg fddgfgi       y )NzM
            items = [(_C, [x for x in [1] if _C]) for _C in [0, 1]]
        r   r   r1   r5   rW   s     r   test_nested_free_var_in_exprz2ListComprehensionTest.test_nested_free_var_in_expr  s/     	dW2wQC.A$BCr   c                 4    d}| j                  |ddgd       y )Nz
            f = [(z, lambda y: [(x, y, z) for x in [3]]) for z in [1]]
            (z, func), = f
            out = func(2)
        r1   )r3   r2   r1   )r`   rj   r5   rW   s     r   test_nested_listcomp_in_lambdaz4ListComprehensionTest.test_nested_listcomp_in_lambda  s"    
 	d!YK$@Ar   c                 2    d}| j                  |dd d       y )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
        r1   )cr-   r5   rW   s     r   test_lambda_in_iterz)ListComprehensionTest.test_lambda_in_iter  s      	d!$$78r   c                 8    d}| j                  |ddgidg       y )Nz*
            a = [1 for a in [0]]
        ar1   r	   ra   r5   rW   s     r   .test_assign_to_comp_iter_var_in_outer_functionzDListComprehensionTest.test_assign_to_comp_iter_var_in_outer_function  s(     	dS1#J
|Dr   c                     d}| j                  |dg ddg       | j                  |ddgddg       | j                  |t        dg	       y )
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rM   r0   r   ra   r   r	   r   r   rU   rW   s     r   test_no_leakage_to_localsz/ListComprehensionTest.test_no_leakage_to_locals  s\     	d$R$8(Ld$cU$;ZLQd9gYGr   c           	      H    d}| j                  |ddgddgddgddgdd       y )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]
        r1   r2   Tr   )r   items2items3items4r0   r5   rW   s     r   !test_iter_var_available_in_localsz7ListComprehensionTest.test_iter_var_available_in_locals,  s@    	 	Qa&,a&		
r   c                     d}|j                  d      }| j                  |dgdgd d       |j                  d      }| j                  |dgd dgdt               y )	Nz
            value = ["ab"]
            result = snapshot = None
            try:
                result = [{func}(value) for value in value]
            except:
                snapshot = value
                raise
        lenfuncabr2   valueresultsnapshotintrT   r   r.   
ValueErrorr#   templater   s      r   test_comp_in_try_exceptz-ListComprehensionTest.test_comp_in_try_exceptB  sn     E*dtfQU$VWE*dtfSWRX$Y%/ 	 	1r   c                     d}|j                  d      }| j                  |dgdgdgd       |j                  d      }| j                  |dgd dgdt               y )	Nz
            value = ["ab"]
            result = snapshot = None
            try:
                result = [{func}(value) for value in value]
            finally:
                snapshot = value
        r   r   r   r2   r   r   rT   r   r   s      r   test_comp_in_try_finallyz.ListComprehensionTest.test_comp_in_try_finallyT  sq     E*dtfRVQW$XYE*dtfSWRX$Y%/ 	 	1r   c                 4    d}| j                  |ddd gi       y )Nz
            value = [1, None]
            try:
                [v for v in value].sort()
            except:
                pass
        r   r1   r5   rW   s     r    test_exception_in_post_comp_callz6ListComprehensionTest.test_exception_in_post_comp_calle  s$     	dWq$i$89r   c                 @    d}dd l }| j                  |ddid|i       y )NzK
            val = [sys._getframe().f_locals for a in [0]][0]["a"]
        r   valsysro   )r   r.   )r#   r   r   s      r   test_frame_localsz'ListComprehensionTest.test_frame_localso  s+     	dUAJE3<@r   c                      t        |t        j                        s|S |j                  t	         fd|j
                  D                    S )Nc              3   @   K   | ]  }j                  |        y wr   )_recursive_replace)rL   r   r#   s     r   	<genexpr>z;ListComprehensionTest._recursive_replace.<locals>.<genexpr>y  s!      2
+,D##A&2
s   )	co_consts)
isinstancetypesCodeTypereplacetupler   )r#   
maybe_codes   ` r   r   z(ListComprehensionTest._recursive_replacev  sG    *enn5!!E 2
0:0D0D2
 -
!  	r   c                 X    t        |dd      }| j                  |      }t        ||       y )Nz<string>exec)compiler   r   )r#   code_stringr%   cos       r   _replacing_execz%ListComprehensionTest._replacing_exec}  s)    [*f5$$R(Rr   c                 x    d}| j                  |dgdd       | j                  |dgdd| j                         y )Nza
            x = 3
            [x for x in (1, 2)]
            dir()
            y = [x]
        r3   r]   r(   )r.   r   rW   s     r   test_code_replacez'ListComprehensionTest.test_code_replace  sD     	d1#A$67d1#A$6$BVBVWr   c           	      z   d}dj                  d t        |      D              }dj                  d t        |      D              }dt        t        |            it        |      D ci c]  }d| |
 c}}d| d	| d
| d| d	}| j                  ||       | j                  ||| j                         y c c}w )Ni,  z; c              3   ,   K   | ]  }d | d|   yw)rM   z = Nr   rL   rE   s     r   r   zGListComprehensionTest.test_code_replace_extended_arg.<locals>.<genexpr>  s     H!!A3c!Hs   z, c              3   &   K   | ]	  }d |   yw)rM   Nr   r   s     r   r   zGListComprehensionTest.test_code_replace_extended_arg.<locals>.<genexpr>  s     @!!g@s   r0   rM   z
            z
            [(z) for z6 in (range(300),)]
            dir()
            y = [z
]
        r   )joinrJ   listr.   r   )r#   	num_namesassignments	name_listrE   expectedr   s          r   test_code_replace_extended_argz4ListComprehensionTest.test_code_replace_extended_arg  s    	iiHuY7GHHII@uY/?@@	eI&'
#(#34a1#wz4
M k	{ + 		 	dH-dH8L8LM 5s   'B8c                     d}| j                  |ddgiddi       d}| j                  |ddgdddid	g
       | j                  |ddgdddiddg
       y )NzG
            [x for x in [1]]
            y = [x for _ in [1]]
        r0   r3   rM   ro   zY
            x = 2
            [x for x in [1]]
            y = [x for _ in [1]]
        r2   r   r   r   r	   r   r5   rW   s     r   &test_multiple_comprehension_name_reusez<ListComprehensionTest.test_multiple_comprehension_name_reuse  s     	dS1#JC8<
 	d!1#$6C8WIVd!1#$6C8ZYaLbcr   )=rG   rH   rI   r   r.   r7   r;   rO   rR   rX   r[   r^   rb   rd   rg   rk   rp   rs   rv   rx   rz   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  rK   )rA   s   @r   r   r   _   sA   -1d4PR#'"EH--	'>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                 L    |j                  t        j                                |S r   )addTestdoctestDocTestSuite)loadertestspatterns      r   
load_testsr    s    	MM'&&()Lr   __main__)r
  r   r   unittestr  TestCaser   __test__r  rG   mainr   r   r   <module>r     s\       UpK	dH-- K	dZ "
 zHMMO r   