o
    HXh                     @   s   U 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d dlZd dlT d dl	m
Z
 d dlZd dlmZ d dlmZ d dlZg dZg d	ZG d
d dejZeed< G dd dZG dd dejZedkrpe  dS dS )    check_syntax_error)import_helpercheck_syntax_warningN)*)ChainMap)ann_module2)Z0_0_0Z4_2Z1_0000_0000Z0b1001_0100Z0xffff_ffffZ0o5_7_7z	1_00_00.5z1_00_00.5e5Z1_00_00e5_1Z1e1_0z.1_4z.1_4e1Z0b_0Z0x_fZ0o_5Z1_00_00jz
1_00_00.5jZ1_00_00e5_1jz.1_4jz(1_2.5+3_3j)z(.5_6j))(Z0_Z42_z1.4j_Z0x_0b1_Z0xf_Z0o5_z0 if 1_Else 1Z0_b0Z0_xfZ0_o5Z0_7Z09_99Z	4_______2z0.1__4z0.1__4jZ0b1001__0100Z0xffff__ffffZ0x___Z0o5__77Z1e1__0Z1e1__0jz1_.4z1_.4jz1._4z1._4jz._5z._5jz1.0e+_1z1.0e+_1jz1.4_jz1.4e5_jZ1_e1z1.4_e1z1.4_e1jZ1e_1z1.4e_1z1.4e_1jz
(1+1.5_j_)z	(1+1.5_j)c                   @   sp   e Zd ZddlmZ dd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )
TokenTestsr   r   c                 C   s(   d}|  |dd d}|  |dd d S )N   zbackslash for line continuationr   zbackslash ending commentassertEqualselfx r   ;/opt/python-3.10.19/usr/lib/python3.10/test/test_grammar.pytest_backslashl   s   zTokenTests.test_backslashc              	   C   s`  |  tdtd |  dd |  dd |  dd |  dd | ttd ddlm} |dkrk|  dd | ddk | ddk | ddk d	D ]}zt|}W qP tyh   | 	d
|  Y qPw d S |dkr|  dd | ddk | ddk | ddk dD ]}zt|}W q ty   | 	d
|  Y qw d S | 	d|  d S )Nr      i	   0x)maxsizei   l    )Z
2147483648Z0o40000000000Z0x100000000Z"0b10000000000000000000000000000000z(OverflowError on huge integer literal %rl    l             l    )Z9223372036854775808Z0o2000000000000000000000Z0x10000000000000000ZA0b100000000000000000000000000000000000000000000000000000000000000zWeird maxsize value %r)
r   typeassertRaisesSyntaxErrorevalsysr   
assertTrueOverflowErrorfail)r   r   sr   r   r   r   test_plain_integersv   s@   zTokenTests.test_plain_integersc                 C   s$   d}d}d}d}d}d}d}d}d S )Nr   r   l   ? l   
~l!]c l            l   r   r   r   r   r   test_long_integers   s   zTokenTests.test_long_integersc                 C   s0   d}d}d}d}d}d}d}d}d}d}d}d S )NgQ	@g     s@gjt?g  Bgt =g  WHBg     F@r   r   r   r   r   test_floats   s   zTokenTests.test_floatsc                 C   sf   t   t dt | tdd | tdd W d    n1 s%w   Y  | ttd d S )Nignorez1 if 1else 0   z1 if 0else 0r   z0 if 1Else 0)warningscatch_warningssimplefilterDeprecationWarningr   r   r   r   r   r   r   r    test_float_exponent_tokenization   s   
z+TokenTests.test_float_exponent_tokenizationc              	   C   sP   t D ]}| t|t|dd qtD ]	}| tt| q| ttd d S )N_ Z_0)VALID_UNDERSCORE_LITERALSr   r   replaceINVALID_UNDERSCORE_LITERALSr   r   	NameError)r   Zlitr   r   r   test_underscore_literals   s
   z#TokenTests.test_underscore_literalsc                 C   s   | 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 S )NZ0b12z#invalid digit '2' in binary literalZ0b1_2Z0b2r
   zinvalid binary literalZ0bZ0o18z"invalid digit '8' in octal literalZ0o1_8Z0o8Z0o1_zinvalid octal literalZ0oZ0x1_zinvalid hexadecimal literalr   Z1_zinvalid decimal literalZ012z`leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integersz1.2_Z1e2_z1e+r   r   checkr   r   r   test_bad_numerical_literals   s(   














z&TokenTests.test_bad_numerical_literalsc              	      s  d fdd	}dD ]r}t |dd || d|dkd	 || d
|dkd	 || d || d t  tddt || d W d    n1 sRw   Y  || d |d| d|dkd	 |d| d || ddd	 q	|d |d |d d S )NFc              
      s    j | dn |rAtjdd#} t t| dd W d    n1 s&w   Y  W d    n1 s5w   Y   |g  n# t t| dd W d    n1 sWw   Y  W d    d S W d    d S W d    d S 1 sww   Y  d S )N)exprT)record
<testcase>r   )	subTestr(   r)   r   r   compiler   ZassertWarnsr+   )testerrorwr,   r   r   r6      s"   "z8TokenTests.test_end_of_numerical_literals.<locals>.check)0xfZ0o7Z0b190z1.Z1e3Z1jr:   r   zand xr@   )r>   zor xrB   zin xznot in xr&   "is" with a literalzis xzif x else yzx if zelse y[zfor x in ()]spamTz[0x1ffor x in ()]z[0x1for x in ()]z[0xfor x in ()]F)r<   r(   r)   filterwarningsSyntaxWarning)r   r6   numr   r,   r   test_end_of_numerical_literals   s(   
z)TokenTests.test_end_of_numerical_literalsc                 C   s
  d}d}|  t|dko||k d}d}|  t|dko&||ko&t|dk d}d}|  t|dko=||ko=t|dk d}d}|  t|d	koN||k d
}d
}|  t|d	ko_||k d}d}| || d}| || d}| || d}| || d S )Nr/   r   'r'   '   ""   zdoesn't "shrink" does it   zdoes "shrink" doesn't itz2
The "quick"
brown fox
jumps over
the 'lazy' dog.
)r   lenordr   r   r   yr   r   r   test_string_literals   s$   "..zTokenTests.test_string_literalsc                 C   s$   d}|  |tu  | ttd d S )N.z.. .)r   Ellipsisr   r   r   r   r   r   r   test_ellipsis  s   zTokenTests.test_ellipsisc              	   C   sZ   d}|D ]&}|  t}t|dd W d    n1 sw   Y  | dt|j qd S )N)zdef foo(z	
def foo(z	def foo(
z<test>execzwas never closed)r   r   r<   ZassertInstr	exception)r   Zsamplesr"   cmr   r   r   test_eof_error$  s   zTokenTests.test_eof_errorN)__name__
__module____qualname__test.supportr   r   r#   r$   r%   r-   r4   r7   rJ   rT   rV   r[   r   r   r   r   r   h   s    
$
(r   Zvar_annot_globalc                   @   $   e Zd Zdd Zdd Zdd ZdS )CNSc                 C   
   i | _ d S N_dctr,   r   r   r   __init__0     
zCNS.__init__c                 C   s   || j | < d S rc   )re   lowerr   itemvaluer   r   r   __setitem__2  s   zCNS.__setitem__c                 C   
   | j | S rc   rd   r   rj   r   r   r   __getitem__4  rg   zCNS.__getitem__Nr\   r]   r^   rf   rl   ro   r   r   r   r   ra   /  s    ra   c                   @   sL  e Zd ZddlmZ ddlmZ ddlmZ dd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Z d7d8 Z!d9d: Z"d;d< Z#d=d> Z$d?d@ Z%dAdB Z&dCdD Z'dEdF Z(dGdH Z)dIdJ Z*e+,dKdLdMdN Z-dOdP Z.dQdR Z/dSdT Z0dUdV Z1dWdX Z2dYdZ Z3d[d\ Z4d]d^ Z5d_d` Z6dadb Z7dcdd Z8dedf Z9dgdh Z:didj Z;dkdl Z<dmdn Z=dodp Z>dqdr Z?dsdt Z@dudv ZAdwdx ZBdydz ZCd{d| ZDd}d~ ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdS )GrammarTestsr   r   r   )check_no_warningsc                 C   s   t d}d S )Nz	1, 0 or 1)r   r   r   r   r   test_eval_inputG     zGrammarTests.test_eval_inputc                 C   s@   d}dg}dd }t  tg d d|| d < | |dg d S )N   *   c                   S      dS Nr'   r   r   r   r   r   oneP     z/GrammarTests.test_var_annot_basics.<locals>.oner   r'   )intlistr   )r   Zvar1Zmy_lstry   r   r   r   test_var_annot_basicsK  s   
