o
    gs                     @   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   G/Users/admin/.pyenv/versions/3.10.0/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                    sX   fdd} 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 t  . t dt |d |d |d  |d! |d" |d# |d$ |d% W d    n1 sw   Y  |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 d S )GNc                    s<     t t| dd W d    d S 1 sw   Y  d S )N
<testcase>r   )ZassertWarnsr+   compiletestr,   r   r   r6      s   "z8TokenTests.test_end_of_numerical_literals.<locals>.checkc              	      sr   t jdd#} t t| dd W d    n1 sw   Y  W d    n1 s,w   Y   |g  d S )NT)recordr8   r   )r(   r)   r   r   r9   r   )r;   wr,   r   r   check_error   s   z>TokenTests.test_end_of_numerical_literals.<locals>.check_errorz0xfand xz0o7and xz0b1and xz9and xz0and xz1.and xz1e3and xz1jand xz0xfor xz0o7or xz0b1or xz9or xz0or xz1.or xz1e3or xz1jor xz0xfin xz0o7in xz0b1in xz9in xz0in xz1.in xz1e3in xz1jin xr&   z0xfis xz0o7is xz0b1is xz9is xz0is xz1.is xz1e3is xz1jis xz0xfif x else yz0o7if x else yz0b1if x else yz9if x else yz0if x else yz1.if x else yz1e3if x else yz1jif x else yzx if 0xfelse yzx if 0o7else yzx if 0b1else yzx if 9else yzx if 0else yzx if 1.else yzx if 1e3else yzx if 1jelse yz[0x1ffor x in ()]z[0x1for x in ()]z[0xfor x in ()]z[0o7for x in ()]z[0b1for x in ()]z[9for x in ()]z[1.for x in ()]z[1e3for x in ()]z[1jfor x in ()]Z0xfspamZ0o7spamZ0b1spamZ9spamZ0spamz1.spamZ1e3spamZ1jspam)r(   r)   r*   SyntaxWarning)r   r6   r>   r   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_ellipsisV  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   r9   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   r@   rJ   rL   rQ   r   r   r   r   r   h   s    
$
V(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__g     
zCNS.__init__c                 C   s   || j | < d S rY   )r[   lowerr   itemvaluer   r   r   __setitem__i  s   zCNS.__setitem__c                 C   
   | j | S rY   rZ   r   r`   r   r   r   __getitem__k  r]   zCNS.__getitem__NrR   rS   rT   r\   rb   re   r   r   r   r   rW   f  s    rW   c                   @   sD  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)e*+dIdJdKdL Z,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 ZJdS )GrammarTestsr   r   r   )check_no_warningsc                 C   s   t d}d S )Nz	1, 0 or 1)r   r   r   r   r   test_eval_input~     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   one     z/GrammarTests.test_var_annot_basics.<locals>.oner   r'   )intlistr   )r   Zvar1Zmy_lstro   r   r   r   test_var_annot_basics  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_errors  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   f  s   z6GrammarTests.test_var_annot_basic_semantics.<locals>.fc                   S      d S rY   r   r   r   r   r   f_OK      z9GrammarTests.test_var_annot_basic_semantics.<locals>.f_OKc                  S   s   t |  d S rY   printr   r   r   r   fbad  rj   z9GrammarTests.test_var_annot_basic_semantics.<locals>.fbadc                   S   s   t t d S rY   )r   Zno_such_globalr   r   r   r   f2bad  rj   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 rY   r   r   r   r   r   r\     r]   z?GrammarTests.test_var_annot_basic_semantics.<locals>.C.__init__N)	rR   rS   rT   rq   __annotations__r"   rN   zr\   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)rR   rS   rT   Zno_such_name_definedr   rq   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)rR   rS   rT   rq   r   r   rI   rr   r   r   r   r   Cbad2  s   
 r   )r   ZeroDivisionErrorZno_nameZdoes_not_existr3   r   r   UnboundLocalError	ExceptionZassertIsr   rq   rN   )	r   rz   r|   r   r   er   r   r   r   r   r   test_var_annot_basic_semantics  s:   

"z+GrammarTests.test_var_annot_basic_semanticsc                 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   )rW   )metaclsnamebaseskwdsr   r   r   __prepare__     
zJGrammarTests.test_var_annot_metaclass_semantics.<locals>.CMeta.__prepare__N)rR   rS   rT   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)rR   rS   rT   r   r   r   r   r   CC  s   
 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   rI   rz   u{   )Z123o)r   r;   r   
ann_modulerq   rN   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_module3rk   )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   )rM   r   rq   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   rX   rY   rZ   r,   r   r   r   r\     r]   z>GrammarTests.test_var_annot_custom_maps.<locals>.CNS2.__init__c                       || j |< | |< d S rY   rZ   r_   	nonloc_nsr   r   rb        
zAGrammarTests.test_var_annot_custom_maps.<locals>.CNS2.__setitem__c                 S   rc   rY   rZ   rd   r   r   r   re     r]   zAGrammarTests.test_var_annot_custom_maps.<locals>.CNS2.__getitem__Nrf   r   r   r   r   CNS2  s    r   z
x: int = 1)rW   rM   r   rq   rN   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   rZ   r,   )cnsr   r   r\        z:GrammarTests.test_var_annot_refleak.<locals>.CNS2.__init__c                    r   rY   rZ   r_   r   r   r   rb     r   z=GrammarTests.test_var_annot_refleak.<locals>.CNS2.__setitem__c                 S   rc   rY   rZ   rd   r   r   r   re     r]   z=GrammarTests.test_var_annot_refleak.<locals>.CNS2.__getitem__Nrf   r   r   r   r   r   r     s    r   zX: strr   )rW   rM   r   rN   )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   ru   zdef f():
    x: int = yieldrz   r'   r         rk   )rw   rx   cr   zx: Tuple[int, ...] = a,*b,cr'   r   r   r   rk   )rM   r   rr   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{   rY   r   r   r   r   r   f15  r}   z%GrammarTests.test_funcdef.<locals>.f1r   c                 S   r{   rY   r   Zone_argumentr   r   r   f29  r}   z%GrammarTests.test_funcdef.<locals>.f2c                 S   r{   rY   r   twoZ	argumentsr   r   r   f3:  r}   z%GrammarTests.test_funcdef.<locals>.f3r   r   c                 S   r{   rY   r   )Zone_argr   r   r   a1=  r}   z%GrammarTests.test_funcdef.<locals>.a1c                 S   r{   rY   r   )r   argsr   r   r   a2>  r}   z%GrammarTests.test_funcdef.<locals>.a2c                  W   r{   rY   r   restr   r   r   v0?  r}   z%GrammarTests.test_funcdef.<locals>.v0c                 W   r{   rY   r   rw   r   r   r   r   v1@  r}   z%GrammarTests.test_funcdef.<locals>.v1c                 W   r{   rY   r   rw   rx   r   r   r   r   v2A  r}   z%GrammarTests.test_funcdef.<locals>.v2r'   r   r   r   rk            r   r   c                 S   r{   rY   r   rw   r   r   r   d01W  r}   z&GrammarTests.test_funcdef.<locals>.d01r'   rw   c                 S   r{   rY   r   rv   r   r   r   d11_  r}   z&GrammarTests.test_funcdef.<locals>.d11rx   c                 S   r{   rY   r   rw   rx   r   r   r   r   d21c  r}   z&GrammarTests.test_funcdef.<locals>.d21r'   r   r   r   r   r   r   c                 S   r{   rY   r   rv   r   r   r   d02j  r}   z&GrammarTests.test_funcdef.<locals>.d02ru   r   rv   c                 S   r{   rY   r   r   r   r   r   d12r  r}   z&GrammarTests.test_funcdef.<locals>.d12c                 S   r{   rY   r   rw   rx   r   dr   r   r   d22v  r}   z&GrammarTests.test_funcdef.<locals>.d22c                 W   r{   rY   r   r   r   r   r   d01vz  r}   z'GrammarTests.test_funcdef.<locals>.d01v)r'   r   r   r   c                 W   r{   rY   r   r   r   r   r   d11v  r}   z'GrammarTests.test_funcdef.<locals>.d11vc                 W   r{   rY   r   rw   rx   r   r   r   r   r   d21v  r}   z'GrammarTests.test_funcdef.<locals>.d21vc                 W   r{   rY   r   r   r   r   r   d02v  r}   z'GrammarTests.test_funcdef.<locals>.d02vr   c                 W   r{   rY   r   r   r   r   r   d12v  r}   z'GrammarTests.test_funcdef.<locals>.d12vr   r   rk   c                 W   r{   rY   r   )rw   rx   r   r   r   r   r   r   d22v  r}   z'GrammarTests.test_funcdef.<locals>.d22vr   r&   r   s   fooz/Bytes should not work as keyword argument namesc                 S      | S rY   r   keyr   r   r   pos0key1  r}   z+GrammarTests.test_funcdef.<locals>.pos0key1d   r   )k2c                S   s   | |||fS rY   r   )p1p2k1r   r   r   r   pos2key2      z+GrammarTests.test_funcdef.<locals>.pos2key2)r      )r   r   )r   r   c                [   s   | ||||fS rY   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 rY   r   )r   kwargsr   r   r   rz     s   z$GrammarTests.test_funcdef.<locals>.fr   rI   )r'   r   r   zf(1, x=2, *(3,4), x=5)Z	scrambledZfried)eggsspamr   r   z
f(*g(1=2))zf(**g(1=2))returnc                 S   r{   rY   r   r   r   r   r   rz     r}   c                 S   r{   rY   r   r   r   r   r   rz     r}   c                S   r{   rY   r   r   r   r   r   rz     r}   rD   c                S   r{   rY   r   r   r   r   r   rz     r}   c                  W   r{   rY   r   r   r   r   r   rz     r}   c                  [   r{   rY   r   r   r   r   r   rz     r}   rI   c                 S   r{   rY   r   r   r   r   r   rz     r}   c                S   r{   rY   r   r   r   r   r   rz     r}   c                 S   r{   rY   r   r   r   r   r   rz     r}   )rx   r   c                S   r{   rY   r   r   r   r   r   rz     r}   r   gc                 W   r{   rY   r   )rw   rx   r   r   r   rz   r   r   r   r   rz     r}   )rx   r   r   r   
   ijhr   k      c                _   r{   rY   r   rw   rx   r   r   r   rz   r   r   r   r   r   r   r   r   rz     rp   )rx   r   r   r   r   r   r   r   rz   c               _   r{   rY   r   r  r   r   r   rz     rp   )	rx   r   r   rz   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{   rY   r   )r   r  r   r   r   rz     rp   z)GrammarTests.test_funcdef.<locals>.Spam.fN)r  r'   )rR   rS   rT   rz   r   r   r   r   Spam  s    r  c                   @      e Zd ZdS )z&GrammarTests.test_funcdef.<locals>.HamNrR   rS   rT   r   r   r   r   Ham  r   r  r  c                 S   r   rY   r   r   r   r   r   null  r}   z'GrammarTests.test_funcdef.<locals>.nullc                 S   r{   rY   r   r   r   r   r   rz     rp   Fc                 S   r{   rY   r   r   r   r   r   rz     rp   c                 S   r{   rY   r   r   r   r   r   rz     rp   c                        | S rY   r   rz   )r	  r   r   <lambda>      z+GrammarTests.test_funcdef.<locals>.<lambda>c                 S   r{   rY   r   r   r   r   r   rz     rp   .c                 S   r{   rY   r   r   r   r   r   rz     rp   c                 S   r{   rY   r   r   r   r   r   rz     rp   c                 S   r{   rY   r   r   r   r   r   rz     rp   c                          S rY   r   r   closurer   r   rz   
  r}   c                    r  rY   r   r   r  r   r   rz     r}   r   c                    r  rY   r   r  r  r   r   rz     r}   c                      r  rY   r   r   r  r   r   rz     r}   c                 S   r{   rY   r   r   r   r   r   rz     r}   c                  W   r{   rY   r   r   r   r   r   rz     r}   c                  [   r{   rY   r   r   r   r   r   rz     r}   c                 W   r{   rY   r   rw   r   r   r   r   rz     r}   c                 [   r{   rY   r   rw   r   r   r   r   rz     r}   c                 W   r{   rY   r   rx   r   r   r   r   rz     r}   c                 S   r{   rY   r   rx   r   r   r   rz     r}   c                  _   r{   rY   r   r   r   r   r   r   rz     r}   c                W   r{   rY   r   rw   rx   r   r   r   r   rz     r}   c                S   r{   rY   r   rv   r   r   r   rz     r}   c                 _   r{   rY   r   rw   r   r   r   r   r   rz     r}   c                 _   r{   rY   r   rx   r   r   r   r   r   rz     r}   c                 [   r{   rY   r   rx   r   r   r   r   rz     r}   c                _   r{   rY   r   rw   rx   r   r   r   r   r   rz     r}   c                [   r{   rY   r   rw   rx   r   r   r   r   rz     r}   r   )rD   )rI   r   )rx   r'   r   r   )r   r   rx   r'   )r   rk   )rx   r'   r   r   r   r   r   r   )rx   r'   r   r   r   r   r   r   r   r   r   r   r   r  r   r  )r   __code__co_varnamesr(   r)   r*   BytesWarningrN   	TypeErrorr!   r   r   r   r   rr   r   rq   r   rz   __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   rz   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   rm   Nr   r   r   r   r   r   r  "  r}   z+GrammarTests.test_lambdef.<locals>.<lambda>r   c                   S   s   t t S rY   )rw   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   rY   r   r   r   r   r   r  '  r}   c                 S      |  S rY   r   )rI   r   r   r   r  '      c                 S   r,  rY   r   r   r   r   r   r  '  r-  r   c                 S      | | | S rY   r   )r   rI   r   r   r   r   r  )  r   rk   r   r   zlambda x: x = 2zlambda (None,): None   r  c                S   r.  rY   r   )r   rI   r   r   r   r   r  .  r      r      c                 S   rm   r%  r   r   r   r   r   r  3  r}   c                  W   rm   r%  r   r  r   r   r   r  4  r}   c                  [   rm   r%  r   r  r   r   r   r  5  r}   c                 W   rm   r%  r   r  r   r   r   r  6  r}   c                 [   rm   r%  r   r  r   r   r   r  7  r}   c                 W   rm   r%  r   r  r   r   r   r  8  r}   c                 S   rm   r%  r   r  r   r   r   r  9  r}   c                  _   rm   r%  r   r  r   r   r   r  :  r}   c                W   rm   r%  r   r  r   r   r   r  ;  r}   c                S   rm   r%  r   rv   r   r   r   r  <  r}   c                 _   rm   r%  r   r  r   r   r   r  =  r}   c                 _   rm   r%  r   r  r   r   r   r  >  r}   c                 [   rm   r%  r   r  r   r   r   r  ?  r}   c                _   rm   r%  r   r  r   r   r   r  @  r}   c                [   rm   r%  r   r  r   r   r   r  A  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 rn   r   r   r   r   r   fooJ  r   z*GrammarTests.test_simple_stmt.<locals>.foor   )r   r   r;  r   r   r   test_simple_stmtG  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   rI   r   abcrw   rx   r   xyzr   r   r   test_expr_stmtR  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    q1 syw   Y  qqd S )N)r   rM   )z{} fooz{} {{1:foo}}zif 1: {} foozif 1: {} {{1:foo}}zif 1:
    {} foozif 1:
    {} {{1:foo}}zcall to '{}')sourcer;  z(foo.)zinvalid syntax)formatZsubTestZassertRaisesRegexr   rM   r1   )r   keywordscaseskeywordZ
custom_msgcaser@  r   r   r   (test_former_statements_refer_to_builtinsa  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   r>  Zabcdefgabcdr'   r   z-del a, (b[0].c, (d.e, f.g[1:2])), [h.i.j], ()r8   rM   )rr   r9   )r   r=  r   rI   r   r>  rw   rx   r   r   r   rz   r   rG  r   r   r   test_del_stmtx  s    



zGrammarTests.test_del_stmtc                 C   r{   rY   r   r,   r   r   r   test_pass_stmt     zGrammarTests.test_pass_stmtc                 C   r{   rn   r   r,   r   r   r   test_break_stmt  rJ  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 q|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!rM  )Zextra_burning_oilcountZ	big_hippor,   r   r   
test_inner  s   z9GrammarTests.test_break_continue_loop.<locals>.test_inner)r'   r   r   )r   rQ  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{   rY   r   r   r   r   r   g1  r}   z$GrammarTests.test_return.<locals>.g1c                   S   rm   rn   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 1r2  )r   rS  rT  rU  r   rI   r   r   r   test_return  s   zGrammarTests.test_returnc                 C   s4  d}|dk r|d7 }zW q   Y |  |d d}|dk r(|d7 }zW q(   Y |  |d d}|dk rC|d7 }zdd  W qC   Y |  |d dD ]}|  |d zW  q\   Y  |  |d dD ]}|  |d zW  qu   Y  |  |d dD ]}|  |d zdd  W  q   Y  |  |d d S Nr   r   r'   r   r'   r   r   rP  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 rW  r   rY  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 rn   r   r   r   r   r   rS  I     z/GrammarTests.test_return_in_finally.<locals>.g1r'   c                   S   r\  )Nr   r   r   r   r   r   r   rT  P  r]  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   rU  W  s   
z/GrammarTests.test_return_in_finally.<locals>.g3r   r   )r   rS  rT  rU  r   r   r   test_return_in_finallyH  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 q  S | r!   Y qw qd||fS )NrX  r   r/  r   endr   r   rP  Zcount2r   r   r   rS  `  s   

z;GrammarTests.test_break_in_finally_after_return.<locals>.g1Fr   T)r_  r'   r   c              	   S   sL   dD ]}dD ]}z|| W | r  q    S | r   Y  qw qd||fS )NrX  )r   r/  r_  r   r`  r   r   r   rT  n  s   
z;GrammarTests.test_break_in_finally_after_return.<locals>.g2r   r   rS  rT  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'   r_  r   r   rP  r   r   r   rS  |  s   z>GrammarTests.test_continue_in_finally_after_return.<locals>.g1Fr'   T)r_  r   c                 S   s4   dD ]}z	|W | r q  S | r   Y qw d|fS )NrX  r_  r   rc  r   r   r   rT    s   
z>GrammarTests.test_continue_in_finally_after_return.<locals>.g2r   )r_  r'   r   ra  r   r   r   %test_continue_in_finally_after_returnz  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 rn   r   r   r   r   r   r        
 z"GrammarTests.test_yield.<locals>.gc                   s   s    dE d H  d S Nr   r   r   r   r   r   r         c                  s       dV } d S rn   r   r   r   r   r   r     rf  c                  s   s    dE d H } d S rg  r   r   r   r   r   r     rh  c                   s   re  N)r'   r'   r   r   r   r   r   r     rf  c                  s   ri  rj  r   r   r   r   r   r     rf  zdef g(): yield from (), 1zdef g(): x = yield from (), 1c                   s   s    ddV f d S rn   r   r   r   r   r   r     rh  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 rn   r  r   r   r   r   r     rh  c                   s   s    t dV d d S rn   r  r   r   r   r   r     s    c                   s   s    t dE d H  d S rg  r  r   r   r   r   r     rl  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   rk   r   r'   r   r   r   r   r   r   r   r         )r'   r   r   r   rk   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   rr   r   r   r   r   r   
