+
    Bi`                         ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt Rt ! R R]P                  4      t	R]/t
R t]R8X  d   ]P                  ! 4        R# R# )	    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                     a a ] tR t^bt oRRRR?]3R ltR tR tR tV 3R l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 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- t0R. t1R/ t2R0 t3R1 t4R2 t5R3 t6R4 t7R5 t8R6 t9R7 t:R8 t;R9 t<R: t=R; t>R< t?R= t@R> tAR?tBVtCV ;tD# )@ListComprehensionTestNc           
        \         P                  ! V4      pT;'       g    . ROpV EF  pV P                  VR7      ;_uu_ 4        VR8X  d@   \         P                  ! R4      P                  \         P                  ! VR4      R7      pR p	MKVR8X  d@   \         P                  ! R4      P                  \         P                  ! VR4      R7      pR	 p	MTpR
 p	V'       d   VP                  4       M/ p
 V! W4       T;'       g    / P                  4        F  w  rV P                  V	! W4      W4       K  	  RRR4       EK  	  R#   T d&   pT P                  \        T4      T4        Rp?L6Rp?ii ; i  + '       g   i     EK^  ; i)moduleclassfunction)scopezZ
                        class _C:
                            {code}
                    z    )codec                 (    \        V R ,          V4      # )_C)getattrmoddictnames   &&*/usr/lib/python3.14/test/test_listcomps.py
get_output:ListComprehensionTest._check_in_scopes.<locals>.get_outputn   s    &wt}d;;    z
                        def _f():
                            {code}
                            return locals()
                        _out = _f()
                    c                 "    V R ,          V,          # )_out r   s   &&r   r   r   w   s    &vt44r   c                     W,          # Nr   r   s   &&r   r   r   {   s
    &},r   N)r   r   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   sG   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 +**sC   BE3E32E:E32E3E0	E+	&E3+E0	0E33Fc                8    R pR. RO/pV P                  W4       R# )zf
            items = [(lambda i=i: i) for i in range(5)]
            y = [x() for x in items]
        yN)r               r0   r%   r   r&   s   &  r   *test_lambdas_with_iteration_var_as_default@ListComprehensionTest.test_lambdas_with_iteration_var_as_default   #     (d,r   c                8    R pR. RO/pV P                  W4       R# )zb
            items = [(lambda: i) for i in range(5)]
            y = [x() for x in items]
        r3   Nr7   r7   r7   r7   r7   r8   r9   s   &  r   test_lambdas_with_free_var0ListComprehensionTest.test_lambdas_with_free_var   r<   r   c                     ! R  R4      pV P                  VP                  . RO4       V P                  V! 4       P                  4       V4       R# )c                      a aa ] tR t^t oV3R lt]! ^4       U a u. uF	  o V 3R lNK  	  up t] Uu. uF	  q! 4       NK  	  uptRtVt	V;t
# u up i u upi )JListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.Cc                   < \        4        S# r   )super)r%   	__class__s   &r   methodQListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.C.method   s      r   c                     < S # r   r   )is   r   <lambda>SListComprehensionTest.test_class_scope_free_var_with_class_cell.<locals>.C.<lambda>   s    ar   r   )__name__
__module____qualname____firstlineno__rG   ranger!   r3   __static_attributes____classdictcell____classcell__)rJ   xrF   __classdict__s   p0@@r   CrC      sD     ! +0(3(Qi(3E#$ee$AA 4$s
   AArW   Nr>   )r"   r3   r#   rG   )r%   rW   s   & r   )test_class_scope_free_var_with_class_cell?ListComprehensionTest.test_class_scope_free_var_with_class_cell   s8    	% 	% 	o.acjjlA&r   c                @   < R pV P                  VR\        ./R7       R# )z0
            res = [super for x in [1]]
        res)r&   N)r0   rE   )r%   r   rF   s   & r   test_references_super+ListComprehensionTest.test_references_super   s&     	dUUG,<=r   c                8    R pV P                  V\        R7       R# )z4
            res = [__class__ for x in [1]]
        r)   Nr0   	NameErrorr%   r   s   & r   test_references___class__/ListComprehensionTest.test_references___class__   s     	d95r   c                n    R pV P                  VR^./RR.R7       V P                  V\        R.R7       R# )zN
            __class__ = 2
            res = [__class__ for x in [1]]
        r[   r   r	   )r&   r(   r   r)   r(   Nr`   rb   s   & r   !test_references___class___defined7ListComprehensionTest.test_references___class___defined   sH     	uqclHj3I 	 	Kd9gYGr   c                8    R pV P                  V\        R7       R# )z
            __class__ = 2
            class C:
                res = [__class__ for x in [1]]
            res = C.res
        r_   Nr`   rb   s   & r   #test_references___class___enclosing9ListComprehensionTest.test_references___class___enclosing   s     	d95r   c                8    R pV P                  V\        R7       R# )zO
            [super for _ in [1]]
            [__class__ for _ in [1]]
        r_   Nr`   rb   s   & r   *test_super_and_class_cell_in_sibling_comps@ListComprehensionTest.test_super_and_class_cell_in_sibling_comps   s     	d95r   c                <    R pR. ROR^/pV P                  W4       R# )zu
            items = [(lambda: i) for i in range(5)]
            i = 20
            y = [x() for x in items]
        r3   rJ   Nr>   r8   r9   s   &  r   test_inner_cell_shadows_outer3ListComprehensionTest.test_inner_cell_shadows_outer   s'    
 b1d,r   c                <    R pR^^.R^/pV P                  W4       R# )z
            def f(x):
                return [lambda: x for x in range(x)], x
            fns, x = f(2)
            y = [fn() for fn in fns]
        r3   rU   Nr8   r9   s   &  r   &test_inner_cell_shadows_outer_no_store<ListComprehensionTest.test_inner_cell_shadows_outer_no_store   s+     AQ'd,r   c                @    R pR. RO/pV P                  WRR.R7       R# )zt
            items = [(lambda: y) for i in range(5)]
            y = 2
            z = [x() for x in items]
        zr   r	   r(   N)r5   r5   r5   r5   r5   r8   r9   s   &  r   %test_closure_can_jump_over_comp_scope;ListComprehensionTest.test_closure_can_jump_over_comp_scope   s-    
 (dXz4JKr   c                >    R pR^./pV P                  WRR.R7       R# )z
            def f():
                return [lambda: x for x in (x, [1])[1]]
            x = ...
            y = [fn() for fn in f()]
        r3   r   r	   rw   Nr8   r9   s   &  r   test_cell_inner_free_outer0ListComprehensionTest.test_cell_inner_free_outer   s.     *dXz4JKr   c                p    R pR^./pV P                  WRR.R7       V P                  VR.\        R7       R# )zj
            g = 2
            def f():
                return g
            y = [g for x in [1]]
        r3   r   r	   rw   r   r(   r)   Nr`   r9   s   &  r   test_free_inner_cell_outer0ListComprehensionTest.test_free_inner_cell_outer   sE     *dXz4JKdG9YGr   c                <    R pR^
R. RO/pV P                  W4       R# )z
            y = 10
            items = [(lambda: y) for y in range(5)]
            x = y
            y = 20
            out = [z() for z in items]
        rU   outNr>   r8   r9   s   &  r   'test_inner_cell_shadows_outer_redefined=ListComprehensionTest.test_inner_cell_shadows_outer_redefined   s'     E?3d,r   c                <    R pRR/pV P                  WRR/R7       R# )zu
            def inner():
                return g
            [g for g in range(5)]
            x = inner()
        rU   gr'   Nr8   r9   s   &  r   test_shadows_outer_cell-ListComprehensionTest.test_shadows_outer_cell  s+     )db	:r   c                F    R pR^R^R^./pV P                  WR^/R7       R# )zy
            global g
            x = g
            g = 2
            items = [g for g in [1]]
            y = g
        rU   r3   r!   r   r   Nr8   r9   s   &  r   test_explicit_global*ListComprehensionTest.test_explicit_global  6     37QC0da9r   c                F    R pR^R^R^./pV P                  WR^/R7       R# )zy
            global g
            x = g
            g = 2
            items = [g for x in [1]]
            y = g
        rU   r3   r!   r   r   Nr8   r9   s   &  r   test_explicit_global_2,ListComprehensionTest.test_explicit_global_2  r   r   c                >    R pR^./pV P                  WR^/R7       R# )zr
            global g
            fns = [lambda: g for g in [2]]
            items = [fn() for fn in fns]
        r!   r   r   Nr8   r9   s   &  r   test_explicit_global_3,ListComprehensionTest.test_explicit_global_3#  s-    
 QC.da9r   c                <    R pR^/pV P                  WRR.R7       R# )zK
            x = -1
            items = [(x:=y) for y in range(3)]
        rU   r   r	   rw   Nr8   r9   s   &  r   test_assignment_expression0ListComprehensionTest.test_assignment_expression,  s,     (dXz4JKr   c                4    R pR^/pV P                  W4       R# )z
            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]()
        rU   Nr8   r9   s   &  r   test_free_var_in_comp_child1ListComprehensionTest.test_free_var_in_comp_child5  s"     (d,r   c                4    R pRR/pV P                  W4       R# )z
            lst = range(3)
            x = -1
            funcs = [lambda: x for x in lst]
            items = [x + 1 for x in lst]
        rU   Nr   r8   r9   s   &  r   test_shadow_with_free_and_local5ListComprehensionTest.test_shadow_with_free_and_local@  "     )d,r   c                6    R pR^./pV P                  W4       R# )z<
            x = [1]
            y = [x for x in x]
        rU   Nr8   r9   s   &  r   test_shadow_comp_iterable_name4ListComprehensionTest.test_shadow_comp_iterable_nameJ  s$     *d,r   c                <    R pR^/pV P                  WRR.R7       R# )z
            x = 1
            def g():
                [x for x in range(3)]
                return x
            g()
        rU   r   r	   rw   Nr8   r9   s   &  r   test_nested_free&ListComprehensionTest.test_nested_freeR  s,     (dXz4JKr   c                4    R pR^/pV P                  W4       R# )zz
            import sys
            [i for i in range(2)]
            i = 20
            sys._getframe().f_locals
        rJ   Nr8   r9   s   &  r   test_introspecting_frame_locals5ListComprehensionTest.test_introspecting_frame_locals]  r   r   c                @    R pR^ ^.. RO./pV P                  W4       R# )zX
            l = [2, 3]
            y = [[x ** 2 for x in range(x)] for x in l]
        r3   N)r   r4   r7   r8   r9   s   &  r   test_nested!ListComprehensionTest.test_nestedg  s,     !Q+,d,r   c                r    R pR. RO/pV P                  WRR.R7       V P                  VR.\        R7       R# )	zt
            l = [1, 2, 3]
            x = 3
            y = [x for [x ** x for x in range(x)][x - 1] in l]
        r3   r   r	   rw   r   r~   N)r6   r6   r6   r`   r9   s   &  r   test_nested_2#ListComprehensionTest.test_nested_2o  sD    
 	"dXz4JKdG9YGr   c                8    R pR. RO/pV P                  W4       R# )zv
            l = [(1, 2), (3, 4), (5, 6)]
            y = [x for (x, [x ** x for x in range(x)][x - 1]) in l]
        r3   N)r4   r6      r8   r9   s   &  r   test_nested_3#ListComprehensionTest.test_nested_3y  s#     	"d,r   c                R    R pR^^.^3^^.^3^^.^3./pV P                  W4       R# )z
            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   Nr8   r9   s   &  r   test_nested_4#ListComprehensionTest.test_nested_4  sB     QFA;!Qq!fa[ABd,r   c                8    R pV P                  V\        R7       R# )z4
            [x for x in [1]]
            x
        r_   Nr`   rb   s   & r   test_nameerror$ListComprehensionTest.test_nameerror  s    
 	d95r   c                6    R pR^./pV P                  W4       R# )z.
            y = [__x for __x in [1]]
        r3   Nr8   r9   s   &  r   test_dunder_name&ListComprehensionTest.test_dunder_name  s$     *d,r   c                    R  pV P                  \        4      ;_uu_ 4        V! 4        RRR4       R#   + '       g   i     R# ; i)c                  2     R U u. uF  q NK  	   p X # u up i )F)r4   r   )rU   s    r   fGListComprehensionTest.test_unbound_local_after_comprehension.<locals>.f  s!    1QH s   
NassertRaisesUnboundLocalErrorr%   r   s   & r   &test_unbound_local_after_comprehension<ListComprehensionTest.test_unbound_local_after_comprehension  s/    	 011C 2111	   3A	c                    R  pV P                  \        4      ;_uu_ 4        V! 4        RRR4       R#   + '       g   i     R# ; i)c                  H    R .p ^^.3 U u. uF  w  X ^ &   p ^NK  	  up # u up i r   r   )ls    r   r   HListComprehensionTest.test_unbound_local_inside_comprehension.<locals>.f  s/    A)*Ax0x)1Q4Ax000s   Nr   r   s   & r   'test_unbound_local_inside_comprehension=ListComprehensionTest.test_unbound_local_inside_comprehension  s/    	1 011C 2111r   c                r    R pV P                  VRR	/R^/RR.R7       V P                  V\        R.R7       R# )
z
            a = 1
            def f():
                func, = [(lambda: b) for b in [a]]
                return b, func()
            x = f()
        rU   br	   r   r'   r(   r   rf   N)r5   r4   r`   rb   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                r    R pV P                  VRR	/R^/RR.R7       V P                  V\        R.R7       R# )