z"GrammarTests.test_var_annot_basicsc                 C   s^   t | d t | d t | d t | d t | d t | d t | d t | d t | d	 d S )
Nz
def f: intzx: int: strzdef f():
    nonlocal x: int
z[x, 0]: int
z	f(): int
z	(x,): intz"def f():
    (x, y): int = (1, 2)
z!def f():
    x: int
    global x
z!def f():
    global x
    x: int
r   r,   r   r   r   test_var_annot_syntax_errorsW  s   







z)GrammarTests.test_var_annot_syntax_errorsc           	   
   C   s  |  t dd tt< W d    n1 sw   Y  |  t dtt< W d    n1 s/w   Y  dd }| |ji  dd }|  dd }|  t |  W d    n1 s]w   Y  d	d
 }z|  W n ty } z| 	t
|t W Y d }~nd }~ww G dd d}| |jttd |  t G dd d}W d    n1 sw   Y  |  t G dd d|}W d    d S 1 sw   Y  d S )Nr'   r   c                  S   s   d} dt _| S )NZHellor'   r   ab)str   r   r   ft  s   z6GrammarTests.test_var_annot_basic_semantics.<locals>.fc                   S      d S rc   r   r   r   r   r   f_OKy      z9GrammarTests.test_var_annot_basic_semantics.<locals>.f_OKc                  S   s   t |  d S rc   printr   r   r   r   fbad|  rt   z9GrammarTests.test_var_annot_basic_semantics.<locals>.fbadc                   S   s   t t d S rc   )r   Zno_such_globalr   r   r   r   f2bad  rt   z:GrammarTests.test_var_annot_basic_semantics.<locals>.f2badc                   @   s.   e Zd ZU eed< dZeed< dZdd ZdS )z6GrammarTests.test_var_annot_basic_semantics.<locals>.C_C__fooattrr"   r   c                 S   s
   || _ d S rc   r   r   r   r   r   rf     rg   z?GrammarTests.test_var_annot_basic_semantics.<locals>.C.__init__N)	r\   r]   r^   r{   __annotations__r"   rX   zrf   r   r   r   r   C  s
   
 r   )r   r"   c                   @   s   e Zd ZU de_e dS )z9GrammarTests.test_var_annot_basic_semantics.<locals>.CBadr   N)r\   r]   r^   Zno_such_name_definedr   r{   r   r   r   r   CBad  s   
 r   c                   @   s    e Zd ZU eed< g e_e dS )z:GrammarTests.test_var_annot_basic_semantics.<locals>.Cbad2r   N)r\   r]   r^   r{   r   r   rS   r|   r   r   r   r   Cbad2  s   
 r   )r   ZeroDivisionErrorZno_nameZdoes_not_existr3   r   r   UnboundLocalError	ExceptionZassertIsr   r{   rX   )	r   r   r   r   r   er   r   r   r   r   r   test_var_annot_basic_semanticsk  s:   

"z+GrammarTests.test_var_annot_basic_semanticsc                 C   s   G dd d}G dd d|}G dd d|}G dd d}G d	d
 d
||}G dd d||}|  |jdti |  |ji  |  |jdti |  |jdti |  |ji  |  |ji  d S )Nc                   @      e Zd ZU eed< dS )z4GrammarTests.test_annotations_inheritance.<locals>.Ar   Nr\   r]   r^   r{   r   r   r   r   r   A     
 r   c                   @      e Zd ZdS )z4GrammarTests.test_annotations_inheritance.<locals>.BNr\   r]   r^   r   r   r   r   B      r   c                   @   r   )z4GrammarTests.test_annotations_inheritance.<locals>.Cr   N)r\   r]   r^   rX   r   r   r   r   r   r     r   r   c                   @   r   )z4GrammarTests.test_annotations_inheritance.<locals>.Dattr2Nr   r   r   r   r   D  r   r   c                   @   r   )z4GrammarTests.test_annotations_inheritance.<locals>.ENr   r   r   r   r   E  r   r   c                   @   r   )z4GrammarTests.test_annotations_inheritance.<locals>.FNr   r   r   r   r   F  r   r   r   r   )r   r   r{   rX   )r   r   r   r   r   r   r   r   r   r   test_annotations_inheritance  s   z)GrammarTests.test_annotations_inheritancec                 C   s8   G dd dt }G dd d|d}| |jd d d S )Nc                   @   s   e Zd Zedd ZdS )z>GrammarTests.test_var_annot_metaclass_semantics.<locals>.CMetac                 [   s
   dt  iS Nr   )ra   )metaclsnamebaseskwdsr   r   r   __prepare__     
zJGrammarTests.test_var_annot_metaclass_semantics.<locals>.CMeta.__prepare__N)r\   r]   r^   classmethodr   r   r   r   r   CMeta  s    r   c                   @   s   e Zd ZU ded< dS )z;GrammarTests.test_var_annot_metaclass_semantics.<locals>.CCANNOTZXXN)r\   r]   r^   r   r   r   r   r   CC  r   r   )	metaclassxxr   )r   r   r   )r   r   r   r   r   r   "test_var_annot_metaclass_semantics  s   z/GrammarTests.test_var_annot_metaclass_semanticsc              	   C   s^   |  tji  |  tjdtttjttf ttB d |  tj	jdt
d |  tji  d S )Nr   )r'   r   rS   r   u{   )Z123o)r   r=   r   
ann_moduler{   rX   typingTuplefloatMr   r	   r,   r   r   r   test_var_annot_module_semantics  s   
z,GrammarTests.test_var_annot_module_semanticsc                 C   s   t d}| t |  W d    n1 sw   Y  | t |  W d    n1 s2w   Y  | t |d W d    d S 1 sMw   Y  d S )Nztest.ann_module3ru   )r   Zimport_fresh_moduler   r3   Z	f_bad_annZ	g_bad_annZ	D_bad_ann)r   Zann_module3r   r   r   test_var_annot_in_module  s   


"z%GrammarTests.test_var_annot_in_modulec                 C   sb   i }i }t d|| | |d dtd | t |d  W d    d S 1 s*w   Y  d S )Nz.'docstring'
__annotations__[1] = 2
x: int = 5
r   r   )r'   r   )rW   r   r{   r   KeyError)r   ZgnsZlnsr   r   r   test_var_annot_simple_exec  s   
"z'GrammarTests.test_var_annot_simple_execc                    s   dt  i}td| | |d d t | |d d t | t |d d  W d    n1 s4w   Y  i  G  fddd}tdi |  |  d d t d S )	Nr   z'X: int; Z: str = "Z"; (w): complex = 1jr   r   r?   c                       s(   e Zd Zdd Z fddZdd ZdS )z5GrammarTests.test_var_annot_custom_maps.<locals>.CNS2c                 S   rb   rc   rd   r,   r   r   r   rf     rg   z>GrammarTests.test_var_annot_custom_maps.<locals>.CNS2.__init__c                       || j |< | |< d S rc   rd   ri   	nonloc_nsr   r   rl        
zAGrammarTests.test_var_annot_custom_maps.<locals>.CNS2.__setitem__c                 S   rm   rc   rd   rn   r   r   r   ro     rg   zAGrammarTests.test_var_annot_custom_maps.<locals>.CNS2.__getitem__Nrp   r   r   r   r   CNS2  s    r   z
x: int = 1)ra   rW   r   r{   rX   r   r   )r   nsr   r   r   r   test_var_annot_custom_maps  s   

	z'GrammarTests.test_var_annot_custom_mapsc                    sH   t   d iG  fddd}tdi |  | d d t d S )Nr   c                       s,   e Zd Z fddZfddZdd ZdS )z1GrammarTests.test_var_annot_refleak.<locals>.CNS2c                    s   d i| _ d S r   rd   r,   )cnsr   r   rf        z:GrammarTests.test_var_annot_refleak.<locals>.CNS2.__init__c                    r   rc   rd   ri   r   r   r   rl     r   z=GrammarTests.test_var_annot_refleak.<locals>.CNS2.__setitem__c                 S   rm   rc   rd   rn   r   r   r   ro     rg   z=GrammarTests.test_var_annot_refleak.<locals>.CNS2.__getitem__Nrp   r   r   r   r   r   r     s    r   zX: strr   )ra   rW   r   rX   )r   r   r   r   r   test_var_annot_refleak  s
   	z#GrammarTests.test_var_annot_refleakc                 C   sr   i }t d| | |d d d}t || | t|d  d g dddtjd	}t d
| | |d d d S )Nzx: tuple = 1, 2r   r   zdef f():
    x: int = yieldr   r'   r         ru   )r   r   cr   zx: Tuple[int, ...] = a,*b,cr'   r   r   r   ru   )rW   r   r|   r   r   )r   r   Zstmtr   r   r   test_var_annot_rhs  s   


