
    <e@                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	Z	d dl
Z
d dlZ e
j        d          Zd Z G d dej                  Z G d	 d
ej                  Zedk    r ej                     dS dS )    N)support)import_helper)dedentz\((\S+).py, line (\d+)c                 |    t                               t          |                     }|                    dd          S )N      )rxsearchstrgroup)msgmos     '/usr/lib/python3.11/test/test_future.pyget_error_locationr      s+    	3s88		B88Aq>>    c                   p    e Zd Zd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S )
FutureTestr   c                 8   |                      d||fz  t          |                     |                     t          j                            |j                  |dz              |                     |j        |           |                     |j        |           d S )Nz%s.py, line %dz.py)	assertInr   assertEqualospathbasenamefilenamelinenooffset)selferrr   r   r   s        r   check_syntax_errorzFutureTest.check_syntax_error   s    &(F);;SXXFFF))#,77E9IJJJV,,,V,,,,,r   c                     t          j        d          5  ddlm} |                     |j        d           d d d            d S # 1 swxY w Y   d S )Nfuture_test1r   )r!      )r   CleanImporttestr!   r   result)r   r!   s     r   test_future1zFutureTest.test_future1       &~66 	5 	5))))))\0!444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5   "AAAc                     t          j        d          5  ddlm} |                     |j        d           d d d            d S # 1 swxY w Y   d S )Nfuture_test2r   )r*   r"   )r   r#   r$   r*   r   r%   )r   r*   s     r   test_future2zFutureTest.test_future2    r'   r(   c                 l    t          j        d          5  ddlm} d d d            d S # 1 swxY w Y   d S )Ntest_future3r   )r-   )r   r#   r$   r-   )r   r-   s     r   r-   zFutureTest.test_future3%   s    &~66 	* 	*))))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*   )--c                     |                      t                    5 }ddlm} d d d            n# 1 swxY w Y   |                     |j        dd           d S )Nr   )badsyntax_future3r0      )assertRaisesSyntaxErrorr$   r0   r   	exception)r   cmr0   s      r   test_badfuture3zFutureTest.test_badfuture3)       {++ 	/r......	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/.A1EEEEE   .22c                     |                      t                    5 }ddlm} d d d            n# 1 swxY w Y   |                     |j        dd           d S )Nr   )badsyntax_future4r:   r1   )r2   r3   r$   r:   r   r4   )r   r5   r:   s      r   test_badfuture4zFutureTest.test_badfuture4.   r7   r8   c                     |                      t                    5 }ddlm} d d d            n# 1 swxY w Y   |                     |j        dd           d S )Nr   )badsyntax_future5r=      )r2   r3   r$   r=   r   r4   )r   r5   r=   s      r   test_badfuture5zFutureTest.test_badfuture53   r7   r8   c                     |                      t                    5 }ddlm} d d d            n# 1 swxY w Y   |                     |j        dd           d S )Nr   )badsyntax_future6rA   r1   )r2   r3   r$   rA   r   r4   )r   r5   rA   s      r   test_badfuture6zFutureTest.test_badfuture68   r7   r8   c                     |                      t                    5 }ddlm} d d d            n# 1 swxY w Y   |                     |j        ddd           d S )Nr   )badsyntax_future7rD   r1   5   )r2   r3   r$   rD   r   r4   )r   r5   rD   s      r   test_badfuture7zFutureTest.test_badfuture7=   s    {++ 	/r......	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/.A1bIIIIIr8   c                     |                      t                    5 }ddlm} d d d            n# 1 swxY w Y   |                     |j        dd           d S )Nr   )badsyntax_future8rH   r1   )r2   r3   r$   rH   r   r4   )r   r5   rH   s      r   test_badfuture8zFutureTest.test_badfuture8B   r7   r8   c                     |                      t                    5 }ddlm} d d d            n# 1 swxY w Y   |                     |j        dd           d S )Nr   )badsyntax_future9rK   r1   )r2   r3   r$   rK   r   r4   )r   r5   rK   s      r   test_badfuture9zFutureTest.test_badfuture9G   r7   r8   c                     |                      t                    5 }ddlm} d d d            n# 1 swxY w Y   |                     |j        dd           d S )Nr   )badsyntax_future10rN   r1   )r2   r3   r$   rN   r   r4   )r   r5   rN   s      r   test_badfuture10zFutureTest.test_badfuture10L   s    {++ 	0r//////	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0.BAFFFFFr8   c                    d t           j        D             }|d t          t                    D             z  }|                     t          |                                          |                                           d S )Nc                 n    i | ]2}d |                                  t          t          |          j        3S )
CO_FUTURE_)uppergetattr
__future__compiler_flag).0futures     r   
<dictcomp>z;FutureTest.test_ensure_flags_dont_clash.<locals>.<dictcomp>U   sG     
 
 
 *))7:v+F+F+T
 
 
