
    dafLA                        d dl Z d dlZd dlZd dlmZ d dlmZ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(                          yy)    N)import_helper)spawn_pythonkill_python)dedentz\((\S+).py, line (\d+)c                 b    t         j                  t        |             }|j                  dd      S )N      )rxsearchstrgroup)msgmos     </root/Python-3.12.4/Lib/test/test_future_stmt/test_future.pyget_error_locationr      s$    	3s8	B88Aq>    c                   t    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 Zy)
FutureTestc                 ,   | j                  d||fz  t        |             | j                  t        j                  j                  |j                        |dz          | j                  |j                  |       | j                  |j                  |       y )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   so    &(F);;SXF))#,,7E9IJV,V,r   c                     t        j                  d      5  ddlm} | j	                  |j
                  d       d d d        y # 1 sw Y   y xY w)Nz"test.test_future_stmt.future_test1r   )future_test1   )r   CleanImporttest.test_future_stmtr"   r   result)r   r"   s     r   test_future1zFutureTest.test_future1   ?    &&'KL 	5:\00!4	5 	5 	5   #AAc                     t        j                  d      5  ddlm} | j	                  |j
                  d       d d d        y # 1 sw Y   y xY w)Nz"test.test_future_stmt.future_test2r   )future_test2r#   )r   r$   r%   r+   r   r&   )r   r+   s     r   test_future2zFutureTest.test_future2    r(   r)   c                 d    t        j                  d      5  ddlm} d d d        y # 1 sw Y   y xY w)Nz/test.test_future_stmt.test_future_single_importr   )test_future_single_import)r   r$   r%   r.   )r   r.   s     r   r.   z$FutureTest.test_future_single_import%   s2    &&=
 	H H	H 	H 	H   &/c                 d    t        j                  d      5  ddlm} d d d        y # 1 sw Y   y xY w)Nz2test.test_future_stmt.test_future_multiple_importsr   )test_future_multiple_imports)r   r$   r%   r1   )r   r1   s     r   r1   z'FutureTest.test_future_multiple_imports+   s2    &&@
 	K K	K 	K 	Kr/   c                 d    t        j                  d      5  ddlm} d d d        y # 1 sw Y   y xY w)Nz3test.test_future_stmt.test_future_multiple_featuresr   )test_future_multiple_features)r   r$   r%   r3   )r   r3   s     r   r3   z(FutureTest.test_future_multiple_features1   s2    &&A
 	L L	L 	L 	Lr/   c                     | j                  t              5 }ddlm} d d d        | j	                  j
                  dd       y # 1 sw Y   'xY w)Nr   )badsyntax_future3r5      )assertRaisesSyntaxErrorr%   r5   r    	exception)r   cmr5   s      r   test_badfuture3zFutureTest.test_badfuture37   E    {+ 	@r?	@.A1E	@ 	@   AAc                     | j                  t              5 }ddlm} d d d        | j	                  j
                  dd       y # 1 sw Y   'xY w)Nr   )badsyntax_future4r?   r6   )r7   r8   r%   r?   r    r9   )r   r:   r?   s      r   test_badfuture4zFutureTest.test_badfuture4<   r<   r=   c                     | j                  t              5 }ddlm} d d d        | j	                  j
                  dd       y # 1 sw Y   'xY w)Nr   )badsyntax_future5rB      )r7   r8   r%   rB   r    r9   )r   r:   rB   s      r   test_badfuture5zFutureTest.test_badfuture5A   r<   r=   c                     | j                  t              5 }ddlm} d d d        | j	                  j
                  dd       y # 1 sw Y   'xY w)Nr   )badsyntax_future6rF   r6   )r7   r8   r%   rF   r    r9   )r   r:   rF   s      r   test_badfuture6zFutureTest.test_badfuture6F   r<   r=   c                     | j                  t              5 }ddlm} d d d        | j	                  j
                  ddd       y # 1 sw Y   (xY w)Nr   )badsyntax_future7rI   r6   6   )r7   r8   r%   rI   r    r9   )r   r:   rI   s      r   test_badfuture7zFutureTest.test_badfuture7K   sG    {+ 	@r?	@.A1bI	@ 	@s   AAc                     | j                  t              5 }ddlm} d d d        | j	                  j
                  dd       y # 1 sw Y   'xY w)Nr   )badsyntax_future8rM   r6   )r7   r8   r%   rM   r    r9   )r   r:   rM   s      r   test_badfuture8zFutureTest.test_badfuture8P   r<   r=   c                     | j                  t              5 }ddlm} d d d        | j	                  j
                  dd       y # 1 sw Y   'xY w)Nr   )badsyntax_future9rP   r6   )r7   r8   r%   rP   r    r9   )r   r:   rP   s      r   test_badfuture9zFutureTest.test_badfuture9U   r<   r=   c                     | j                  t              5 }ddlm} d d d        | j	                  j
                  dd       y # 1 sw Y   'xY w)Nr   )badsyntax_future10rS   r6   )r7   r8   r%   rS   r    r9   )r   r:   rS   s      r   test_badfuture10zFutureTest.test_badfuture10Z   sE    {+ 	Ar@	A.BAF	A 	Ar=   c           	         t         j                  D ci c].  }d|j                          t        t         |      j                  0 }}|t        t              D ci c]$  }|j                  d      r|t        t        |      & c}z  }| j                  t        |j                               |j                                y c c}w c c}w )N