z
            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()
        rU   r   r	   r   r   r   rf   N)r5   r5   r4   r`   rb   s   & r   !test_cell_in_nested_comprehension7ListComprehensionTest.test_cell_in_nested_comprehension  sO     	3	"QxX8N 	 	P 	d9gYGr   c                <    R pV P                  V\        R.R7       R# )zA
            y = 1
            [x + y for x in range(2)]
        r   rf   Nr`   rb   s   & r   test_name_error_in_class_scope4ListComprehensionTest.test_name_error_in_class_scope  s"     	d9gYGr   c                D    R pRRR./pV P                  WR^/R.R7       R# )zI
            y = 2
            vals = [(x, y) for x in range(2)]
        valsr3   r   r   Nr   r4   r4   r4   r8   r9   s   &  r   test_global_in_class_scope0ListComprehensionTest.test_global_in_class_scope  s5     FF+,da'Kr   c                D    R pRRR./pV P                  WR^/R.R7       R# )z
            class C:
                y = 2
                vals = [(x, y) for x in range(2)]
            vals = C.vals
        r   r3   r	   r   Nr   r   r8   r9   s   &  r   %test_in_class_scope_inside_function_1;ListComprehensionTest.test_in_class_scope_inside_function_1  s5     FF+,da*Nr   c                >    R pRRR./pV P                  WR.R7       R# )z
            y = 1
            class C:
                y = 2
                vals = [(x, y) for x in range(2)]
            vals = C.vals
        r   r	   rw   Nr   r   r8   r9   s   &  r   %test_in_class_scope_inside_function_2;ListComprehensionTest.test_in_class_scope_inside_function_2  s/     FF+,dZLAr   c                t    R pRRR./pV P                  WRR.R7       RR	R