r   c                 d    i | ]-}|                     d           |t          t          |          .S )PyCF_)
startswithrT   ast)rW   flags     r   rY   z;FutureTest.test_ensure_flags_dont_clash.<locals>.<dictcomp>Z   sE     
 
 
DOOG$<$<
'#t$$
 
 
r   )rU   all_feature_namesdirr]   assertCountEqualsetvalues)r   flagss     r   test_ensure_flags_dont_clashz'FutureTest.test_ensure_flags_dont_clashQ   s    
 
$6
 
 

 	 
 
C
 
 
 	
 	c%,,..115<<>>BBBBBr   c                     	 t          d           |                     d           n# t          $ r Y nw xY w	 t          d           |                     d           d S # t          $ r Y d S w xY w)Nz.from __future__ import print_function; print 0zsyntax error didn't occurz0from __future__ import (print_function); print 0)execfailr3   r   s    r   test_parserhackzFutureTest.test_parserhack`   s    	3ABBB II12222  	 	 	D	
	3CDDD II122222  	 	 	DD	s   ' 
44A 
A,+A,c                 l    t          j        d          5  ddlm} d d d            d S # 1 swxY w Y   d S )Nztest.test_future5r   )test_future5)r   r#   r$   rl   )r   rl   s     r   test_multiple_featuresz!FutureTest.test_multiple_featurest   s    &':;; 	* 	*))))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*r.   c                 n    i }t          di |           |                     |d         t                     d S )Nz/from __future__ import unicode_literals; x = ''x)rg   assertIsInstancer   )r   scopes     r   test_unicode_literals_execz%FutureTest.test_unicode_literals_execx   s:    >EJJJeCj#.....r   N)r   )__name__
__module____qualname__r   r&   r+   r-   r6   r;   r?   rB   rF   rI   rL   rO   re   rj   rm   rr    r   r   r   r      s$       - - - -5 5 5
5 5 5
* * *F F F
F F F
F F F
F F F
J J J
F F F
F F F
G G G
C C C3 3 3(* * */ / / / /r   r   c                   d    e Zd Z ed          Zd Z	 ddZd Zd Zd Z	d	 Z
d
 Zd Zd Zd ZdS )AnnotationsFutureTestCasea  
        from __future__ import annotations
        def f() -> {ann}:
            ...
        def g(arg: {ann}) -> None:
            ...
        async def f2() -> {ann}:
            ...
        async def g2(arg: {ann}) -> None:
            ...
        class H:
            var: {ann}
            object.attr: {ann}
        var: {ann}
        var2: {ann} = None
        object.attr: {ann}
        c                 
   i }t          | j                            |          i |           |d         j        d         }|d         j        d         }|d         j        d         }|d         j        d         }|d         d	         }|d         d
         }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |S )N)annfreturngargf2g2__annotations__varvar2)rg   templateformatr   r   )	r   