CO_FUTURE_PyCF_)
__future__all_feature_namesuppergetattrcompiler_flagdirast
startswithassertCountEqualsetvalues)r   futureflagsflags       r   test_ensure_flags_dont_clashz'FutureTest.test_ensure_flags_dont_clash_   s     %66
 ()7:v+F+T+TT
 

 	C
DOOG$< '#t$$
 	
 	c%,,.15<<>B


s   3C )Cc                 T    i }t        di |       | j                  |d   t               y )Nz/from __future__ import unicode_literals; x = ''x)execassertIsInstancer   )r   scopes     r   test_unicode_literals_execz%FutureTest.test_unicode_literals_execn   s(    >EJeCj#.r   c                     t        d      }|j                  j                  d       |j                  j                  d       t        |      }| j	                  d|       y )Nz-is&   from __future__ import barry_as_FLUFL
s   2 <> 3
s   SyntaxError: invalid syntax)r   stdinwriter   assertNotIn)r   pouts      r   test_syntactical_future_replz'FutureTest.test_syntactical_future_repls   sG    	@A	k"!n7=r   N)r   )__name__
__module____qualname__r    r'   r,   r.   r1   r3   r;   r@   rD   rG   rK   rN   rQ   rT   rf   rl   rs    r   r   r   r      sc    -5
5
HKLF
F
F
F
J
F
F
G
C/
>r   r   c                   \    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y)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                  j                  |      i |       |d   j                  d   }|d   j                  d   }|d   j                  d   }|d   j                  d   }|d   d	   }|d   d
   }| j	                  ||       | j	                  ||       | j	                  ||       | j	                  ||       | j	                  ||       |S )N)annfreturngargf2g2__annotations__varvar2)ri   templateformatr   r   )	r   
annotationrk   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!12u=Sz11(;Sz11%8"4[88B"4[88?*+E2*+F3|4'9:'9:x0x0r   Nc                     | j                  |      }|	|s|n|dd }|r4| j                  ||       |j                  dd      j                  dd      }| j                  ||       y )Nr   ( ))r   assertNotEqualreplacer   )r   r   expecteddrop_parensis_tupleactuals         r   assertAnnotationEqualz/AnnotationsFutureTestCase.assertAnnotationEqual   sh     
+)1zz!B7GH1^^C,44S"=F*r   c                 (    i }t        d|z   |       |S )Nz#from __future__ import annotations
)ri   )r   coderk   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       y )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
./


 
9
9
>
/0
;
?
8
8
9
4
./
=
>


#$
:;
FG
IJ