./pV P                  WR.R7       R# )a;  
            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   r   rw   r	   Nr   r5   r4   r5   r   r   r8   r9   s   &  r   test_in_class_scope_with_global5ListComprehensionTest.test_in_class_scope_with_global  sV    
 FF+,dXw4GHFF+,dZLAr   c                >    R pRRR./pV P                  WR.R7       R# )a=  
            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	   rw   Nr   r   r8   r9   s   &  r   !test_in_class_scope_with_nonlocal7ListComprehensionTest.test_in_class_scope_with_nonlocal  s/    
 FF+,dZLAr   c                <    R pR^./pV P                  WR.R7       R# )zB
            items = [a for a in [1] if [a for _ in [0]]]
        r!   r   rw   Nr8   r9   s   &  r   test_nested_has_free_var.ListComprehensionTest.test_nested_has_free_var  s+     QC.dWI>r   c                p    R pV P                  VR^./RR.R7       V P                  VR. /R^ /R.R7       R# )	zY
            z = 1
            items = [a for a in [1] if [x for x in [1] if z]]
        r!   r   r	   rw   rv   r   r   Nr8   rb   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                4    R pV P                  VR^./4       R# )z]
            items = [_C for _C in [1] for [0, 1][[x for x in [1] if _C][0]] in [2]]
        r!   Nr8   rb   s   & r   test_nested_free_var_in_iter2ListComprehensionTest.test_nested_free_var_in_iter  s!     	dWqcN3r   c                @    R pV P                  VR^ . 3^^.3./4       R# )zM
            items = [(_C, [x for x in [1] if _C]) for _C in [0, 1]]
        r!   Nr8   rb   s   & r   test_nested_free_var_in_expr2ListComprehensionTest.test_nested_free_var_in_expr  s/     	dW2wQC.A$BCr   c                8    R pV P                  VR^RR./4       R# )z
            f = [(z, lambda y: [(x, y, z) for x in [3]]) for z in [1]]
            (z, func), = f
            out = func(2)
        rv   r   N)r6   r5   r4   r8   rb   s   & r   test_nested_listcomp_in_lambda4ListComprehensionTest.test_nested_listcomp_in_lambda#  s&    
 	dS!UYK$@Ar   c                6    R pV P                  VR^RR/4       R# )z
            (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
        cr/   Nr8   rb   s   & r   test_lambda_in_iter)ListComprehensionTest.test_lambda_in_iter+  s$     	dS!S$$78r   c                :    R pV P                  VR^./R.R7       R# )z*
            a = [1 for a in [0]]
        ar	   rw   Nr8   rb   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                    R pV P                  VRRR. /R.R7       V P                  VRRRR./R.R7       V P                  V\        R.R	7       R