zGrammarTests.test_var_annot_rhsc                    s\
  dd }|  |d  |di i  dd }dd }|  |jjd |  |j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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   |	g pdg  |	g di odR i i  |	di d!di |	di d!dipi  d d"d#}
|
d |
dd |
d i d$di d d%d&}|dd |ddd |d'  |dgd(R   |ddgd)R   |d-i d*di d-d+d,}|  |d |dd |d-  |dgd.R   |d i d$di |di ddd/ d-d0d1}|d |dd |ddd d-d2d3}|dd |ddd |dddd d d4d5}|  |d |dd |d6  |d   |di d!di d d7d8}|d |dd |ddd d d9d:}|dd |ddd |dddd |d6  |d-i d*di d-d;d<}|  |d |dd |ddd |dgd=R   |di ddd/ d-d>d?}|d |dd |ddd |dddd |d6  |ddgd@R   |dgd.R i d*di d-dAdB}|dd |ddd |dddd |ddddd |d6  |ddgd@R   |dgd(R i dCdi t ) tdDt ztdi dFdi W n
 ty   Y nw | 	dG W d    n	1 sw   Y  dHdI }|dJdK dJdLdMdN}|dddJdO |dddJdPdQ |dddJdPdR dJdOdSdT}|dddJdJdPdU |dddJdPdJdV | 
ttdW | 
ttdX | 
ttdY dZd[ }|  |dgddgR ddd\d]ddd\f |  |dgd(dR  d6i f | 
ttd^ |  |di d_d`dadd_d`daf |  |ddbd`idcd_idd_d`daf t| dd t| de dftfdgd[}|  |jdfti dEtfdhd[}|  |jdEti dEtfdid[}|  |jdEti ddEtfdkd[}|  |jdEti dEtfdld[}|  |jdEti dEtfdmd[}|  |jdEti ddod[}|  |jdndi ddpd[}|  |jdndi ddqd[}|  |jdddr ddsd[}|  |jdddr dddvd[}|  |jdddddw dddxdy	}	f	~ddd[}|  |jddddddd}d~d dddxdyd$dd*ddtddtduddzdd{dd|d}dfd~fdd[}|  |jdddtdddd}d~d	 G dd d}G dd d|}|  |jjddi |  |jjddi dd dftfdd[}|  |jdfti dd[ } }dd[ }fdddd[ }ddgd dd[ }dd[ }gd jjdd[ }d  fdd[}d  fdd[	}dd fdd[
}dftf fdd[}dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }dd[ }d S )Nc                   S   r   rc   r   r   r   r   r   f1  r   z%GrammarTests.test_funcdef.<locals>.f1r   c                 S   r   rc   r   Zone_argumentr   r   r   f2  r   z%GrammarTests.test_funcdef.<locals>.f2c                 S   r   rc   r   twoZ	argumentsr   r   r   f3  r   z%GrammarTests.test_funcdef.<locals>.f3r   r   c                 S   r   rc   r   )Zone_argr   r   r   a1  r   z%GrammarTests.test_funcdef.<locals>.a1c                 S   r   rc   r   )r   argsr   r   r   a2  r   z%GrammarTests.test_funcdef.<locals>.a2c                  W   r   rc   r   restr   r   r   v0  r   z%GrammarTests.test_funcdef.<locals>.v0c                 W   r   rc   r   r   r   r   r   r   v1  r   z%GrammarTests.test_funcdef.<locals>.v1c                 W   r   rc   r   r   r   r   r   r   r   v2   r   z%GrammarTests.test_funcdef.<locals>.v2r'   r   r   r   ru            r   r   c                 S   r   rc   r   r   r   r   r   d016  r   z&GrammarTests.test_funcdef.<locals>.d01r'   r   c                 S   r   rc   r   r   r   r   r   d11>  r   z&GrammarTests.test_funcdef.<locals>.d11r   c                 S   r   rc   r   r   r   r   r   r   r   d21B  r   z&GrammarTests.test_funcdef.<locals>.d21r'   r   r   r   r   r   r   c                 S   r   rc   r   r   r   r   r   d02I  r   z&GrammarTests.test_funcdef.<locals>.d02r   r   r   c                 S   r   rc   r   r   r   r   r   d12Q  r   z&GrammarTests.test_funcdef.<locals>.d12c                 S   r   rc   r   r   r   r   dr   r   r   d22U  r   z&GrammarTests.test_funcdef.<locals>.d22c                 W   r   rc   r   r   r   r   r   d01vY  r   z'GrammarTests.test_funcdef.<locals>.d01v)r'   r   r   r   c                 W   r   rc   r   r   r   r   r   d11v`  r   z'GrammarTests.test_funcdef.<locals>.d11vc                 W   r   rc   r   r   r   r   r   r   r   r   d21vd  r   z'GrammarTests.test_funcdef.<locals>.d21vc                 W   r   rc   r   r   r   r   r   d02vj  r   z'GrammarTests.test_funcdef.<locals>.d02vr   c                 W   r   rc   r   r   r   r   r   d12vq  r   z'GrammarTests.test_funcdef.<locals>.d12vr   r   ru   c                 W   r   rc   r   )r   r   r   r   r   r   r   r   d22vy  r   z'GrammarTests.test_funcdef.<locals>.d22vr   r&   r   s   fooz/Bytes should not work as keyword argument namesc                 S      | S rc   r   keyr   r   r   pos0key1  r   z+GrammarTests.test_funcdef.<locals>.pos0key1d   r   )k2c                S   s   | |||fS rc   r   )p1p2k1r   r   r   r   pos2key2      z+GrammarTests.test_funcdef.<locals>.pos2key2)r     )r  r   )r   r  c                [   s   | ||||fS rc   r   )r  r  r  r   kwargr   r   r   pos2key2dict      z/GrammarTests.test_funcdef.<locals>.pos2key2dict)r   tokwarg1tokwarg2)r
  r  r   zdef f(*): passzdef f(*,): passzdef f(*, **kwds): passc                  _   s   | |fS rc   r   )r   kwargsr   r   r   r     s   z$GrammarTests.test_funcdef.<locals>.fr   rS   )r'   r   r   zf(1, x=2, *(3,4), x=5)Z	scrambledZfried)eggsrE   rE   r  z
f(*g(1=2))zf(**g(1=2))returnc                 S   r   rc   r   r   r   r   r   r     r   c                 S   r   rc   r   r   r   r   r   r     r   c                S   r   rc   r   r   r   r   r   r     r   rN   c                S   r   rc   r   r   r   r   r   r     r   c                  W   r   rc   r   r   r   r   r   r     r   c                  [   r   rc   r   r   r   r   r   r     r   rS   c                 S   r   rc   r   r  r   r   r   r     r   c                S   r   rc   r   r  r   r   r   r     r   c                 S   r   rc   r   r   r   r   r   r     r   )r   r   c                S   r   rc   r   r   r   r   r   r     r   r   gc                 W   r   rc   r   )r   r   r   r   r   r   r  r   r   r   r     r   )r   r   r   r  
   ijhr  k      c                _   r   rc   r   r   r   r   r   r   r   r  r  r  r  r  r   r   r   r     rz   )r   r   r   r  r  r  r  r  r   c               _   r   rc   r   r  r   r   r   r     rz   )	r   r   r   r   r  r  r  r  r  c                   @   s   e Zd ZdddZdS )z'GrammarTests.test_funcdef.<locals>.Spam	_Spam__kwr'   c                S   r   rc   r   )r   r  r   r   r   r     rz   z)GrammarTests.test_funcdef.<locals>.Spam.fN)r  r'   )r\   r]   r^   r   r   r   r   r   Spam  s    r  c                   @   r   )z&GrammarTests.test_funcdef.<locals>.HamNr   r   r   r   r   Ham  r  r  r  c                 S   r   rc   r   r   r   r   r   null  r   z'GrammarTests.test_funcdef.<locals>.nullc                 S   r   rc   r   r   r   r   r   r     rz   Fc                 S   r   rc   r   r   r   r   r   r     rz   c                 S   r   rc   r   r   r   r   r   r     rz   c                        | S rc   r   r   )r  r   r   <lambda>      z+GrammarTests.test_funcdef.<locals>.<lambda>c                 S   r   rc   r   r   r   r   r   r     rz   .c                 S   r   rc   r   r   r   r   r   r     rz   c                 S   r   rc   r   r   r   r   r   r     rz   c                 S   r   rc   r   r   r   r   r   r     rz   c                          S rc   r   r   closurer   r   r     r   c                    r"  rc   r   r   r#  r   r   r     r   r  c                    r"  rc   r   r%  r#  r   r   r     r   c                      r"  rc   r   r   r#  r   r   r     r   c                 S   r   rc   r   r   r   r   r   r     r   c                  W   r   rc   r   r   r   r   r   r     r   c                  [   r   rc   r   r   r   r   r   r     r   c                 W   r   rc   r   r   r   r   r   r   r     r   c                 [   r   rc   r   r   r   r   r   r   r     r   c                 W   r   rc   r   r   r   r   r   r   r     r   c                 S   r   rc   r   r   r   r   r   r     r   c                  _   r   rc   r   r   r   r   r   r   r     r   c                W   r   rc   r   r   r   r   r   r   r   r     r   c                S   r   rc   r   r   r   r   r   r     r   c                 _   r   rc   r   r   r   r   r   r   r   r     r   c                 _   r   rc   r   r   r   r   r   r   r   r     r   c                 [   r   rc   r   r   r   r   r   r   r     r   c                _   r   rc   r   r   r   r   r   r   r   r   r     r   c                [   r   rc   r   r   r   r   r   r   r   r     r   r   )rN   )rS   r   )r   r'   r   r   )r   r   r   r'   )r   ru   )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   __code__co_varnamesr(   r)   r*   BytesWarningrX   	TypeErrorr!   r   r   r   r   r|   r   r{   r   r   __call__)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   test_funcdef  s  





























	
  