"#
&'
$%
01
23
01
KL
UV
./
&'

AB
HI
/0
-.
89
MN

PQ
>
LM
4
6

8
;
>
4
CD
>
#$
()
@A
?@
#$
()
@A
?@
#$
()
@A
?@
&'
>?
()
"#
&'
>
8
;

#$
34
CD


9
:
?
;

;
;

 
()
./
34
:
<
>
:
<
;
=
;
=
?
?

; 	=
?
?


 
 
 
"#


!"
!"
"#
PQ
BC
)*
GH
-.
GH
 
./
8
:
:
)*
./

!"
!"
9c
<"
;r   c                     | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd	       | j                  d
d       y )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   r   s    r   test_fstring_debug_annotationsz8AnnotationsFutureTestCase.test_fstring_debug_annotationsW  sx     	"";"F"":"D""=>"J"";"F"";"F""#3>O"Pr   c                    dt        t        j                  j                  dz         z   }| d}| j	                  d|       | j	                  d|       | j	                  dd|        | j	                  d	d
|        | j	                  dd| d| d       | j	                  d       | j	                  dd| d| d       | j	                  dd| d| d       y )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_numbersa  s   T#..33a788ay""8c":""9t"<""93%y"A"";4v"G""#61SED6QRAS"T""7+""#GT\]`\aamnrmsstRu"v""#9auCPTvUXDY"Zr   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Nz8from __future__ import annotations
object.__debug__: int)r7   r8   ri   r   s    r   #test_annotation_with_complex_targetz=AnnotationsFutureTestCase.test_annotation_with_complex_targetm  s2    {+ 	(	 	 	s   +4c                 <   | j                  t        d            }|j                  d      }| j                   |       j                         | j                  |j                  j                  d       | j                   |       j                  j                  d       y )Nz
        from __future__ import annotations

        def foo():
            outer = 1
            def bar():
                inner: outer = 1
            return bar
        foorw   )	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_passt  sz    %%f . ' 	 mmE"#%++,112633R8r   c                 F   | j                  t              5  | j                  d       d d d        | j                  t              5  | j                  d       d d d        | j                  t              5  | j                  d       d d d        | j                  t              5  | j                  d       d d d        | j                  t              5  | j                  d       d d d        | j                  t              5  | j                  d       d d d        | j                  t              5  | j                  d       d d d        | j                  t              5  | j                  d       d d d        | j                  t              5  | j                  t        d	             d d d        y # 1 sw Y   xY w# 1 sw Y   jxY w# 1 sw Y   HxY w# 1 sw Y   &xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)
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
            )r7   r8   r   r   r   s    r   test_annotations_forbiddenz4AnnotationsFutureTestCase.test_annotations_forbidden  s   {+ 	/o.	/ {+ 	:89	: {+ 	A?@	A {+ 	YWX	Y {+ 	?=>	? {+ 	OMN	O {+ 	dbc	d {+ 	:89	: {+ 	f &  	 	1	/ 	/	: 	:	A 	A	Y 	Y	? 	?	O 	O	d 	d	: 	:	 	sk   F2F?4G#GG&G30G?HH2F<?G	GG#&G03G<?HHH c                     | j                  t        d            }|j                  d      }| j                  |d   |d          y )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   rj   )r   r   r   s      r   -test_get_type_hints_on_func_with_variadic_argzGAnnotationsFutureTestCase.test_get_type_hints_on_func_with_variadic_arg  sI    
 %%f 	. 	' 		 g&eFmYz-BCr   )NFF)rt   ru   rv   r   r   r   r   r   r   r   r   r   r   r   r   rw   r   r   ry   ry   z   sO    	H(" FK
+bHQ
[9 >Dr   ry   __main__)rX   r^   unittesttest.supportr   test.support.script_helperr   r   textwrapr   r   rer   compiler
   r   TestCaser   ry   rt   mainrw   r   r   <module>r      s~     
  & @  	 	 
RZZ)*e>"" e>NzD 1 1 zDz	 zHMMO r   