test_yield  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   rs  r   r   r&  r   r   r   r(    rt  ru  r   r   r   r   r   r   r     ro  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{   rY   r   r,   r   r   r   test_global  r}   zGrammarTests.test_globalc                    s   d d fdd}d S )Nr   c                      r{   rY   r   r   r   r   r   rz     r}   z%GrammarTests.test_nonlocal.<locals>.fr   )r   rz   r   r   r   test_nonlocal  s   zGrammarTests.test_nonlocalc              
   C   s   	 	 dd sJ 	 z	 W n t y# } z| d W Y d }~nd }~ww zW d S  t y? } z| d W Y d }~d S d }~ww )	Nr'   c                 S   r   rY   r   r   r   r   r   r    r}   z*GrammarTests.test_assert.<locals>.<lambda>c                 S   s   | d S rn   r   r   r   r   r   r    r  Tz6'assert True' should not have raised an AssertionErrorzthis should always passz;'assert True, msg' should not have raised an AssertionError)AssertionErrorr!   r   r   r   r   r   test_assert  s    zGrammarTests.test_assertTz Won't work if __debug__ is Falsec              
   C   s~   zJ d t y } z| |jd d W Y d }~nd }~ww zJ  t y> } z| t|jd W Y d }~d S d }~ww )Nr   rN  z%AssertionError not raised by assert 0Fz+AssertionError not raised by 'assert False')r  r   r   r!   rF   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"r8   rM   zassert False, "msg")r   rh   r?   r9   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 )	Nerrorzassert x, "msg" r8   rM   z4SyntaxError incorrectly raised for 'assert x, "msg"'r  r  r  )r(   r)   r*   r?   r9   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 Nr'   r   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_whileK  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                   @   rV   )z&GrammarTests.test_for.<locals>.Squaresc                 S   s   || _ g | _d S rY   )maxsofar)r   r  r   r   r   r\   `  s   