# )z
            def b():
                [a for b in [1] for _ in []]
                return b, locals()
            r, s = b()
            x = r is b
            y = list(s.keys())
        rU   Tr3   r   rw   r   r	   r   rf   Nr`   rb   s   & r   test_no_leakage_to_locals/ListComprehensionTest.test_no_leakage_to_locals;  sd     	dS$R$8(LdS$cU$;ZLQd9gYGr   c                R    R pV P                  VR^^.R^^.RRR.R^^.R^ /4       R# )aJ  
            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]
        r!   items2items3Titems4r3   Nr8   rb   s   & r   !test_iter_var_available_in_locals7ListComprehensionTest.test_iter_var_available_in_localsH  sJ    	 	!Q1a&4,1a&Q		
r   c           	         R pVP                  RR7      pV P                  VRR.R^.RR/4       VP                  RR7      pV P                  VRR.RRRR./\        R	7       R# )
z
            value = ["ab"]
            result = snapshot = None
            try:
                result = [{func}(value) for value in value]
            except ValueError:
                snapshot = value
                raise
        lenfuncvalueabresultsnapshotNintr_   r   r0   
ValueErrorr%   templater   s   &  r   test_comp_in_try_except-ListComprehensionTest.test_comp_in_try_except^  sz     E*dWtfhZQU$VWE*dWtfhjSWRX$Y%/ 	 	1r   c           	         R pVP                  RR7      pV P                  VRR.R^.RR./4       VP                  RR7      pV P                  VRR.RRRR./\        R	7       R# )
z
            value = ["ab"]
            result = snapshot = None
            try:
                result = [{func}(value) for value in value]
            finally:
                snapshot = value
        r  r  r  r  r  r  r  Nr_   r  r  s   &  r   test_comp_in_try_finally.ListComprehensionTest.test_comp_in_try_finallyp  s}     E*dWtfhZRVQW$XYE*dWtfhjSWRX$Y%/ 	 	1r   c                6    R pV P                  VR^R./4       R# )z
            value = [1, None]
            try:
                [v for v in value].sort()
            except TypeError:
                pass
        r  Nr8   rb   s   & r    test_exception_in_post_comp_call6ListComprehensionTest.test_exception_in_post_comp_call  s$     	dWq$i$89r   c                v    R p^ RI pV P                  VRR/RV/R7       RpV P                  VR^ /RV/R7       R# )zM
            val = "a" in [sys._getframe().f_locals for a in [0]][0]
        NvalFsysr   zK
            val = [sys._getframe().f_locals["a"] for a in [0]][0]
        )r"  r0   )r%   r   r"  s   &  r   test_frame_locals'ListComprehensionTest.test_frame_locals  sQ     	dUENs|D 	dUAJE3<@r   c                   a  \        V\        P                  4      '       g   V# TP                  \        ;QJ d&    . V 3R  lVP
                   4       F  NK  	  5R7      # ! V 3R  lVP
                   4       4      R7      # )c              3   F   <"   T F  pSP                  V4      x  K  	  R # 5ir   )_recursive_replace).0r   r%   s   & r   	<genexpr>;ListComprehensionTest._recursive_replace.<locals>.<genexpr>  s#      2
0D1D##A&&0Ds   !)	co_consts)
isinstancetypesCodeTypereplacetupler+  )r%   
maybe_codes   f&r   r'  (ListComprehensionTest._recursive_replace  sp    *enn55!!EE 2
0:0D0D2
E!  	E 2
0:0D0D2
 -
!  	r   c                X    \        VR R4      pV P                  V4      p\        W24       R# )z<string>execN)compiler'  r4  )r%   code_stringr'   cos   &&& r   _replacing_exec%ListComprehensionTest._replacing_exec  s'    [*f5$$R(Rr   c                ~    R pV P                  VR^.R^/4       V P                  VR^.R^/V P                  R7       R# )za
            x = 3
            [x for x in (1, 2)]
            dir()
            y = [x]
        r3   rU   r*   N)r0   r8  rb   s   & r   test_code_replace'ListComprehensionTest.test_code_replace  sL     	dS1#sA$67dS1#sA$6$BVBVWr   c           	     |   R pRP                  R \        V4       4       4      pRP                  R \        V4       4       4      pR\        \        V4      4      /\        V4       Uu/ uF	  pRV 2VbK  	  upCpRV RV R	V R
V R2	pV P                  We4       V P                  WeV P                  R7       R# u upi )i,  z; c              3   2   "   T F  pR V RV 2x  K  	  R# 5i)rU   z = Nr   r(  rJ   s   & r   r)  GListComprehensionTest.test_code_replace_extended_arg.<locals>.<genexpr>  s     H7G!!A3c!7Gs   z, c              3   ,   "   T F
  pR V 2x  K  	  R# 5i)rU   Nr   r@  s   & r   r)  rA    s     @/?!!g/?s   r3   rU   z
            z
            [(z) for z6 in (range(300),)]
            dir()
            y = [z
]
        r;  N)joinrQ   listr0   r8  )r%   	num_namesassignments	name_listrJ   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   'B9c                    R pV P                  VR^./R^/R7       RpV P                  VR^R^./R^/R.R7       V P                  VR^R^./R^/RR.R7       R	# )
zG
            [x for x in [1]]
            y = [x for _ in [1]]
        r3   rU   r   zY
            x = 2
            [x for x in [1]]
            y = [x for _ in [1]]
        r   r   r	   r   Nr8   rb   s   & r   &test_multiple_comprehension_name_reuse<ListComprehensionTest.test_multiple_comprehension_name_reuse  s     	dS1#JC8<
 	dS!S1#$6C8WIVdS!S1#$6C8ZYaLbcr   c           	     ^   R  pR pR pVR3VR3VR33 F  w  rEV P                  V4      ;_uu_ 4        V! 4       p\        P                  ! VP                  4      ^ ,          p^pVP                  p	V P                  VP                  V	P                  ^,           4       V P                  VP                  V	P                  ^,           4       V P                  VP                  VP                  V,
          VP                  V,
           V4       RRR4       EK  	  R#   + '       g   i     EK  ; i)c                  z     \        R R7       U u. uF  q NK  	   p R# u up i   \         d   pTu Rp?# Rp?ii ; i)T)init_raisesNr   	ExceptionrU   r/   s     r   rP  CListComprehensionTest.test_exception_locations.<locals>.init_raises  8    &4898q899     # 
# # :5::c                  z     \        R R7       U u. uF  q NK  	   p R# u up i   \         d   pTu Rp?# Rp?ii ; i)T)next_raisesNrQ  rS  s     r   rX  CListComprehensionTest.test_exception_locations.<locals>.next_raises  rU  rV  c                  z     \        R R7       U u. uF  q NK  	   p R# u up i   \         d   pTu Rp?# Rp?ii ; i)T)iter_raisesNrQ  rS  s     r   r[  CListComprehensionTest.test_exception_locations.<locals>.iter_raises  rU  rV  zBrokenIter(init_raises=True)zBrokenIter(next_raises=True)zBrokenIter(iter_raises=True)N)r   	traceback
extract_tb__traceback____code__r"   linenoco_firstlineno
end_linenolinecolno	end_colno)
r%   rP  rX  r[  r  rH  excr   r   r7  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DD,c                   a  ! R  R4      o ! V3R lR4      pT P                  ^^.V! 4        Uu. uF  q"NK  	  up4       R# u upi )c                   ,   a  ] tR tRt o R tR tRtV tR# )HListComprehensionTest.test_only_calls_dunder_iter_once.<locals>.Iteratori  c                    ^ V n         R# )r   Nr!  r%   s   &r   __init__QListComprehensionTest.test_only_calls_dunder_iter_once.<locals>.Iterator.__init__  s	    r   c                z    V P                   ^8X  d   \        hV ;P                   ^,          un         V P                   # )r5   )r!  StopIterationro  s   &r   __next__QListComprehensionTest.test_only_calls_dunder_iter_once.<locals>.Iterator.__next__  s)    88q=''Axxr   rn  N)rM   rN   rO   rP   rp  rt  rR   rS   )rV   s   @r   Iteratorrl    s        r   rv  c                   .   <a  ] tR tRt o V3R ltRtV tR# )AListComprehensionTest.test_only_calls_dunder_iter_once.<locals>.Ci   c                   < S! 4       # r   r   )r%   rv  s   &r   __iter__JListComprehensionTest.test_only_calls_dunder_iter_once.<locals>.C.__iter__  s    z!r   r   N)rM   rN   rO   rP   rz  rR   rS   )rV   rv  s   @r   rW   rx     s     " "r   rW   N)r"   )r%   rW   rJ   rv  s   &  @r    test_only_calls_dunder_iter_once6ListComprehensionTest.test_only_calls_dunder_iter_once  sA    		  		 	" 	"
 	!QQS!1S!S!12!1s   
A
r   )ErM   rN   rO   rP   r4  r0   r:   r?   rX   r\   rc   rg   rj   rm   rp   rs   rx   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'  r8  r<  rI  rL  rh  r|  rR   rS   rT   )rF   rV   s   @@r   r   r   b   sc    -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"+H3 3r   r   doctestsc                 N    VP                  \        P                  ! 4       4       V# r   )addTestdoctestDocTestSuite)loadertestspatterns   &&&r   
load_testsr  	  s    	MM'&&()Lr   __main__)r  r   r]  r-  unittesttest.supportr   r~  TestCaser   __test__r  rM   mainr   r   r   <module>r     s^         #Upc
3H-- c
3J "
 zMMO r   