(








zGrammarTests.test_funcdefc                 C   sV  dd }|  | d dd }dd }|  | g d d'ddfd	dfd
d}|  | d d(dd}|  |ddd |  |dddd t| d t| 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 S ))Nc                   S   rw   Nr   r   r   r   r   r   r     r   z+GrammarTests.test_lambdef.<locals>.<lambda>r   c                   S   s   t t S rc   )r   r   r   r   r   r   r     r!  c                   S   s   dd dD S )Nc                 S   s   g | ]}d |k qS r   r   .0r   r   r   r   
<listcomp>      z?GrammarTests.test_lambdef.<locals>.<lambda>.<locals>.<listcomp>)r   r   r   r   r   r   r   r     r	  )r   r'   r   r'   c                 S   r   rc   r   r   r   r   r   r     r   c                 S      |  S rc   r   )rS   r   r   r   r         c                 S   r@  rc   r   r   r   r   r   r     rA  r   c                 S      | | | S rc   r   )r   rS   r   r   r   r   r     r  ru   r   r   zlambda x: x = 2zlambda (None,): None   r%  c                S   rB  rc   r   )r   rS   r  r   r   r   r     r     r     c                 S   rw   r9  r   r   r   r   r   r     r   c                  W   rw   r9  r   r&  r   r   r   r     r   c                  [   rw   r9  r   r'  r   r   r   r     r   c                 W   rw   r9  r   r(  r   r   r   r     r   c                 [   rw   r9  r   r)  r   r   r   r     r   c                 W   rw   r9  r   r*  r   r   r   r     r   c                 S   rw   r9  r   r+  r   r   r   r     r   c                  _   rw   r9  r   r,  r   r   r   r     r   c                W   rw   r9  r   r-  r   r   r   r     r   c                S   rw   r9  r   r   r   r   r   r     r   c                 _   rw   r9  r   r.  r   r   r   r     r   c                 _   rw   r9  r   r/  r   r   r   r     r   c                 [   rw   r9  r   r0  r   r   r   r     r   c                _   rw   r9  r   r1  r   r   r   r     r   c                [   rw   r9  r   r2  r   r   r   r      r   r   r   r   r   )r   l1l2l3l4l5l6l10Zl11Zl12Zl13Zl14Zl15Zl16Zl17Zl18Zl19Zl20Zl21Zl22Zl23Zl24r   r   r   test_lambdef  s<   


zGrammarTests.test_lambdefc                 C   s   d}~dd }|  d S )Nr'   c                  S   s
   d} ~ d S rx   r   r   r   r   r   foo)  r   z*GrammarTests.test_simple_stmt.<locals>.foor   )r   r   rO  r   r   r   test_simple_stmt&  s   
zGrammarTests.test_simple_stmtc           	      C   sV   	 	 d}d}d } }}d\}}}d } \}}} \}}}}t | d t | d d S )Nr'   r   )r'   r   )r   r   z	x + 1 = 1za + 1 = b + 2r   )	r   r   rS   r   abcr   r   r   xyzr   r   r   test_expr_stmt1  s   

zGrammarTests.test_expr_stmtc                 C   s  d}g d}|D ]w}d |}|D ]m}| |}| j|d" | t| t| W d    n1 s4w   Y  W d    n1 sCw   Y  |dd}| j|d" | td t| W d    n1 sjw   Y  W d    n1 syw   Y  qqd S )N)r   rW   )z{} fooz{} {{1:foo}}zif 1: {} foozif 1: {} {{1:foo}}zif 1:
    {} foozif 1:
    {} {{1:foo}}zcall to '{}')sourcerO  z(foo.)zinvalid syntax)formatr;   ZassertRaisesRegexr   rW   r1   )r   keywordscaseskeywordZ
custom_msgcaserT  r   r   r   (test_former_statements_refer_to_builtins@  s,   



z5GrammarTests.test_former_statements_refer_to_builtinsc                 C   s   g d}|\}}}|||f}~~~~~d\}}}~~~d\}}}}	}
}}~~~~	~
~d\}}}}	}
}}~~~~	~
~t d}|dd= tddd	 d S )
Nr   rR  Zabcdefgabcdr'   r   z-del a, (b[0].c, (d.e, f.g[1:2])), [h.i.j], ()r:   rW   )r|   r<   )r   rQ  r   rS   r   rR  r   r   r   r   r   r   r  r[  r   r   r   test_del_stmtW  s    



zGrammarTests.test_del_stmtc                 C   r   rc   r   r,   r   r   r   test_pass_stmtq     zGrammarTests.test_pass_stmtc                 C   r   rc   r   r,   r   r   r   test_break_stmtx  r^  zGrammarTests.test_break_stmtc                 C   sx   d}|rd}qd}|sd}zW q	   d}Y |r|dkr!|  | d}|s/d}zW d}q#d}w |dkr:|  | d S d S )Nr'   r   r/   okz&continue failed to continue inside tryz'continue inside try called except blockzfinally block not calledr!   )r   r  msgr   r   r   test_continue_stmt|  s*   

zGrammarTests.test_continue_stmtc                    s   d fdd	}|  d S )Nr'   r   c                    s`   d}|r|d7 }z| r|dkr| d8 } W n
|d8 }W q    |dks'|dkr.  d d S d S )Nr   r'   z1continue then break in try/except in loop broken!ra  )Zextra_burning_oilcountZ	big_hippor,   r   r   
test_inner  s   z9GrammarTests.test_break_continue_loop.<locals>.test_inner)r'   r   r   )r   re  r   r,   r   test_break_continue_loop  s   

z%GrammarTests.test_break_continue_loopc                 C   sF   dd }dd }dd }|  | }| }|  |dd t| d	 d S )
Nc                   S   r   rc   r   r   r   r   r   g1  r   z$GrammarTests.test_return.<locals>.g1c                   S   rw   rx   r   r   r   r   r   g2  r   z$GrammarTests.test_return.<locals>.g2c                  S   s   ddg} dg| R S )Nr   r   r'   r   r?  r   r   r   g3  s   z$GrammarTests.test_return.<locals>.g3r   z unparenthesized star expr returnzclass foo:return 1rF  )r   rg  rh  ri  r   rS   r   r   r   test_return  s   zGrammarTests.test_returnc                 C   s4  d}|dk r|d7 }zW n   Y |  |d d}|dk r(|d7 }zW n   Y |  |d d}|dk rC|d7 }zdd  W n   Y |  |d dD ]}|  |d zW  n   Y  |  |d dD ]}|  |d zW  n   Y  |  |d dD ]}|  |d zdd  W  n   Y  |  |d d S Nr   r   r'   r   r'   r   r   rd  r   r   r   test_break_in_finally  sN   




z"GrammarTests.test_break_in_finallyc                 C   s  d}|dk r|d7 }zW q   Y q|  |d d}|dk r*|d7 }zW q   Y q|  |d d}|dk rF|d7 }zdd  W q2   Y q2|  |d dD ]	}zW qN   Y qN|  |d dD ]	}zW q`   Y q`|  |d dD ]}zdd  W qr   Y qr|  |d d S rk  r   rm  r   r   r   test_continue_in_finally  sH   

z%GrammarTests.test_continue_in_finallyc                 C   sF   dd }|  | d dd }|  | d dd }|  | d	 d S )
Nc                   S      zW dS    Y dS rx   r   r   r   r   r   rg  (     z/GrammarTests.test_return_in_finally.<locals>.g1r'   c                   S   rp  )Nr   r   r   r   r   r   rh  /  rq  z/GrammarTests.test_return_in_finally.<locals>.g2r   c                   S   s   zdd  W dS    Y dS )Nr'   r   r   r   r   r   r   r   ri  6  s   
z/GrammarTests.test_return_in_finally.<locals>.g3r   r   )r   rg  rh  ri  r   r   r   test_return_in_finally'  s   z#GrammarTests.test_return_in_finallyc                 C   sT   dd }|  |dd |  |dd dd }|  |dd |  |dd d S )	Nc                 S   sP   dD ] }d}|dk r"|d7 }z|| W | r n  S | r!   Y nw qd||fS )Nrl  r   rC  r  endr   r   rd  Zcount2r   r   r   rg  ?  s   