z/GrammarTests.test_for.<locals>.Squares.__init__c                 S   s
   t | jS rY   )rF   r  r,   r   r   r   __len__c  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  
IndexErrorrF   r  append)r   r   nr   r   r   re   d  s   

z2GrammarTests.test_for.<locals>.Squares.__getitem__N)rR   rS   rT   r\   r  re   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_forZ  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?rM   z0try:
    pass
except Exception as a[b]:
    pass)r   EOFErrorr"  r   r   r9   )r   rN  r   r   r   test_tryu  s0   
  "zGrammarTests.test_tryc                 C   s   	 	 	 	 	 	 	 d S rn   r   r,   r   r   r   
test_suite  s   zGrammarTests.test_suitec                 C   s   	 	 	 	 	 	 d S )NFr'   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 rk  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 )N"is" with a literalc                    s     | | d S rY   r   )r;   rN  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 Noner8   rM   z
x is Falsez	x is Truezx is ...)r  r(   r)   r*   r?   r9   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 rY   r   r:   rN  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)]r8   rM   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 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_ops2  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*  rk   r'   r   r   r   ru   r   r   c                 S   s   t | j| fS rY   )r   rR   r   r   r   r   r  T  r   z-GrammarTests.test_selectors.<locals>.<lambda>r   z[1, (1,), (1, 2), (1, 2, 3)])r   r{  r|  modulesrr   sortr   rN   )	r   r   r{  r   r   rw   r"   r   Lr   r   r   test_selectors9  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   ro   r   )ro   r   r   rk   r   )ro   r   threeZfourZfiveZsix>   r   ro   r  >   r   r   r   r   r   r   r   r   r   r   
test_atomsW  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   B|  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   D  r   r  c                   @   rV   )z%GrammarTests.test_classdef.<locals>.Cc                 S   r{   rY   r   r,   r   r   r   meth1  r}   z+GrammarTests.test_classdef.<locals>.C.meth1c                 S   r{   rY   r   )r   argr   r   r   meth2  r}   z+GrammarTests.test_classdef.<locals>.C.meth2c                 S   r{   rY   r   )r   r   r   r   r   r   meth3  r}   z+GrammarTests.test_classdef.<locals>.C.meth3N)rR   rS   rT   r  r  r  r   r   r   r   r     s    r   c                 S   r   rY   r   r   r   r   r   class_decorator  r}   z3GrammarTests.test_classdef.<locals>.class_decoratorc                   @   r  )z%GrammarTests.test_classdef.<locals>.GNr  r   r   r   r   G      r  Fc                   @   r  )z%GrammarTests.test_classdef.<locals>.HNr  r   r   r   r   H  r  r  c                   @   r  )z%GrammarTests.test_classdef.<locals>.INr  r   r   r   r   I  r  r  c                    r
  rY   r   )r   r  r   r   r    r  z,GrammarTests.test_classdef.<locals>.<lambda>c                   @   r  )z%GrammarTests.test_classdef.<locals>.JNr  r   r   r   r   J  r  r  .r'   c                   @   r  )z%GrammarTests.test_classdef.<locals>.KNr  r   r   r   r   K  r  r  c                   @   r  )z%GrammarTests.test_classdef.<locals>.LNr  r   r   r   r   r    r  r  r   c                   @   r  )z%GrammarTests.test_classdef.<locals>.MNr  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_classdefz  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_dictcomps  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  )rk   r  rk   r  rk   r  c                    s(   g | ]}d d  D D ]}||fqqS )c                 S   s   g | ]}d |v r|qS )r  r   )r'  rz   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  rk   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   rs  r   r   r'  rI   r   r   r   r(    rt  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   rk   r'   r   r   r   rk   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)r/  Engine)   Cheeseburger))r'   r   )r'   r/  )r   r/  )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   rs  r   r   r&  r   r   r   r(    rt  z7GrammarTests.test_genexps.<locals>.<genexpr>.<listcomp>r   Nr  r&  r   r   r   	<genexpr>       z,GrammarTests.test_genexps.<locals>.<genexpr>r'   c                 S   rs  r   r   r&  r   r   r   r(    rt  z-GrammarTests.test_genexps.<locals>.<listcomp>r   z&should produce StopIteration exceptionc                 3   s    | ]} V  qd S rY   r   )r'  r   r   r   r   r    rl  zshould produce TypeErrorc                 s   "    | ]}d D ]}||fV  qqdS )rG  Nr   r'  r   rI   r   r   r   r    r  rG  c                 S      g | ]}d D ]}||fqqS )rG  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   rs  r   r   r&  r   r   r   r(    rt  c                 s       | ]}|V  qd S rY   r   r&  r   r   r   r    rl  c                 s   r  rY   r   r  r   r   r   r    rl  c                 S   rs  r   r   r&  r   r   r   r(    rt  c                 s   s    | ]}|d  V  qdS r   Nr   r&  r   r   r   r    rv  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  rY   r   r&  r   r   r   r    rl  c                 s   r  rY   r   r  r   r   r   r    rl  c                 S   rs  r   r   r&  r   r   r   r(    rt  c                 s   r  rY   r   r&  r   r   r   r    rl  c                 s   r  rY   r   r  r   r   r   r    rl  c                 s   r  rY   r   r'  r   r   r   r   r    rl  c                 S   rs  r   r   r&  r   r   r   r(    rt  c                 s   r  rY   r   r&  r   r   r   r    rl  c                 S   rs  r   r   r  r   r   r   r(    rt  c                 s   r  rY   r   r  r   r   r   r    rl  c                 S   rs  r   r   r&  r   r   r   r(    rt  c                 s       | ]}|V  qdS TNr   r&  r   r   r   r    rl  c                 s   r  rY   r   r  r   r   r   r    rl  c                 s   r   r  r   r  r   r   r   r    rl  c                 S   rs  r   r   r&  r   r   r   r(    rt  c                 s   r   r  r   r&  r   r   r   r     rl  c                 s   s    | ]}qdS )FNr   r  r   r   r   r     s    c                 s   r   r  r   r  r   r   r   r     rl  r   zfoo(x for x in range(10), 100)zfoo(100, x for x in range(10)))	r  r   nextr!   StopIterationr"  rr   sumr   )r   r   rx   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  rY   r   r  r   r   r   r    rl  z;GrammarTests.test_comprehension_specials.<locals>.<genexpr>rk   Fc                 3   s*    | ]} rt D ]}||fV  q