annotationrq   func_ret_annfunc_arg_annasync_func_ret_annasync_func_arg_annvar_ann1var_ann2s	            r   	getActualz#AnnotationsFutureTestCase.getActual   s   T]!!j!112u===Sz1(;Sz1%8"4[8B"4[8?*+E2*+F3|444'9:::'9:::x000x000r   NFc                     |                      |          }||s|n	|dd         }|r@|                     ||           |                    dd                              dd          }|                     ||           d S )Nr   ( ))r   assertNotEqualreplacer   )r   r   expecteddrop_parensis_tupleactuals         r   assertAnnotationEqualz/AnnotationsFutureTestCase.assertAnnotationEqual   s     
++)1Gzzz!B$7GH 	>111^^C,,44S"==F*****r   c                 0    i }t          d|z   |           |S )Nz#from __future__ import annotations
)rg   )r   coderq   s      r   _exec_futurez&AnnotationsFutureTestCase._exec_future   s.    2	
 	
 	
 r   c                    | j         } |d            |d            |d            |d            |d            |d            |d            |d            |d	            |d
            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d             |d!            |d"            |d#            |d$            |d%            |d&            |d'            |d(            |d)            |d*            |d+            |d,            |d-            |d.            |d/            |d0            |d1            |d2            |d3            |d4            |d5            |d6            |d7            |d8            |d9            |d:            |d;            |d<            |d=            |d>            |d?            |d@            |dA            |dB            |dC            |dD            |dE            |dF            |dG            |dH            |dI            |dJ            |dK            |dL            |dM            |dN            |dO            |dP            |dQ            |dR            |dS            |dT            |dU            |dV            |dW            |dX            |dY            |dZ            |d[            |d\            |d]            |d^            |d_            |d`            |da            |db            |dc            |dd            |de            |df            |dg            |dh            |di            |dj            |dk            |dl            |dm            |dn            |do            |dp            |dq            |dr            |ds            |dt            |du            |dv            |dw            |dx            |dy            |dz            |d{            |d|            |d}            |d~            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |d            |dd            |ddE            |d           d S )Nz...z'some_string'zu'some_string'zb'\xa3'NameNoneTrueFalse1z1.01jzTrue or FalsezTrue or False or NonezTrue and FalsezTrue and False and NonezName1 and Name2 or Name3zName1 and (Name2 or Name3)zName1 or Name2 and Name3z(Name1 or Name2) and Name3z"Name1 and Name2 or Name3 and Name4z!Name1 or Name2 and Name3 or Name4za + b + (c + d)za * b * (c * d)z(a ** b) ** c ** dzv1 << 2z1 >> v2z1 % finishedz"1 + v2 - v3 * 4 ^ 5 ** v6 / 7 // 8z	not greatznot not greatz~greatz+valuez++valuez-1z!~int and not v1 ^ 123 + v2 | Trueza + (not b)zlambda: Nonezlambda arg: Nonezlambda a=True: azlambda a, b, c=True: az-lambda a, b, c=True, *, d=1 << v2, e='str': az9lambda a, b, c=True, *vararg, d, e='str', **kwargs: a + bz<lambda a, /, b, c=True, *vararg, d, e='str', **kwargs: a + bzlambda x, /: xzlambda x=1, /: xzlambda x, /, y: x + yzlambda x=1, /, y=2: x + yzlambda x, /, y=1: x + yz#lambda x, /, y=1, *, z=3: x + y + zz%lambda x=1, /, y=2, *, z=3: x + y + zz#lambda x=1, /, y=2, *, z: x + y + zz>lambda x=1, y=2, z=3, /, w=4, *, l, l2: x + y + z + w + l + l2zHlambda x=1, y=2, z=3, /, w=4, *, l, l2, **kwargs: x + y + z + w + l + l2z!lambda x, /, y=1, *, z: x + y + zzlambda x: lambda y: x + yz1 if True else 2z4str or None if int or True else str or bytes or Nonez;str or None if (1 if True else 2) else str or bytes or Nonez"0 if not x else 1 if x > 0 else -1z (1 if x > 0 else -1) if x else 0z+{'2.7': dead, '3.7': long_live or die_hard}z@{'2.7': dead, '3.7': long_live or die_hard, **{'3.6': verygood}}z{**a, **b, **c}zC{'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'}z{*a, *b, *c}z?({'a': 'b'}, True or False, +value, 'string', b'bytes') or Nonez()z(a,)z(a, b)z	(a, b, c)z(*a, *b, *c)z[]z6[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]z[*a, *b, *c]z{i for i in (1, 2, 3)}z{i ** 2 for i in (1, 2, 3)}z3{i ** 2 for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))}z2{i ** 2 + j for i in (1, 2, 3) for j in (1, 2, 3)}z[i for i in (1, 2, 3)]z[i ** 2 for i in (1, 2, 3)]z3[i ** 2 for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))]z2[i ** 2 + j for i in (1, 2, 3) for j in (1, 2, 3)]z(i for i in (1, 2, 3))z(i ** 2 for i in (1, 2, 3))z3(i ** 2 for i, _ in ((1, 'a'), (2, 'b'), (3, 'c')))z2(i ** 2 + j for i in (1, 2, 3) for j in (1, 2, 3))z{i: 0 for i in (1, 2, 3)}z1{i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))}z[(x, y) for x, y in (a, b)]z[(x,) for x, in (a,)]zPython3 > Python2 > COBOLzLife is Lifezcall()z	call(arg)zcall(kwarg='hey')zcall(arg, kwarg='hey')z&call(arg, *args, another, kwarg='hey')z6call(arg, another, kwarg='hey', **kwargs, kwarg2='ho')zlukasz.langa.plzcall.me(maybe)z1 .realz1.0.realz....__class__z	list[str]zdict[str, int]z	set[str,]z	tuple[()]ztuple[str, ...]ztuple[str, *types]ztuple[str, int, (str, int)]z!tuple[*int, str, str, (str, int)]z&tuple[str, int, float, dict[str, int]]zslice[0]z