z;GrammarTests.test_break_in_finally_after_return.<locals>.g1Fr  T)rs  r'   r  c              	   S   sL   dD ]}dD ]}z|| W | r  n    S | r   Y  nw qd||fS )Nrl  )r  rC  rs  r   rt  r   r   r   rh  M  s   
z;GrammarTests.test_break_in_finally_after_return.<locals>.g2r   r   rg  rh  r   r   r   "test_break_in_finally_after_return=  s   	z/GrammarTests.test_break_in_finally_after_returnc                 C   sT   dd }|  |dd |  |dd dd }|  |dd	 |  |dd
 d S )Nc                 S   s<   d}|dk r|d7 }z|W | r qS | r   Y qw d|fS )Nr   r   r'   rs  r   r   rd  r   r   r   rg  [  s   z>GrammarTests.test_continue_in_finally_after_return.<locals>.g1Fr'   T)rs  r   c                 S   s4   dD ]}z	|W | r q  S | r   Y qw d|fS )Nrl  rs  r   rw  r   r   r   rh  h  s   
z>GrammarTests.test_continue_in_finally_after_return.<locals>.g2r   )rs  r'   r   ru  r   r   r   %test_continue_in_finally_after_returnY  s   
z2GrammarTests.test_continue_in_finally_after_returnc                 C   s  dd }dd }dd }dd }dd }dd }t | d t | d	 d
d }dd }t | d t | d dd }dd }dd }dd }dd }| t| dg t | d t | d t | d t | d t | d t | d t | d t | d t | d d S )Nc                   s       dV  d S rx   r   r   r   r   r   r  u     
 z"GrammarTests.test_yield.<locals>.gc                   s   s    dE d H  d S Nr   r   r   r   r   r   r  v      c                  s       dV } d S rx   r   r   r   r   r   r  x  rz  c                  s   s    dE d H } d S r{  r   r   r   r   r   r  y  r|  c                   s   ry  N)r'   r'   r   r   r   r   r   r  {  rz  c                  s   r}  r~  r   r   r   r   r   r  |  rz  zdef g(): yield from (), 1zdef g(): x = yield from (), 1c                   s   s    ddV f d S rx   r   r   r   r   r   r    r|  c                   s   s    ddE d H f d S Nr'   r   r   r   r   r   r   r        zdef g(): 1, yield 1zdef g(): 1, yield from ()c                   s   s    t dV  d S rx   r  r   r   r   r   r    r|  c                   s   s    t dV d d S rx   r  r   r   r   r   r    s    c                   s   s    t dE d H  d S r{  r  r   r   r   r   r    r  c                   s   s    t dE d H d d S )Nr   r'   r  r   r   r   r   r        c                  s   s    d} dddg| R V  d S )Nr   ru   r   r'   r   r   r   r   r   r   r   r        )r'   r   r   r   ru   r   zdef g(): f(yield 1)zdef g(): f(yield 1, 1)zdef g(): f(yield from ())zdef g(): f(yield from (), 1)yieldz
yield fromzclass foo:yield 1zclass foo:yield from ()zdef g(a:(yield)): pass)r   r   r|   r   r  r   r   r   
test_yields  s6   











zGrammarTests.test_yieldc                 C   s~   dd }dd }| j }|dd |dd |dd |dd	 |d
d |dd |dd |dd |dd |dd d S )Nc                   s   s    dd dV fD  d S )Nc                 S      g | ]}|qS r   r   r:  r   r   r   r<        HGrammarTests.test_yield_in_comprehensions.<locals>.g.<locals>.<listcomp>r'   r   r   r   r   r   r        z4GrammarTests.test_yield_in_comprehensions.<locals>.gc                   s   s    dd dE d H fD  d S )Nc                 S   r  r   r   r:  r   r   r   r<    r  r  r   r   r   r   r   r   r    r  z def g(): [(yield x) for x in ()]z!'yield' inside list comprehensionz)def g(): [x for x in () if not (yield x)]z-def g(): [y for x in () for y in [(yield x)]]z def g(): {(yield x) for x in ()}z 'yield' inside set comprehensionz#def g(): {(yield x): x for x in ()}z!'yield' inside dict comprehensionz#def g(): {x: (yield x) for x in ()}z def g(): ((yield x) for x in ())z#'yield' inside generator expressionz%def g(): [(yield from x) for x in ()]z class C: [(yield x) for x in ()]z[(yield x) for x in ()]r   )r   r  r6   r   r   r   test_yield_in_comprehensions  sB   z)GrammarTests.test_yield_in_comprehensionsc                 C   s6   zt d t y   Y nw zt ty   Y d S w )Nzjust testing)RuntimeErrorKeyboardInterruptr,   r   r   r   
test_raise  s   
zGrammarTests.test_raisec                 C   sd   dd l }dd l}dd l }ddlm} ddlm} ddl m}m} ddl m}m} ddl m}m} d S )Nr   )time)pathargv)r   r  r  r  )r   r   r  r  r  r   r   r   test_import  s   zGrammarTests.test_importc                 C   r   rc   r   r,   r   r   r   test_global  r   zGrammarTests.test_globalc                    s   d d fdd}d S )Nr   c                      r   rc   r   r   r  r   r   r     r   z%GrammarTests.test_nonlocal.<locals>.fr   )r   r   r   r  r   test_nonlocal  s   zGrammarTests.test_nonlocalc              
   C   sl   zW n t y } z| d W Y d }~nd }~ww zW d S  t y5 } z| d W Y d }~d S d }~ww )Nz6'assert True' should not have raised an AssertionErrorz;'assert True, msg' should not have raised an AssertionError)AssertionErrorr!   r   r   r   r   r   test_assert  s   zGrammarTests.test_assertFz Won't work if __debug__ is Falsec              
   C   s   zW n t y } z| |jd d W Y d }~n
d }~ww | d zW n t yA } z| t|jd W Y d }~d S d }~ww | d d S )Nr   rb  z%AssertionError not raised by assert 0z+AssertionError not raised by 'assert False')r  r   r   r!   rP   r  r   r   r   test_assert_failures  s   
 z!GrammarTests.test_assert_failuresc                 C   sn   |  dd |  dd |  dd | jtd tddd td	dd W d    d S 1 s0w   Y  d S )
Nassert(x, "msg")zassertion is always trueassert(False, "msg")assert(False,))categoryzassert x, "msg"r:   rW   zassert False, "msg")r   rr   rH   r<   r,   r   r   r   test_assert_syntax_warnings  s   "z(GrammarTests.test_assert_syntax_warningsc              	   C   s  t   t dt ztddd W n ty!   | d Y nw | t tddd W d    n1 s8w   Y  | t tddd W d    n1 sSw   Y  | t tddd W d    n1 snw   Y  W d    d S W d    d S 1 sw   Y  d S )	Nr>   zassert x, "msg" r:   rW   z4SyntaxError incorrectly raised for 'assert x, "msg"'r  r  r  )r(   r)   r*   rH   r<   r   r!   r   r,   r   r   r   ,test_assert_warning_promotes_to_syntax_error  s&   