qd S rY   r  r'  r   r   tr   r   r   r  
  s   ( Tc                 S   s"   g | ]}t d D ]}||fqqS rk   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'   rk   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   rn  c                 s   s    | ]\}|V  qd S rY   r   r&  r   r   r   r    rm  ))r   )r   )r   )r   r   r   )r  r   rF   rr   rq  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   rm   Nru   r   r,   r   r   r   	__enter__  rp   z;GrammarTests.test_with_statement.<locals>.manager.__enter__c                 W   r{   rY   r   )r   r   r   r   r   __exit__  rp   z:GrammarTests.test_with_statement.<locals>.manager.__exit__N)rR   rS   rT   r  r  r   r   r   r   manager      r  )object)r   r  r   rI   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 )z@helper to check that evaluation of expressions is done correctlyNr~   )rN  Z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(  d  r  z2GrammarTests.test_if_else_expr.<locals>.<listcomp>c                   S   rm   )NTr   r   r   r   r   r  d  r}   z0GrammarTests.test_if_else_expr.<locals>.<lambda>c                   S   rm   NFr   r   r   r   r   r  d  r}   Tc                 S   s   g | ]
}|d r|d qS )Fr   r&  r   r   r   r(  e  r  c                 S      | rdS dS )NFTr   r   r   r   r   r  e  r   c                 S   r  )NTFr   r   r   r   r   r  e  r   r'   rk   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assertFalserH   r   r   r   test_paren_evaluationv  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   rm   )Nr   r   r   r   r   r   r   
__matmul__  rp   z2GrammarTests.test_matrix_mul.<locals>.M.__matmul__c                 S   s
   || _ | S rY   )otherr  r   r   r   __imatmul__  s   z3GrammarTests.test_matrix_mul.<locals>.M.__imatmul__N)rR   rS   rT   r  r  r   r   r   r   r     r  r   r   rl   )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{   rY   r   r   r   r   r   r    rp   z8GrammarTests.test_async_await.<locals>.test.<locals>.sumr'   )Zsomeobj)r  r   r   r   r;     s   z+GrammarTests.test_async_await.<locals>.testr;   c                 S   s   t | dd | S )N_markedT)setattr)funcr   r   r   	decorator  s   z0GrammarTests.test_async_await.<locals>.decoratorc                         dS )N   r   r   r   r   r   test2  s   z,GrammarTests.test_async_await.<locals>.test2r$  )	r   rR   r   boolr  co_flagsinspectZCO_COROUTINEr  )r   r;   r!  r$  r   r   r   test_async_await  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   r)  c                   @   r  )z*GrammarTests.test_async_for.<locals>.AIterc                 S   r   rY   r   r,   r   r   r   	__aiter__  rp   z4GrammarTests.test_async_for.<locals>.AIter.__aiter__c                    s   t rY   )StopAsyncIterationr,   r   r   r   	__anext__     z4GrammarTests.test_async_for.<locals>.AIter.__anext__N)rR   rS   rT   r*  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 	 rY   r   r   r.  r)  r   r   r;    s   z(GrammarTests.test_async_for.<locals>.foor   r   sendr   r;  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   r)    r   r)  c                   @   r  )z-GrammarTests.test_async_with.<locals>.managerc                    r"  r  r   r,   r   r   r   
__aenter__  r-  z8GrammarTests.test_async_with.<locals>.manager.__aenter__c                    r"  r  r   )r   excr   r   r   	__aexit__  r-  z7GrammarTests.test_async_with.<locals>.manager.__aexit__N)rR   rS   rT   r4  r6  r   r   r   r   r    r  r  c               
      s   4 I d H  W d   I d H  q1 I d H sw   Y   4 I d H } W d   I d H  q;1 I d H s6w   Y   4 I d H \} }W d   I d H  qZ1 I d H sUw   Y   4 I d H (  4 I d H  W d   I d H  q1 I d H szw   Y  W d   I d H  q1 I d H sw   Y   4 I d H (}  4 I d H }W d   I d H  q1 I d H sw   Y  W d   I d H  q1 I d H sw   Y   4 I d H )}  4 I d H  W d   I d H  q1 I d H sw   Y  W d   I d H   1 I d H sw   Y   rY   r   r   r)  r  r   r   r;    s,   ((( R R :z)GrammarTests.test_async_with.<locals>.foor0  r2  r   r7  r   test_async_with  s   "zGrammarTests.test_async_withN)KrR   rS   rT   rU   r   test.support.warnings_helperr   rh   ri   rs   rt   r   r   r   r   r   r   r   r   r$  r:  r<  r?  rF  rH  rI  rK  rO  rR  rV  rZ  r[  r^  rb  rd  rr  rw  rz  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  r(  r3  r8  r   r   r   r   rg   o  s    .		 y'45'

R#!?#D
rg   __main__)rU   r   r   r9  r   r'  r:  r   r(   Ztest.ann_moduler   r   collectionsr   r;   r	   r0   r2   ZTestCaser   rq   r   rW   rg   rR   mainr   r   r   r   <module>   sF   7 {	            s