slice[0:1]zslice[0:1:2]zslice[:]z
slice[:-1]z	slice[1:]zslice[::-1]z	slice[:,]zslice[1:2,]zslice[1:2:3,]zslice[1:2, 1]zslice[1:2, 2, 3]z	slice[()]zslice[*Ts,]zslice[1, *Ts]zslice[*Ts, 2]zslice[1, *Ts, 2]zslice[*Ts, *Ts]zslice[1, *Ts, *Ts]zslice[*Ts, 1, *Ts]zslice[*Ts, *Ts, 1]zslice[1, *Ts, *Ts, 2]zslice[1:2, *Ts]zslice[*Ts, 1:2]zslice[1:2, *Ts, 3:4]zslice[a, b:c, d:e:f]zslice[(x for x in a)]zCstr or None if sys.version_info[0] > (3,) else str or bytes or Nonez5f'f-string without formatted values is just a string'zf'{{NOT a formatted value}}'z:f'some f-string with {a} {few():.2f} {formatted.values!r}'zf"{f'{nested} inner'} outer"z:f'space between opening braces: { {a for a in (1, 2, 3)}}'zf'{(lambda x: x)}'z!f'{(None if a else lambda x: x)}'zf'{x}'zf'{x!r}'zf'{x!a}'z[x for x in (a if b else c)]z![x for x in a if (b if c else d)]zf(x for x in a)zf(1, (x for x in a))zf((x for x in a), 2)z(((a)))az
(((a, b)))z	1 + 2 + 3r   )r   eqs     r   test_annotationsz*AnnotationsFutureTestCase.test_annotations   s	   '
5			
?

:
6



6



6



7
3
5			
4
?
"###

$%%%
%&&&
'(((
%&&&
'(((
/000
.///


   
9
9
>
/000
;
?
8
8
9
4
.///
=
>


#$$$
:;;;
FGGG
IJJJ


"###
&'''
$%%%
0111
2333
0111
KLLL
UVVV
.///
&'''

ABBB
HIII
/000
-...
8999
MNNN

PQQQ
>
LMMM
4
6



8
;
>
4
CDDD
>
#$$$
()))
@AAA
?@@@
#$$$
()))
@AAA
?@@@
#$$$
()))
@AAA
?@@@
&'''
>???
()))
"###
&'''
>
8
;

#$$$
3444
CDDD


9
:
?
;

;
;

   
()))
.///
3444
:
<
>
:
<
;
=
;
=
?
?

; 	=
?
?


   
   
   
"###


!"""
!"""
"###
PQQQ
BCCC
)***
GHHH
-...
GHHH
   
.///
8
:
:
)***
.///