"z9GrammarTests.test_assert_warning_promotes_to_syntax_errorc                 C   s   	 	 	 	 	 	 	 	 	 d S rc   r   r,   r   r   r   test_if  s   zGrammarTests.test_ifc                 C   s    	 	 	 d}	 d}|  |d d S )Nr   r'   r   r   r   r   r   r   
test_while*  s   zGrammarTests.test_whilec                 C   s   dD ]}qdD ]\}}}q	 G dd d}d}|dD ]}|| }q|dkr+|  d g }d	D ]\}|| q/| |g d d S )
Nr   r   c                   @   r`   )z&GrammarTests.test_for.<locals>.Squaresc                 S   s   || _ g | _d S rc   )maxsofar)r   r  r   r   r   rf   ?  s   
z/GrammarTests.test_for.<locals>.Squares.__init__c                 S   s
   t | jS rc   )rP   r  r,   r   r   r   __len__B  s   
 z.GrammarTests.test_for.<locals>.Squares.__len__c                 S   sZ   d|  kr| j k st tt| j}||kr(| j||  |d }||ks| j| S )Nr   r'   )r  
IndexErrorrP   r  append)r   r  nr   r   r   ro   C  s   

z2GrammarTests.test_for.<locals>.Squares.__getitem__N)r\   r]   r^   rf   r  ro   r   r   r   r   Squares>  s    r  r   r  i  zfor over growing sequence)r   r   r   )r!   r  r   )r   r  r  r  r  r  r   resultr   r   r   test_for9  s   


zGrammarTests.test_forc              
   C   s  zdd  W n	 t y   Y nw 	 zdd  W n ty    Y n ty1 } zW Y d }~n
d }~w   Y n	 zdd  W n ttt fyI   Y nw zdd  W n ttt fye } zW Y d }~nd }~ww zW nw | t tddd tddd W d    d S 1 sw   Y  d S )Nr'   r   z/try:
    pass
except Exception as a.b:
    pass?rW   z0try:
    pass
except Exception as a[b]:
    pass)r   EOFErrorr6  r   r   r<   )r   rb  r   r   r   test_tryT  s0   
  "zGrammarTests.test_tryc                 C   s   	 	 	 	 	 	 	 d S rc   r   r,   r   r   r   
test_suitem  s   zGrammarTests.test_suitec                 C   s   	 	 	 	 	 	 d S rc   r   r,   r   r   r   	test_test|  s   zGrammarTests.test_testc                 C   s   	 ddk}ddkr	ddkrddk rddkrddkrddkr||u r!||ur%ddv r)ddvr-dd  k r_d  kr_d  kr_d  kr_d  kr_d  kr_d  v r_|  vr_|  u r_|uren d S 	 d S d S r  r   r   r   r   r   test_comparison  s   tzGrammarTests.test_comparisonc                    s   d fdd	}|d |d |d |d |dd	 t  ' t d
t tddd tddd tddd tddd W d    d S 1 sJw   Y  d S )NrC   c                    s     | | d S rc   r   )r=   rb  r,   r   r   r6        z6GrammarTests.test_comparison_is_literal.<locals>.checkzx is 1zx is "thing"z1 is xzx is y is 1z
x is not 1z"is not" with a literalr>   z	x is Noner:   rW   z
x is Falsez	x is Truezx is ...)rC   r(   r)   r*   rH   r<   r5   r   r,   r   test_comparison_is_literal  s   

"z'GrammarTests.test_comparison_is_literalc                    sn   f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 t  3 t dDt tdEdFdG tdHdFdG tdIdFdG tdJdFdG tdKdFdG tdLdFdG W d    d S 1 s0w   Y  d S )MNc                    s    |   d S rc   r   )r=   rb  r   r   r   r6     r  z2GrammarTests.test_warn_missed_comma.<locals>.checkz-is not callable; perhaps you missed a comma\?z[(1, 2) (3, 4)]z[(x, y) (3, 4)]z[[1, 2] (3, 4)]z[{1, 2} (3, 4)]z[{1: 2} (3, 4)]z[[i for i in range(5)] (3, 4)]z[{i for i in range(5)} (3, 4)]z[(i for i in range(5)) (3, 4)]z![{i: i for i in range(5)} (3, 4)]z[f"{x}" (3, 4)]z[f"x={x}" (3, 4)]z["abc" (3, 4)]z[b"abc" (3, 4)]z[123 (3, 4)]z[12.3 (3, 4)]z[12.3j (3, 4)]z[None (3, 4)]z[True (3, 4)]z[... (3, 4)]z2is not subscriptable; perhaps you missed a comma\?z[{1, 2} [i, j]]z[{i for i in range(5)} [i, j]]z[(i for i in range(5)) [i, j]]z[(lambda x, y: x) [i, j]]z[123 [i, j]]z[12.3 [i, j]]z[12.3j [i, j]]z[None [i, j]]z[True [i, j]]z[... [i, j]]zKindices must be integers or slices, not tuple; perhaps you missed a comma\?z[(1, 2) [i, j]]z[(x, y) [i, j]]z[[1, 2] [i, j]]z[[i for i in range(5)] [i, j]]z[f"{x}" [i, j]]z[f"x={x}" [i, j]]z["abc" [i, j]]z[b"abc" [i, j]]z.indices must be integers or slices, not tuple;z[[1, 2] [3, 4]]z-indices must be integers or slices, not list;z[[1, 2] [[3, 4]]]z [[1, 2] [[i for i in range(5)]]]z,indices must be integers or slices, not set;z[[1, 2] [{3, 4}]]z [[1, 2] [{i for i in range(5)}]]z-indices must be integers or slices, not dict;z[[1, 2] [{3: 4}]]z#[[1, 2] [{i: i for i in range(5)}]]z2indices must be integers or slices, not generator;z [[1, 2] [(i for i in range(5))]]z1indices must be integers or slices, not function;z[[1, 2] [(lambda x, y: x)]]z,indices must be integers or slices, not str;z[[1, 2] [f"{x}"]]z[[1, 2] [f"x={x}"]]z[[1, 2] ["abc"]]z'indices must be integers or slices, notz[[1, 2] [b"abc"]]z[[1, 2] [12.3]]z[[1, 2] [12.3j]]z[[1, 2] [None]]z[[1, 2] [...]]r>   z[(lambda x, y: x) (3, 4)]r:   rW   z[[1, 2] [i]]z[[1, 2] [0]]z[[1, 2] [True]]z[[1, 2] [1:2]]z[{(1, 2): 3} [i, j]]r  r5   r   r  r   test_warn_missed_comma  s   
$z#GrammarTests.test_warn_missed_commac                 C   s   d}d}d}d S )Nr'   r   r   r   r   r   r   test_binary_mask_ops     z!GrammarTests.test_binary_mask_opsc                 C   s   d}d}d}d S )Nr   r   r'   r   r   r   r   r   test_shift_ops   r  zGrammarTests.test_shift_opsc                 C   s   d}d}d}d}d S )Nr'   r   r>  r   r   r   r   r   test_additive_ops     zGrammarTests.test_additive_opsc                 C   s   d}d}d}d}d S )Nr'         ?r   g        r   r   r   r   r   test_multiplicative_ops  r  z$GrammarTests.test_multiplicative_opsc                 C   s   d}d}d}d}d}d S )Nr'   r>  r  r   r   r   r   r   test_unary_ops  s
   zGrammarTests.test_unary_opsc           	      C   s   dd l }dd l}|jd }| }|jd  }d}|d }|d }|dd }|d d }|dd  }|d d  }|dd  }|d d }|dd }i }d	|d	< d
|d< d|d< d|d< t|}|jdd d | t|d d S )Nr   r  Z01234r>  ru   r'   r   r   r   r   r   r   c                 S   s   t | j| fS rc   )r   r\   r   r   r   r   r   3  r	  z-GrammarTests.test_selectors.<locals>.<lambda>r   z[1, (1,), (1, 2), (1, 2, 3)])r   r  r  modulesr|   sortr   rX   )	r   r   r  r   r   r   r"   r   Lr   r   r   test_selectors  s,   
zGrammarTests.test_selectorsc                 C   s   d}d}dddf}g }dg}dg}dddg}g }i }ddi}ddi}ddi}ddd}ddd}dddddd	d
}dh}ddh}h d}h d}|}d}d}d S )Nr'   r   r   ry   r   )ry   r   r   ru   r   )ry   r   threeZfourZfiveZsix>   r   r  ry   >   r   r   r   r   r   r   r   r   r   r   
test_atoms6  s,   



zGrammarTests.test_atomsc                    s  G dd d}G dd d}G dd d|}G dd d|}G d	d
 d
|||}G dd d}dd   G dd d} G dd d}  }	G dd d}
 fddG dd d}d dgd G dd d}   G dd d} gd  j j G d!d" d"}d S )#Nc                   @   r   )z%GrammarTests.test_classdef.<locals>.BNr   r   r   r   r   r   [  r  r   c                   @   r   )z&GrammarTests.test_classdef.<locals>.B2Nr   r   r   r   r   B2\  r  r  c                   @   r   )z&GrammarTests.test_classdef.<locals>.C1Nr   r   r   r   r   C1]  r  r  c                   @   r   )z&GrammarTests.test_classdef.<locals>.C2Nr   r   r   r   r   C2^  r  r  c                   @   r   )z%GrammarTests.test_classdef.<locals>.DNr   r   r   r   r   r   _  r  r   c                   @   r`   )z%GrammarTests.test_classdef.<locals>.Cc                 S   r   rc   r   r,   r   r   r   meth1a  r   z+GrammarTests.test_classdef.<locals>.C.meth1c                 S   r   rc   r   )r   argr   r   r   meth2b  r   z+GrammarTests.test_classdef.<locals>.C.meth2c                 S   r   rc   r   )r   r   r   r   r   r   meth3c  r   z+GrammarTests.test_classdef.<locals>.C.meth3N)r\   r]   r^   r  r  r  r   r   r   r   r   `  s    r   c                 S   r   rc   r   r   r   r   r   class_decoratorh  r   z3GrammarTests.test_classdef.<locals>.class_decoratorc                   @   r   )z%GrammarTests.test_classdef.<locals>.GNr   r   r   r   r   Gi  r   r  Fc                   @   r   )z%GrammarTests.test_classdef.<locals>.HNr   r   r   r   r   Hm  r   r  c                   @   r   )z%GrammarTests.test_classdef.<locals>.INr   r   r   r   r   Io  r   r  c                    r  rc   r   )r   r  r   r   r   q  r!  z,GrammarTests.test_classdef.<locals>.<lambda>c                   @   r   )z%GrammarTests.test_classdef.<locals>.JNr   r   r   r   r   Jq  r   r  .r'   c                   @   r   )z%GrammarTests.test_classdef.<locals>.KNr   r   r   r   r   Ks  r   r  c                   @   r   )z%GrammarTests.test_classdef.<locals>.LNr   r   r   r   r   r  u  r   r  r   c                   @   r   )z%GrammarTests.test_classdef.<locals>.MNr   r   r   r   r   r   w  r   r   )r7  )r   r   r  r  r  r   r   r  r  r   r  r  r  r  r   r   r  r   test_classdefY  s*   

zGrammarTests.test_classdefc                 C   s*   g d}|  dd |D dddd d S )Nr   c                 S   s   i | ]}||d  qS r   r   r;  r  r   r   r   
<dictcomp>  s    z/GrammarTests.test_dictcomps.<locals>.<dictcomp>r   r   r   r   )r   numsr   r   r   test_dictcompsz  s   "zGrammarTests.test_dictcompsc              	      sZ  g d}g dg d} dd |D g d  dd |D g d  d	d |D g d
  fdd|D g d  fdd|D g d  dd tdD dgddgg dg dg dg dd } ||g d fdd}|  td td g d}g d g d fdd|D } |g d  d S )!Nr   )AppleBananaCoconut)z  Applez Banana zCoco  nut  c                 S   s   g | ]}|  qS r   )strip)r;  r"   r   r   r   r<    r=  z/GrammarTests.test_listcomps.<locals>.<listcomp>)r  r  z	Coco  nutc                 S   s   g | ]}d | qS r   r   r:  r   r   r   r<    r=  )r   r   r   r     c                 S   s   g | ]}|d kr|qS r   r   r:  r   r   r   r<        r   c                    s   g | ]} D ]}||fqqS r   r   r;  r  r"   strsr   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  )ru   r  ru   r  ru   r  c                    s(   g | ]}d d  D D ]}||fqqS )c                 S   s   g | ]}d |v r|qS )r  r   )r;  r   r   r   r   r<    r  z:GrammarTests.test_listcomps.<locals>.<listcomp>.<listcomp>r   r  r  r   r   r<    s   ( )
r  r  r  r  r  r  r  r  r  r  c                 S   s   g | ]}d d |qS )c                    s    fddt  d D S )Nc                    s   g | ]} | qS r   r   r  r   r   r   r<    r=  zLGrammarTests.test_listcomps.<locals>.<listcomp>.<lambda>.<locals>.<listcomp>r'   ranger   r   r   r   r     s    z8GrammarTests.test_listcomps.<locals>.<listcomp>.<lambda>r   )r;  r  r   r   r   r<    r  ru   r'   )r'   r   r   )r'   r   r      )r'   r      @      c                 S   s   dd | D S )Nc                 S   s,   g | ]}|d krd|  k odk n  qS )r   r   r   r   r:  r   r   r   r<    s   , zEGrammarTests.test_listcomps.<locals>.test_in_func.<locals>.<listcomp>r   )lr   r   r   test_in_func  r   z1GrammarTests.test_listcomps.<locals>.test_in_func)FFFc                      s,     dd dD ddgddgdd	gg d S )
Nc                 S   s"   g | ]}d d ||d fD qS )c                 S   r  r   r   r;  rS   r   r   r   r<    r  zUGrammarTests.test_listcomps.<locals>.test_nested_front.<locals>.<listcomp>.<listcomp>r'   r   r:  r   r   r   r<       " zJGrammarTests.test_listcomps.<locals>.test_nested_front.<locals>.<listcomp>)r'   r   ru   r'   r   r   r   ru   r   r   r   r,   r   r   test_nested_front  s   z6GrammarTests.test_listcomps.<locals>.test_nested_frontz"[i, s for i in nums for s in strs]z[x if y]))r'   Boeing)r   Ford)r   
Macdonalds))r  Airliner)rC  Engine)   Cheeseburger))r'   r  )r'   rC  )r   rC  )r   r  c                    sD   g | ]\}} D ]\}}D ]\}}||kr||kr||fqqqS r   r   )r;  ZsnoZsnameZpnoZpnameZsp_snoZsp_pno)partssuppartr   r   r<    s    
))r  r  )r  r  )r  r  )r  r  )r   r  r   )r   r  Zspcsr  r  Z	suppliersr   r   )r   r   r  r  r   test_listcomps  s8   

zGrammarTests.test_listcompsc                    s  dd t dD }| t|dd t dD  zt| | d W n	 ty,   Y nw d z fdd D }t| | d	 W n	 tyL   Y nw | td
d dD dd dD  | tdd dD dd dD  dd t dD  dd dd  D D }| t|tdd t dD  | tdd t dD tdd t dD  | tdd t dD tdd t dD  | tdd dd t dD D tdd t dD  | tdd dd dd t dD D D tdd t dD  | tdd d d d!d t dD D D td"d t dD  | td#d d$d d%d t dD D D td&d t dD  | td'd d(d d)d t dD D D d* t| d+ t| d, d S )-Nc                 s   s"    | ]}d d t dD V  qdS )c                 S   r  r   r   r:  r   r   r   r<    r  z7GrammarTests.test_genexps.<locals>.<genexpr>.<listcomp>r  Nr  r:  r   r   r   	<genexpr>       z,GrammarTests.test_genexps.<locals>.<genexpr>r'   c                 S   r  r   r   r:  r   r   r   r<    r  z-GrammarTests.test_genexps.<locals>.<listcomp>r  z&should produce StopIteration exceptionc                 3   s    | ]} V  qd S rc   r   )r;  r   r   r   r   r    r  zshould produce TypeErrorc                 s   "    | ]}d D ]}||fV  qqdS )r[  Nr   r;  r   rS   r   r   r   r    r  r[  c                 S      g | ]}d D ]}||fqqS )r[  r   r  r   r   r   r<    r  c                 s   r  )xyNr   r  r   r   r   r    r  abc                 S   r  )r  r   r  r   r   r   r<    r  c                 S   r  r   r   r:  r   r   r   r<    r  c                 s       | ]}|V  qd S rc   r   r:  r   r   r   r    r  c                 s   r
  rc   r   r  r   r   r   r    r  c                 S   r  r   r   r:  r   r   r   r<    r  c                 s   s    | ]}|d  V  qdS r   Nr   r:  r   r   r   r    r  c                 S   s   g | ]}|d  qS r   r   r:  r   r   r   r<    r=  c                 s   s     | ]}|d  r|| V  qdS r  r   r:  r   r   r   r    s    c                 S   s   g | ]
}|d  r|| qS r   r   r:  r   r   r   r<        c                 s   r
  rc   r   r:  r   r   r   r    r  c                 s   r
  rc   r   r  r   r   r   r    r  c                 S   r  r   r   r:  r   r   r   r<    r  c                 s   r
  rc   r   r:  r   r   r   r    r  c                 s   r
  rc   r   r  r   r   r   r    r  c                 s   r
  rc   r   r;  r   r   r   r   r    r  c                 S   r  r   r   r:  r   r   r   r<    r  c                 s   r
  rc   r   r:  r   r   r   r    r  c                 S   r  r   r   r  r   r   r   r<    r  c                 s   r
  rc   r   r  r   r   r   r    r  c                 S   r  r   r   r:  r   r   r   r<    r  c                 s       | ]}|V  qdS TNr   r:  r   r   r   r    r  c                 s   r
  rc   r   r  r   r   r   r    r  c                 s   r  r  r   r  r   r   r   r    r  c                 S   r  r   r   r:  r   r   r   r<    r  c                 s   r  r  r   r:  r   r   r   r    r  c                 s   s    | ]}qdS )FNr   r  r   r   r   r    s    c                 s   r  r  r   r  r   r   r   r    r  r   zfoo(x for x in range(10), 100)zfoo(100, x for x in range(10)))	r  r   nextr!   StopIterationr6  r|   sumr   )r   r  r   r   r   r   test_genexps  s<   $$"00:DDD2
zGrammarTests.test_genexpsc                    s   ddd t D }d| tt|d dd  fddt D }dd | dd	 t dD t| | d
d	 t dD g d | tdd t dD g d | dd	 dD g d | tdd dD g d d S )Nr  c                 s   r
  rc   r   r  r   r   r   r    r  z;GrammarTests.test_comprehension_specials.<locals>.<genexpr>ru   Fc                 3   s*    | ]} rt D ]}||fV  q
qd S rc   r  r;  r  r  tr   r   r   r    s   ( Tc                 S   s"   g | ]}t d D ]}||fqqS ru   r  r  r   r   r   r<    r  z<GrammarTests.test_comprehension_specials.<locals>.<listcomp>c                 S   s    g | ]}|d  r|d r|qS r   r   r:  r   r   r   r<    s     )r'   ru   r   c                 s   s$    | ]}|d  r|d r|V  qdS )r   r   Nr   r:  r   r   r   r    s   " c                 S   s   g | ]\}|qS r   r   r:  r   r   r   r<    s    ))r   r  )r   r  c                 s   s    | ]\}|V  qd S rc   r   r:  r   r   r   r    r  ))r   )r   )r   )r   r   r   )r  r   rP   r|   r  r   r  r   test_comprehension_specials  s    ""z(GrammarTests.test_comprehension_specialsc              
   C   s  G dd dt }|  W d    n1 sw   Y  | }W d    n1 s)w   Y  | 
\}}W d    n1 s>w   Y  |  |  W d    n1 sUw   Y  W d    n1 sdw   Y  | }| }W d    n1 s{w   Y  W d    n1 sw   Y  | }|  W d    n1 sw   Y  W d    n1 sw   Y  |  W d    n1 sw   Y  | }W d    n1 sw   Y  | \}}| }W d    n1 sw   Y  W d    n1 sw   Y  |  |  W d    n	1 sw   Y  W d    n	1 s&w   Y  | }| }W d    n	1 s>w   Y  W d    n	1 sNw   Y  | }|  W d    n	1 sfw   Y  W d    n	1 svw   Y  | 0}| }| }W d    n	1 sw   Y  W d    n	1 sw   Y  W d    n	1 sw   Y  | 9}| }|  W d    n	1 sw   Y  W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nc                   @      e Zd Zdd Zdd ZdS )z1GrammarTests.test_with_statement.<locals>.managerc                 S   rw   Nr   r   r,   r   r   r   	__enter__  rz   z;GrammarTests.test_with_statement.<locals>.manager.__enter__c                 W   r   rc   r   )r   r   r   r   r   __exit__  rz   z:GrammarTests.test_with_statement.<locals>.manager.__exit__N)r\   r]   r^   r  r  r   r   r   r   manager      r  )object)r   r  r   rS   r   r   r   r   test_with_statement  s            T z GrammarTests.test_with_statementc                 C   s  dd }|  dd dd dd fD dg |  d	d d
d dd fD dg |  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 S )Nc                 S   s   	 t |  |S rc   r   )rb  retr   r   r   
_checkeval<  s   z2GrammarTests.test_if_else_expr.<locals>._checkevalc                 S   s   g | ]}| r| qS r   r   r:  r   r   r   r<  C  r  z2GrammarTests.test_if_else_expr.<locals>.<listcomp>c                   S   rw   )NTr   r   r   r   r   r   C  r   z0GrammarTests.test_if_else_expr.<locals>.<lambda>c                   S   rw   NFr   r   r   r   r   r   C  r   Tc                 S   s   g | ]
}|d r|d qS rF   r   r:  r   r   r   r<  D  r  c                 S      | rdS dS )NFTr   r   r   r   r   r   D  r  c                 S   r$  )NTFr   r   r   r   r   r   D  r  r'   ru   zcheck 1r   zcheck 2r   zcheck 3r   r   zcheck 4zcheck 5zcheck 6Fr   r  r   g      @r   )r   r"  r   r   r   test_if_else_expr:  s$   $$zGrammarTests.test_if_else_exprc                 C   sx   |  dd |  dd |  dd d}d}| d||u u  | d|u |u  | d|  u o6|u  d S    d S )Nr   r   r   F)r   r   ZassertFalserR   r   r   r   test_paren_evaluationU  s   (z"GrammarTests.test_paren_evaluationc                 C   s>   G dd d}| }|  || d |d }|  |jd d S )Nc                   @   r  )z'GrammarTests.test_matrix_mul.<locals>.Mc                 S   rw   )Nr   r   r   r   r   r   r   
__matmul__c  rz   z2GrammarTests.test_matrix_mul.<locals>.M.__matmul__c                 S   s
   || _ | S rc   )otherr'  r   r   r   __imatmul__e  s   z3GrammarTests.test_matrix_mul.<locals>.M.__imatmul__N)r\   r]   r^   r(  r*  r   r   r   r   r   b  r  r   r   rv   )r   r)  )r   r   mr   r   r   test_matrix_mul_  s
   zGrammarTests.test_matrix_mulc                 C   sx   dd }|  |jd | t|jjtj@  dd }|dd }| |j |  |jd | t|jjtj@  d S )	Nc                     s   dd } 	 t  I d H  d S )Nc                   S   r   rc   r   r   r   r   r   r  o  rz   z8GrammarTests.test_async_await.<locals>.test.<locals>.sum)Zsomeobj)r  r   r   r   r=   n  s   z+GrammarTests.test_async_await.<locals>.testr=   c                 S   s   t | dd | S )N_markedT)setattr)funcr   r   r   	decoratorw  s   z0GrammarTests.test_async_await.<locals>.decoratorc                         dS )N   r   r   r   r   r   test2{  s   z,GrammarTests.test_async_await.<locals>.test2r3  )	r   r\   r   boolr3  co_flagsinspectZCO_COROUTINEr-  )r   r=   r0  r3  r   r   r   test_async_awaitm  s   
zGrammarTests.test_async_awaitc                    sh   G dd dt G dd d  fdd}|  | d  W d    d S 1 s-w   Y  d S )Nc                   @   r   )z)GrammarTests.test_async_for.<locals>.DoneNr   r   r   r   r   Done  r  r8  c                   @   r  )z*GrammarTests.test_async_for.<locals>.AIterc                 S   r   rc   r   r,   r   r   r   	__aiter__  rz   z4GrammarTests.test_async_for.<locals>.AIter.__aiter__c                    s   t rc   )StopAsyncIterationr,   r   r   r   	__anext__     z4GrammarTests.test_async_for.<locals>.AIter.__anext__N)r\   r]   r^   r9  r;  r   r   r   r   AIter  r  r=  c                     sN     2 z3 d H W } q6   2 z3 d H W \} }q6   2 z3 d H W } q6 	 rc   r   r  r=  r8  r   r   rO    s   z(GrammarTests.test_async_for.<locals>.foor   r   sendr   rO  r   r>  r   test_async_for  s   "zGrammarTests.test_async_forc                    sh   G dd dt  G dd d fdd}|   | d  W d    d S 1 s-w   Y  d S )Nc                   @   r   )z*GrammarTests.test_async_with.<locals>.DoneNr   r   r   r   r   r8    r  r8  c                   @   r  )z-GrammarTests.test_async_with.<locals>.managerc                    r1  r  r   r,   r   r   r   
__aenter__  r<  z8GrammarTests.test_async_with.<locals>.manager.__aenter__c                    r1  r#  r   )r   excr   r   r   	__aexit__  r<  z7GrammarTests.test_async_with.<locals>.manager.__aexit__N)r\   r]   r^   rC  rE  r   r   r   r   r    r  r  c               
      s   4 I d H  W d   I d H  n1 I d H sw   Y   4 I d H } W d   I d H  n1 I d H s6w   Y   4 I d H \} }W d   I d H  n1 I d H sUw   Y   4 I d H (  4 I d H  W d   I d H  n1 I d H szw   Y  W d   I d H  n1 I d H sw   Y   4 I d H (}  4 I d H }W d   I d H  n1 I d H sw   Y  W d   I d H  n1 I d H sw   Y   4 I d H )}  4 I d H  W d   I d H  n1 I d H sw   Y  W d   I d H   1 I d H sw   Y   rc   r   r  r8  r  r   r   rO    s,   ((( R R :z)GrammarTests.test_async_with.<locals>.foor?  rA  r   rF  r   test_async_with  s   "zGrammarTests.test_async_withN)Lr\   r]   r^   r_   r   test.support.warnings_helperr   rr   rs   r}   r~   r   r   r   r   r   r   r   r   r   r8  rN  rP  rS  rZ  r\  r]  r_  rc  rf  rj  rn  ro  rr  rv  rx  r  r  r  r  r  r  r  unittestZ
skipUnlessr  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,  r7  rB  rG  r   r   r   r   rq   8  s    .		 y'45'

R#!?#D
rq   __main__)r_   r   r   rH  r   r6  rI  r   r(   Ztest.ann_moduler   r   collectionsr   r=   r	   r0   r2   ZTestCaser   r{   r   ra   rq   r\   mainr   r   r   r   <module>   sH   7 D	             