!"""
!"""
9c
<"""
;r   c                    |                      dd           |                      dd           |                      dd           |                      dd           |                      dd	           |                      d
d           d S )Nz	f'{x=!r}'z
f'x={x!r}'r   zf'{x=:}'z	f'x={x:}'zf'{x=:.2f}'zf'x={x:.2f}'z	f'{x=!a}'z
f'x={x!a}'zf'{x=!s:*^20}'zf'x={x!s:*^20}'r   ri   s    r   test_fstring_debug_annotationsz8AnnotationsFutureTestCase.test_fstring_debug_annotationsZ  s     	"";"FFF"":"DDD""=>"JJJ"";"FFF"";"FFF""#3>O"PPPPPr   c                    dt          t          j        j        dz             z   }| d}|                     d|           |                     d|           |                     dd|            |                     d	d
|            |                     dd| d| d           |                     d           |                     dd| d| d           |                     dd| d| d           d S )N1er   j1e1000r   1e1000jz-1e1000-z	3+1e1000jz3 + z(1e1000, 1e1000j)r   z, r   z'inf'z"('inf', 1e1000, 'infxxx', 1e1000j)z('inf', z, 'infxxx', z(1e1000, (1e1000j,))z, (z,)))reprsys
float_info
max_10_expr   )r   infinfjs      r   test_infinity_numbersz/AnnotationsFutureTestCase.test_infinity_numbersd  s@   T#.3a7888yyy""8c":::""9t"<<<""9y3yy"AAA"";"GGG""#6ASSASASDASASAS"TTT""7+++""#GRu]`RuRunrRuRuRu"vvv""#9DYDYDYPTDYDYDY"ZZZZZr   c                     |                      t                    5  t          d           d d d            d S # 1 swxY w Y   d S )Nz8from __future__ import annotations
object.__debug__: int)r2   r3   rg   ri   s    r   #test_annotation_with_complex_targetz=AnnotationsFutureTestCase.test_annotation_with_complex_targetp  s    {++ 	 	(  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   8<<c                 H   |                      t          d                    }|                    d          }|                      |            j                   |                     |j        j        d           |                      |            j        j        d           d S )Nz
        from __future__ import annotations

        def foo():
            outer = 1
            def bar():
                inner: outer = 1
            return bar
        foorv   )	r   r   popassertIsNone__closure__r   __code__co_cellvarsco_freevars)r   	namespacer   s      r   "test_annotations_symbol_table_passz<AnnotationsFutureTestCase.test_annotations_symbol_table_passw  s    %%f . ' '  	 mmE""##%%+,,,126663R88888r   c                     |                      t                    5  |                     d           d d d            n# 1 swxY w Y   |                      t                    5  |                     d           d d d            n# 1 swxY w Y   |                      t                    5  |                     d           d d d            n# 1 swxY w Y   |                      t                    5  |                     d           d d d            n# 1 swxY w Y   |                      t                    5  |                     d           d d d            n# 1 swxY w Y   |                      t                    5  |                     d           d d d            n# 1 swxY w Y   |                      t                    5  |                     d           d d d            n# 1 swxY w Y   |                      t                    5  |                     d           d d d            n# 1 swxY w Y   |                      t                    5  |                     t          d	                     d d d            d S # 1 swxY w Y   d S )
Nztest: (yield)ztest.test: (yield a + b)ztest[something]: (yield from x)z7def func(test: (yield from outside_of_generator)): passzdef test() -> (await y): passz-async def test() -> something((a := b)): passzBtest: await some.complicated[0].call(with_args=True or 1 is not 1)ztest: f'{(x := 10):=10}'zO            def foo():
                def bar(arg: (yield)): pass
            )r2   r3   r   r   ri   s    r   test_annotations_forbiddenz4AnnotationsFutureTestCase.test_annotations_forbidden  s   {++ 	/ 	/o...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ {++ 	: 	:8999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: {++ 	A 	A?@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A {++ 	Y 	YWXXX	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y {++ 	? 	?=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? {++ 	O 	OMNNN	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O {++ 	d 	dbccc	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d {++ 	: 	:8999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: {++ 	 	f &     	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   =AA"BBB)CCC0DDD7EE E>F  F$'F$G''G+.G+H..H25H2#JJ
Jc                     |                      t          d                    }|                    d          }|                     |d         |d                    d S )Nz        class StarredC: pass
        class C:
          def __iter__(self):
            yield StarredC()
        c = C()
        def f(*args: *c): pass
        import typing
        hints = typing.get_type_hints(f)
        hintsargsStarredC)r   r   r   rp   )r   r   r   s      r   -test_get_type_hints_on_func_with_variadic_argzGAnnotationsFutureTestCase.test_get_type_hints_on_func_with_variadic_arg  sb    
 %%f 	. 	' 	' 	 		 g&&eFmYz-BCCCCCr   )NFF)rs   rt   ru   r   r   r   r   r   r   r   r   r   r   r   r   rv   r   r   rx   rx   }   s        v	 H(  " FK
+ 
+ 
+ 
+  b b bHQ Q Q
[ 
[ 
[  9 9 9   >D D D D Dr   rx   __main__)rU   r]   unittestr$   r   test.supportr   textwrapr   r   rer   compiler	   r   TestCaser   rx   rs   mainrv   r   r   <module>r      s1       



        & & & & & &       				 				 



RZ)**  h/ h/ h/ h/ h/" h/ h/ h/TzD zD zD zD zD 1 zD zD zDz	 zHMOOOOO r   