a
    ze0                 
   @   st  d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZm	Z	 d dl
m
Z
mZ d dlmZmZ d dlmZmZ d dlmZmZmZ d dlmZmZmZ d dlmZmZmZmZ d d	lmZ d d
lmZmZmZmZm Z  d dlm!Z!m"Z" d dlm#Z# d dlm$Z$m%Z% d dlm&Z&m'Z' d dlm(Z( d dlm)Z) d dlm*Z*m+Z+ d dlm,Z,m-Z-m.Z. d dlm/Z/m0Z0 d dlm1Z1m2Z2 d dl3Z3d dlZd dl4Z4d dl5Z5d dl6m7Z7 d dl6m8Z8 G dd deZ9G dd dZ:G dd de:Z;G dd de:Z<G dd  d e;e<Z=G d!d" d"e9Z>G d#d$ d$e9Z?G d%d& d&e9Z@G d'd( d(e9ZAG d)d* d*e9ZBG d+d, d,e9ZCG d-d. d.e9ZDed/eEeFZGed0ZHG d1d2 d2eeGeHf ZIG d3d4 d4eIeGeHf ZJG d5d6 d6e ZKe"G d7d8 d8eKe ZLG d9d: d:ZMG d;d< d<e ZNG d=d> d>e ZOe"G d?d@ d@eNeOe ZPe"G dAdB dBe ZQG dCdD dDeQZRG dEdF dFZSG dGdH dHe*ZTe"G dIdJ dJe ZUG dKdL dLe9ZVG dMdN dNe9ZWG dOdP dPe9ZXG dQdR dRe9ZYG dSdT dTe9ZZG dUdV dVe9Z[G dWdX dXe9Z\dYZ]ze^e] W n e_y   dZZ`Y n0 d[Z`d d\l6maZambZbmcZcmdZdmeZe d d]lmfZf G d^d_ d_ZgG d`da daegZhG dbdc dcehZiG ddde deee ZjG dfdg dgZkG dhdi diZlG djdk dke*ZmG dldm dme*ZnG dndo doe*ZoG dpdq dqe*Zpe+drdseEfgZqG dtdu due+ZrG dvdw dwe8jsdZdxZtG dydz dzereqZuG d{d| d|e+dZdxZvG d}d~ d~e7jgZwefex dddZyzeyez {d W n& e|y Z} zW Y dZ}[}n
dZ}[}0 0 e#Z~G dd dZG dd de9ZG dd deZG dd de9ZG dd de9ZG dd de9ZG dd de9ZG dd de9ZG dd de9ZG dd de9ZG dd de9ZG dd de9ZG dd de9Zedkrpe  dS )    N)TestCasemain
skipUnlessskip)copydeepcopy)AnyNoReturn)TypeVarAnyStr)TKTVT)UnionOptionalLiteral)TupleListDictMutableMapping)Callable)GenericClassVarFinalfinalProtocol)castruntime_checkable)get_type_hints)
get_originget_args)no_type_checkno_type_check_decoratorType)NewType)
NamedTuple	TypedDictIOTextIOBinaryIO)PatternMatch)	Annotated
ForwardRef)mod_generics_cache)_typed_dict_helperc                   @   s(   e Zd ZdddZd	ddZdd ZdS )
BaseTestCaseNc                 C   s8   t ||s4d||f }|d ur*|d| 7 }| |d S )Nz%r is not a subclass of %r : %s
issubclassZfailureExceptionselfclsZclass_or_tuplemsgmessage r;   &/usr/lib/python3.9/test/test_typing.pyassertIsSubclass%   s
    
zBaseTestCase.assertIsSubclassc                 C   s8   t ||r4d||f }|d ur*|d| 7 }| |d S )Nz%r is a subclass of %rr3   r4   r6   r;   r;   r<   assertNotIsSubclass,   s
    
z BaseTestCase.assertNotIsSubclassc                 C   s   t jD ]
}|  qd S N)typing	_cleanupsr7   fr;   r;   r<   clear_caches3   s    
zBaseTestCase.clear_caches)N)N)__name__
__module____qualname__r=   r>   rD   r;   r;   r;   r<   r2   #   s   

r2   c                   @   s   e Zd ZdS )EmployeeNrE   rF   rG   r;   r;   r;   r<   rH   8   s   rH   c                   @   s   e Zd ZdS )ManagerNrI   r;   r;   r;   r<   rJ   <   s   rJ   c                   @   s   e Zd ZdS )FounderNrI   r;   r;   r;   r<   rK   @   s   rK   c                   @   s   e Zd ZdS )ManagingFounderNrI   r;   r;   r;   r<   rL   D   s   rL   c                   @   sD   e Z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 )AnyTestsc                 C   s8   |  t tdt W d    n1 s*0    Y  d S N*   )assertRaises	TypeError
isinstancer   r7   r;   r;   r<   test_any_instance_type_errorJ   s    z%AnyTests.test_any_instance_type_errorc                 C   sl   |  t ttt W d    n1 s*0    Y  |  t ttt W d    n1 s^0    Y  d S r?   )rP   rQ   r5   rH   r   rS   r;   r;   r<   test_any_subclass_type_errorN   s    (z%AnyTests.test_any_subclass_type_errorc                 C   s   |  ttd d S )Nz
typing.Any)assertEqualreprr   rS   r;   r;   r<   	test_reprT   s    zAnyTests.test_reprc                 C   sj   |  t tdt W d    n1 s*0    Y  |  t tt  W d    n1 s\0    Y  d S rN   )rP   rQ   r5   r   intrS   r;   r;   r<   test_errorsW   s    (zAnyTests.test_errorsc                 C   s|   |  t  G dd dt}W d    n1 s00    Y  |  t$ G dd dtt}W d    n1 sn0    Y  d S )Nc                   @   s   e Zd ZdS z(AnyTests.test_cannot_subclass.<locals>.ANrI   r;   r;   r;   r<   A_   s   r\   c                   @   s   e Zd ZdS r[   rI   r;   r;   r;   r<   r\   b   s   rP   rQ   r   typer7   r\   r;   r;   r<   test_cannot_subclass]   s    .zAnyTests.test_cannot_subclassc                 C   sh   |  t t  W d    n1 s&0    Y  |  t tt  W d    n1 sZ0    Y  d S r?   r]   rS   r;   r;   r<   test_cannot_instantiatee   s    $z AnyTests.test_cannot_instantiatec                 C   s"   t jt  t jt  t jt  d S r?   )r@   r-   r   r,   r)   rS   r;   r;   r<   test_any_works_with_aliask   s    

z"AnyTests.test_any_works_with_aliasN)
rE   rF   rG   rT   rU   rX   rZ   r`   ra   rb   r;   r;   r;   r<   rM   H   s   rM   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )NoReturnTestsc                 C   s8   |  t tdt W d    n1 s*0    Y  d S rN   )rP   rQ   rR   r	   rS   r;   r;   r<   !test_noreturn_instance_type_errort   s    z/NoReturnTests.test_noreturn_instance_type_errorc                 C   sl   |  t ttt W d    n1 s*0    Y  |  t ttt W d    n1 s^0    Y  d S r?   )rP   rQ   r5   rH   r	   rS   r;   r;   r<   !test_noreturn_subclass_type_errorx   s    (z/NoReturnTests.test_noreturn_subclass_type_errorc                 C   s   |  ttd d S )Nztyping.NoReturn)rV   rW   r	   rS   r;   r;   r<   rX   ~   s    zNoReturnTests.test_reprc                 C   s6   |  t tt  W d    n1 s(0    Y  d S r?   )rP   rQ   r	   rY   rS   r;   r;   r<   test_not_generic   s    zNoReturnTests.test_not_genericc                 C   s|   |  t  G dd dt}W d    n1 s00    Y  |  t$ G dd dtt}W d    n1 sn0    Y  d S )Nc                   @   s   e Zd ZdS z-NoReturnTests.test_cannot_subclass.<locals>.ANrI   r;   r;   r;   r<   r\      s   r\   c                   @   s   e Zd ZdS rg   rI   r;   r;   r;   r<   r\      s   rP   rQ   r	   r^   r_   r;   r;   r<   r`      s    .z"NoReturnTests.test_cannot_subclassc                 C   sh   |  t t  W d    n1 s&0    Y  |  t tt  W d    n1 sZ0    Y  d S r?   rh   rS   r;   r;   r<   ra      s    $z%NoReturnTests.test_cannot_instantiateN)	rE   rF   rG   rd   re   rX   rf   r`   ra   r;   r;   r;   r<   rc   r   s   rc   c                   @   s|   e Z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S )TypeVarTestsc                 C   s$   t d}| || | |t  d S Nr   )r
   rV   assertIsInstancer7   r   r;   r;   r<   test_basic_plain   s    zTypeVarTests.test_basic_plainc                 C   s@   t d}| t td| W d    n1 s20    Y  d S )Nr   rO   )r
   rP   rQ   rR   rl   r;   r;   r<    test_typevar_instance_type_error   s    z-TypeVarTests.test_typevar_instance_type_errorc                 C   st   t d}| t tt| W d    n1 s20    Y  | t t|t W d    n1 sf0    Y  d S rj   )r
   rP   rQ   r5   rY   rl   r;   r;   r<    test_typevar_subclass_type_error   s
    (z-TypeVarTests.test_typevar_subclass_type_errorc                 C   s<   |  t tdt}| W d    n1 s.0    Y  d S )NX)rP   rQ   r
   rY   r7   rp   r;   r;   r<   test_constrained_error   s    
z#TypeVarTests.test_constrained_errorc                 C   s   t d}t d}| || | t| | | t| t||f  | t||f | | t|tf t|  | t|tf tt  | t|tf j|tf | t|tf j|f | t|tf jt d S )Nrp   Y)	r
   assertNotEqualrV   r   rY   __args____parameters__assertIs
__origin__)r7   rp   rs   r;   r;   r<   test_union_unique   s    zTypeVarTests.test_union_uniquec                 C   s(   t dtt}| t|tf t|  d S Nr\   )r
   strbytesrt   r   r_   r;   r;   r<   test_union_constrained   s    z#TypeVarTests.test_union_constrainedc                 C   s|   |  ttd |  ttd |  ttd |  ttd tddd}|  t|d td	dd
}|  t|d d S )Nz~Tz~KTz~VTz~AnyStrT_coT	covariantz+T_coT_contra)contravariantz	-T_contra)rV   rW   r   r   r   r   r
   )r7   r~   r   r;   r;   r<   rX      s    zTypeVarTests.test_reprc                 C   s4   |  tdtd |  tdtttdtt d S rj   )rt   r
   rY   r{   rS   r;   r;   r<   test_no_redefinition   s    z!TypeVarTests.test_no_redefinitionc                 C   sB   |  t$ G dd dtd}W d    n1 s40    Y  d S )Nc                   @   s   e Zd ZdS )z1TypeVarTests.test_cannot_subclass_vars.<locals>.VNrI   r;   r;   r;   r<   V   s   r   r   rP   rQ   r
   r7   r   r;   r;   r<   test_cannot_subclass_vars   s    z&TypeVarTests.test_cannot_subclass_varsc                 C   s>   |  t  G dd dt}W d    n1 s00    Y  d S )Nc                   @   s   e Zd ZdS )z7TypeVarTests.test_cannot_subclass_var_itself.<locals>.VNrI   r;   r;   r;   r<   r      s   r   r   r   r;   r;   r<   test_cannot_subclass_var_itself   s    z,TypeVarTests.test_cannot_subclass_var_itselfc                 C   s8   |  t td  W d    n1 s*0    Y  d S rz   r   rS   r;   r;   r<   test_cannot_instantiate_vars   s    z)TypeVarTests.test_cannot_instantiate_varsc                 C   st   |  t tddd W d    n1 s,0    Y  |  t  tdtttd W d    n1 sf0    Y  d S )Nrp   rO   bound)rP   rQ   r
   r{   floatrH   rS   r;   r;   r<   test_bound_errors   s    *zTypeVarTests.test_bound_errorsc                 C   s   d}t |i  d S )Nz&import typing
T = typing.TypeVar('T')
)exec)r7   coder;   r;   r<   test_missing__name__   s    z!TypeVarTests.test_missing__name__c                 C   s<   |  t tdddd W d    n1 s.0    Y  d S )Nr   T)r   r   )rP   
ValueErrorr
   rS   r;   r;   r<   test_no_bivariant   s    zTypeVarTests.test_no_bivariantN)rE   rF   rG   rm   rn   ro   rr   ry   r}   rX   r   r   r   r   r   r   r   r;   r;   r;   r<   ri      s   
ri   c                   @   s   e Z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)S )*
UnionTestsc                 C   s   t ttf }| |t  d S r?   )r   rY   r   rt   r7   ur;   r;   r<   test_basics   s    zUnionTests.test_basicsc                 C   s   |  t ttt W d    n1 s*0    Y  |  t ttt W d    n1 s^0    Y  |  t" tttttf  W d    n1 s0    Y  |  t" ttttf t W d    n1 s0    Y  d S r?   )rP   rQ   r5   rY   r   r{   rS   r;   r;   r<   test_subclass_error   s    ((0zUnionTests.test_subclass_errorc                 C   sl   t t }| |t t ttf }t ttf }t ttf }| || | |t | |t | |t d S r?   )r   r   rV   rY   objectrt   )r7   r   u1u2u3r;   r;   r<   test_union_any   s    zUnionTests.test_union_anyc                 C   sT   t t }| |t t ttf }t ttf }| || | |t | |t d S r?   )r   r   rV   rY   rt   )r7   r   r   r   r;   r;   r<   test_union_object  s    zUnionTests.test_union_objectc                 C   s(   t ttf }t ttf }| || d S r?   )r   rY   r   rV   )r7   r   r   r;   r;   r<   test_unordered  s    zUnionTests.test_unorderedc                 C   s   t t }| |t d S r?   )r   rH   rw   )r7   tr;   r;   r<   test_single_class_disappears  s    z'UnionTests.test_single_class_disappearsc                 C   s8   t ttf }| |t | t|j | t|j d S r?   )r   rH   rJ   rt   assertInru   r   r;   r;   r<   test_base_class_kept  s    zUnionTests.test_base_class_keptc                 C   s2   t ttf }t |tf }| |t tttf  d S r?   )r   rY   r   rH   rV   )r7   r   vr;   r;   r<   test_union_union   s    zUnionTests.test_union_unionc                 C   s6  |  ttd tttf }|  t|dt  tttf }|  t|dt  td}t|tf t }|  t|tt ttt tf }|  t|d ttt t	t
tf f }|  t|d td t
f }|  t|d tt
d f }|  t|d td t
tf }|  t|d tt
 }|  t|d d S )	Nztyping.Unionztyping.Union[%s.Employee, int]ztyping.Union[int, %s.Employee]r   z#typing.Union[typing.List[int], int]z)typing.Union[list[int], dict[str, float]]ztyping.Optional[str]z typing.Union[NoneType, str, int])rV   rW   r   rH   rY   rE   r
   r   listdictr{   r   r   )r7   r   r   r;   r;   r<   rX   %  s(    zUnionTests.test_reprc                 C   s   |  t  G dd dt}W d    n1 s00    Y  |  t$ G dd dtt}W d    n1 sn0    Y  |  t( G dd dtttf }W d    n1 s0    Y  d S )Nc                   @   s   e Zd ZdS z*UnionTests.test_cannot_subclass.<locals>.CNrI   r;   r;   r;   r<   C>  s   r   c                   @   s   e Zd ZdS r   rI   r;   r;   r;   r<   r   A  s   c                   @   s   e Zd ZdS r   rI   r;   r;   r;   r<   r   D  s   )rP   rQ   r   r^   rY   r{   r7   r   r;   r;   r<   r`   <  s    .2zUnionTests.test_cannot_subclassc                 C   s   |  t t  W d    n1 s&0    Y  |  t tt  W d    n1 sZ0    Y  tttf }|  t |  W d    n1 s0    Y  |  t t|  W d    n1 s0    Y  d S r?   )rP   rQ   r   r^   rY   r   r   r;   r;   r<   ra   G  s    $($z"UnionTests.test_cannot_instantiatec                 C   s   |  tttjt f tk |  tttjt f tjt k | ttttjt f j | tjt tttjt f j d S r?   )assertFalser   r{   r@   IterablerY   r   ru   rS   r;   r;   r<   test_union_generalizationR  s    "z$UnionTests.test_union_generalizationc                 C   sb   |  tt |  tt |  tt |  tt |  d gt |  ttj |  ttj t d S r?   )	rt   r   r   r   r   r   r@   Mappingr   rS   r;   r;   r<   test_union_compare_otherX  s    z#UnionTests.test_union_compare_otherc                 C   s$   t t }ttd f }| || d S r?   )r   rY   r   rV   )r7   or   r;   r;   r<   test_optionala  s    zUnionTests.test_optionalc                 C   s6   |  t td  W d    n1 s(0    Y  d S Nr;   )rP   rQ   r   rS   r;   r;   r<   
test_emptyf  s    zUnionTests.test_emptyc                 C   s@   |  t" tdtttf  W d    n1 s20    Y  d S rN   )rP   rQ   rR   r   rY   r{   rS   r;   r;   r<   test_union_instance_type_errorj  s    z)UnionTests.test_union_instance_type_errorc                 C   s2   t ttf }|ddd}| t|d | d S )Nxc                 S   s   d S r?   r;   r   r;   r;   r<   rC   p      z(UnionTests.test_no_eval_union.<locals>.fr   )r   rY   r{   rw   r   )r7   r   rC   r;   r;   r<   test_no_eval_unionn  s    zUnionTests.test_no_eval_unionc                 C   s*   t ddd}| tt|t f d d S )Nreturnc                   S   s   d S r?   r;   r;   r;   r;   r<   funt  r   z0UnionTests.test_function_repr_union.<locals>.funztyping.Union[fun, int])rY   rV   rW   r   )r7   r   r;   r;   r<   test_function_repr_unions  s    z#UnionTests.test_function_repr_unionc                 C   s   t ttf }| d S r?   )r   r{   r,   r_   r;   r;   r<   test_union_str_patternw  s    z!UnionTests.test_union_str_patternc                    s4   ddl m  t tf   fdd}t|tf  d S )Nr   Elementc                     s    |  S r?   r;   )argsr   r;   r<   Elem  s    z#UnionTests.test_etree.<locals>.Elem)Zxml.etree.ElementTreer   r   r{   )r7   r   r;   r   r<   
test_etree|  s    zUnionTests.test_etreeN)rE   rF   rG   r   r   r   r   r   r   r   r   rX   r`   ra   r   r   r   r   r   r   r   r   r   r;   r;   r;   r<   r      s(   
		r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )
TupleTestsc                 C   s   |  t" tttttf  W d    n1 s20    Y  |  t" tttttf  W d    n1 sn0    Y  G dd dt}| ttt | t|t d S )Nc                   @   s   e Zd ZdS )z"TupleTests.test_basics.<locals>.TPNrI   r;   r;   r;   r<   TP  r   r   )rP   rQ   r5   r   rY   r{   tuple
assertTrue)r7   r   r;   r;   r<   r     s    00zTupleTests.test_basicsc                 C   sd   |  tt tt  |  ttdf ttdf  | tt tttf  | tt ttdf  d S N.)rV   r   rY   rt   rS   r;   r;   r<   test_equality  s    zTupleTests.test_equalityc                 C   s$   G dd dt }| t|t d S )Nc                   @   s   e Zd ZdS )z/TupleTests.test_tuple_subclass.<locals>.MyTupleNrI   r;   r;   r;   r<   MyTuple  s   r   )r   r   r5   r   )r7   r   r;   r;   r<   test_tuple_subclass  s    zTupleTests.test_tuple_subclassc                 C   sL   |  t" tdtttf  W d    n1 s20    Y  | dt d S )N)r   r   )rP   rQ   rR   r   rY   rk   rS   r;   r;   r<   test_tuple_instance_type_error  s    0z)TupleTests.test_tuple_instance_type_errorc                 C   sp   |  ttd |  ttd d |  ttttf d |  tttdf d |  tttt  d d S )Nztyping.Tupler;   ztyping.Tuple[()]ztyping.Tuple[int, float].ztyping.Tuple[int, ...]ztyping.Tuple[list[int]])rV   rW   r   rY   r   r   rS   r;   r;   r<   rX     s
    zTupleTests.test_reprc                 C   sp   |  t tdt W d    n1 s*0    Y  |  t tdtt  W d    n1 sb0    Y  d S rN   )rP   rQ   r5   r   rY   rS   r;   r;   r<   rZ     s    (zTupleTests.test_errorsN)	rE   rF   rG   r   r   r   r   rX   rZ   r;   r;   r;   r<   r     s   
r   c                   @   sT   e Z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 )CallableTestsc                 C   sh   |  t2 | ttdd ttgtf  W d    n1 sB0    Y  | ttdd t d S )Nc                 S   s   | S r?   r;   r   r;   r;   r<   <lambda>  r   z2CallableTests.test_self_subclass.<locals>.<lambda>c                 S   s   | S r?   r;   r   r;   r;   r<   r     r   )rP   rQ   r   r5   r^   r   rY   rS   r;   r;   r<   test_self_subclass  s    @z CallableTests.test_self_subclassc                 C   s   |  ttgtf ttgtf  |  tttgtf ttgtf hd | ttgtf ttgtf  | ttgtf ttgtf  | ttgtf tttgtf  | ttgtf tg tf  | ttgtf t d S N   )rV   r   rY   lenrt   r{   rS   r;   r;   r<   test_eq_hash  s     (  "zCallableTests.test_eq_hashc                 C   s   |  t t  W d    n1 s&0    Y  |  t tt  W d    n1 sZ0    Y  ttgtf }|  t |  W d    n1 s0    Y  |  t t|  W d    n1 s0    Y  d S r?   )rP   rQ   r   r^   rY   r{   )r7   cr;   r;   r<   ra     s    $($z%CallableTests.test_cannot_instantiatec                 C   s6   |  t tt  W d    n1 s(0    Y  d S r?   )rP   rQ   r   rY   rS   r;   r;   r<   test_callable_wrong_forms  s    z'CallableTests.test_callable_wrong_formsc                 C   s$   dd }|  |t | d t d S )Nc                   S   s   d S r?   r;   r;   r;   r;   r<   rC     s    z5CallableTests.test_callable_instance_works.<locals>.f)rk   r   assertNotIsInstancerB   r;   r;   r<   test_callable_instance_works  s    z*CallableTests.test_callable_instance_worksc                 C   s  dd }|  t$ | |tg d f  W d    n1 s<0    Y  |  t$ | |tg tf  W d    n1 sz0    Y  |  t$ | d tg d f  W d    n1 s0    Y  |  t$ | d tg tf  W d    n1 s0    Y  d S )Nc                   S   s   d S r?   r;   r;   r;   r;   r<   rC     s    z:CallableTests.test_callable_instance_type_error.<locals>.f)rP   rQ   rk   r   r   r   rB   r;   r;   r<   !test_callable_instance_type_error  s    222z/CallableTests.test_callable_instance_type_errorc                 C   s   t g tf }| t|d t ttgtf }| t|d t dtf }| t|d t ttgtt f }| t|d d S )Nztyping.Callable[[], bool]z"typing.Callable[[str, float], int].ztyping.Callable[..., str]z(typing.Callable[[str, float], list[int]])r   boolrV   rW   r{   r   rY   r   )r7   Zct0Zct2ZctvZct3r;   r;   r<   rX     s    zCallableTests.test_reprc                 C   s>   t dtf ddd}| t|t t dt dtf i d S )N.ac                 S   s   d S r?   r;   r   r;   r;   r<   foo  s    z6CallableTests.test_callable_with_ellipsis.<locals>.foor   )r   r   rV   r   globalslocalsr7   r   r;   r;   r<   test_callable_with_ellipsis  s    z)CallableTests.test_callable_with_ellipsisc                 C   s   t jtdtf   d S r   )r@   r   r   r{   rS   r;   r;   r<   test_ellipsis_in_generic  s    z&CallableTests.test_ellipsis_in_genericN)rE   rF   rG   r   r   ra   r   r   r   rX   r   r   r;   r;   r;   r<   r     s   	
r   c                   @   sl   e Z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S )LiteralTestsc                 C   sP   t d  t d  t d  t d   t d  t d  t t d t d f  t d  d S )	Nr   r         )r   yzT)r   2Fr   r         )s   foobar)r   rS   r;   r;   r<   r     s    zLiteralTests.test_basicsc                 C   s*   t t  t d  t ddd  t t  d S )N)y       @      @.r;   r   r   r   r   )r   rY   r   rS   r;   r;   r<   3test_illegal_parameters_do_not_raise_runtime_errors  s    z@LiteralTests.test_illegal_parameters_do_not_raise_runtime_errorsc                 C   s   t td   t td   d S )Nr   )r   r   baz)r   r   rS   r;   r;   r<    test_literals_inside_other_types  s    z-LiteralTests.test_literals_inside_other_typesc                 C   sx   |  ttd d |  ttd d |  ttt d |  ttd |  ttd  d |  ttd d	 d S )
Nr   ztyping.Literal[1])r   Tr   ztyping.Literal[1, True, 'foo']ztyping.Literal[int]ztyping.Literalztyping.Literal[None]r   r   r   r   ztyping.Literal[1, 2, 3])rV   rW   r   rY   rS   r;   r;   r<   rX     s    zLiteralTests.test_reprc                 C   s   |  t t  W d    n1 s&0    Y  |  t td   W d    n1 sZ0    Y  |  t tt  W d    n1 s0    Y  |  t ttd   W d    n1 s0    Y  d S r   )rP   rQ   r   r^   rS   r;   r;   r<   test_cannot_init  s    $((zLiteralTests.test_cannot_initc                 C   s   |  t tdtd  W d    n1 s.0    Y  |  t tttd  W d    n1 sf0    Y  |  t tdtd  W d    n1 s0    Y  |  t tttd  W d    n1 s0    Y  d S r   )rP   rQ   rR   r   rY   r5   rS   r;   r;   r<    test_no_isinstance_or_issubclass%  s    ,,,z-LiteralTests.test_no_isinstance_or_issubclassc                 C   s|   |  t$ G dd dtd }W d    n1 s40    Y  |  t  G dd dt}W d    n1 sn0    Y  d S )Nc                   @   s   e Zd ZdS )z-LiteralTests.test_no_subclassing.<locals>.FooNrI   r;   r;   r;   r<   Foo1  r   r   r   c                   @   s   e Zd ZdS )z-LiteralTests.test_no_subclassing.<locals>.BarNrI   r;   r;   r;   r<   Bar3  r   r   rP   rQ   r   )r7   r   r   r;   r;   r<   test_no_subclassing/  s    2z LiteralTests.test_no_subclassingc                 C   s:   |  t td d  W d    n1 s,0    Y  d S r   r   rS   r;   r;   r<   test_no_multiple_subscripts5  s    z(LiteralTests.test_no_multiple_subscriptsc                 C   s   |  td td  |  td td  |  td td  |  td td  |  td td  |  td td	  | td td  | td td
  | td td  d S )Nr   FTr   r   )r   T)r   r   r   )Tr   r   r   r   r   )rt   r   rV   rS   r;   r;   r<   
test_equal9  s    zLiteralTests.test_equalc                 C   sX   |  ttd ttd  |  ttd ttd  |  ttd ttd  d S )Nr   r   r   r   r   )rV   hashr   rS   r;   r;   r<   	test_hashD  s    zLiteralTests.test_hashc                 C   sb   |  td jd |  td jd |  tdtd td f jd |  tg g f jg g f d S )Nr   r   r   r   )r   r   )r   r   r   r   )rV   r   ru   rS   r;   r;   r<   	test_argsI  s     zLiteralTests.test_argsc                 C   sh   t t d t d t d f }t t d df }t t d  }|||fD ]"}| |t d  | |jd q@d S )Nr   r   r   r   r   )r   rV   ru   )r7   l1l2l3lr;   r;   r<   test_flattenP  s    zLiteralTests.test_flattenN)rE   rF   rG   r   r   r   rX   r   r   r   r   r   r   r   r  r;   r;   r;   r<   r     s   

r   XKXVc                   @   s@   e Zd ZeedddZeedddZdeeedd	d
ZdS )SimpleMapping)keyr   c                 C   s   d S r?   r;   r7   r  r;   r;   r<   __getitem___  s    zSimpleMapping.__getitem__)r  valuec                 C   s   d S r?   r;   r7   r  r  r;   r;   r<   __setitem__b  s    zSimpleMapping.__setitem__N)r  defaultr   c                 C   s   d S r?   r;   r7   r  r  r;   r;   r<   gete  s    zSimpleMapping.get)N)rE   rF   rG   r  r  r  r
  r  r;   r;   r;   r<   r  ]  s   r  c                   @   s@   e Zd Zdd ZedddZedddZdedd	d
ZdS )MySimpleMappingc                 C   s
   i | _ d S r?   storerS   r;   r;   r<   __init__k  s    zMySimpleMapping.__init__)r  c                 C   s
   | j | S r?   r  r  r;   r;   r<   r  n  s    zMySimpleMapping.__getitem__c                 C   s   || j |< d S r?   r  r	  r;   r;   r<   r
  q  s    zMySimpleMapping.__setitem__Nc                 C   s(   z| j | W S  ty"   | Y S 0 d S r?   )r  KeyErrorr  r;   r;   r<   r  t  s    zMySimpleMapping.get)N)rE   rF   rG   r  r{   r  r
  r  r;   r;   r;   r<   r  i  s   r  c                   @   s   e Zd ZU eed< eed< dS )
Coordinater   r   NrE   rF   rG   rY   __annotations__r;   r;   r;   r<   r  {  s   
r  c                   @   s   e Zd ZU eed< dS )PointlabelNrE   rF   rG   r{   r  r;   r;   r;   r<   r    s   
r  c                   @   s&   e Zd ZU eed< eed< eed< dS )MyPointr   r   r  NrE   rF   rG   rY   r  r{   r;   r;   r;   r<   r    s   
r  c                   @   s   e Zd ZU eed< dS )XAxisr   Nr  r;   r;   r;   r<   r    s   
r  c                   @   s   e Zd ZU eed< dS )YAxisr   Nr  r;   r;   r;   r<   r    s   
r  c                   @   s   e Zd ZdS )PositionNrI   r;   r;   r;   r<   r    s   r  c                   @   s&   e Zd ZU eed< eedddZdS )Protoattrargr   c                 C   s   d S r?   r;   r7   r!  r;   r;   r<   meth  s    z
Proto.methN)rE   rF   rG   rY   r  r{   r#  r;   r;   r;   r<   r    s   
r  c                   @   s   e Zd ZdS )ConcreteNrI   r;   r;   r;   r<   r$    s   r$  c                   @   s*   e Zd ZU dZeed< eedddZdS )Otherr   r  r   c                 C   s   |dkrdS dS )Nthisr   r   r;   r"  r;   r;   r<   r#    s    z
Other.methN)rE   rF   rG   r  rY   r  r{   r#  r;   r;   r;   r<   r%    s   
r%  c                   @   s   e Zd ZU eed< eed< dS )NTr   r   Nr  r;   r;   r;   r<   r'    s   
r'  c                   @   s   e Zd ZU ejed< dS )HasCallProtocol__call__N)rE   rF   rG   r@   r   r  r;   r;   r;   r<   r(    s   
r(  c                   @   st  e Z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)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'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[S )\ProtocolTestsc                 C   s   t G dd dt}G dd d}G dd d}dd }| || | | | | || | | | | tj| | || d S )	Nc                   @   s   e Zd Zdd ZdS )z,ProtocolTests.test_basic_protocol.<locals>.Pc                 S   s   d S r?   r;   rS   r;   r;   r<   r#    s    z1ProtocolTests.test_basic_protocol.<locals>.P.methNrE   rF   rG   r#  r;   r;   r;   r<   P  s   r,  c                   @   s   e Zd ZdS )z,ProtocolTests.test_basic_protocol.<locals>.CNrI   r;   r;   r;   r<   r     r   r   c                   @   s   e Zd Zdd ZdS )z,ProtocolTests.test_basic_protocol.<locals>.Dc                 S   s   d S r?   r;   rS   r;   r;   r<   r#    s    z1ProtocolTests.test_basic_protocol.<locals>.D.methNr+  r;   r;   r;   r<   D  s   r-  c                   S   s   d S r?   r;   r;   r;   r;   r<   rC     s    z,ProtocolTests.test_basic_protocol.<locals>.f)r   r   r=   rk   r>   r   typesFunctionType)r7   r,  r   r-  rC   r;   r;   r<   test_basic_protocol  s    z!ProtocolTests.test_basic_protocolc                 C   sr   t G dd dt}G dd d}dd }ttt|tjfD ]}| || q:t ddt|fD ]}| 	|| q\d S )	Nc                   @   s   e Zd ZdS )zFProtocolTests.test_everything_implements_empty_protocol.<locals>.EmptyNrI   r;   r;   r;   r<   Empty  s   r1  c                   @   s   e Zd ZdS )zBProtocolTests.test_everything_implements_empty_protocol.<locals>.CNrI   r;   r;   r;   r<   r     s   r   c                   S   s   d S r?   r;   r;   r;   r;   r<   rC     s    zBProtocolTests.test_everything_implements_empty_protocol.<locals>.fr   r;   )
r   r   r   r^   r   r.  r/  r=   r@   rk   )r7   r1  r   rC   thingr;   r;   r<   )test_everything_implements_empty_protocol  s    z7ProtocolTests.test_everything_implements_empty_protocolc                 C   s   dd }|  |t d S )Nc                   S   s   d S r?   r;   r;   r;   r;   r<   rC     s    z:ProtocolTests.test_function_implements_protocol.<locals>.f)rk   r(  rB   r;   r;   r<   !test_function_implements_protocol  s    z/ProtocolTests.test_function_implements_protocolc                 C   s  G dd d}G dd dt }| t" G dd d|t }W d    n1 sP0    Y  | t" G dd dt |}W d    n1 s0    Y  | t$ G dd d||t }W d    n1 s0    Y  G d	d
 d
||}G dd d||}| | | | | | d S )Nc                   @   s   e Zd ZdS )z9ProtocolTests.test_no_inheritance_from_nominal.<locals>.CNrI   r;   r;   r;   r<   r     r   r   c                   @   s   e Zd ZdS )z:ProtocolTests.test_no_inheritance_from_nominal.<locals>.BPNrI   r;   r;   r;   r<   BP  r   r5  c                   @   s   e Zd ZdS z9ProtocolTests.test_no_inheritance_from_nominal.<locals>.PNrI   r;   r;   r;   r<   r,    s   r,  c                   @   s   e Zd ZdS r6  rI   r;   r;   r;   r<   r,    s   c                   @   s   e Zd ZdS r6  rI   r;   r;   r;   r<   r,    s   c                   @   s   e Zd ZdS )z9ProtocolTests.test_no_inheritance_from_nominal.<locals>.DNrI   r;   r;   r;   r<   r-    r   r-  c                   @   s   e Zd ZdS )z9ProtocolTests.test_no_inheritance_from_nominal.<locals>.ENrI   r;   r;   r;   r<   E  r   r7  )r   rP   rQ   r   )r7   r   r5  r,  r-  r7  r;   r;   r<    test_no_inheritance_from_nominal  s    002z.ProtocolTests.test_no_inheritance_from_nominalc                 C   s  G dd dt }| t |  W d    n1 s60    Y  G dd d|}| | | | t |d W d    n1 s0    Y  td}G dd dt | }| t |  W d    n1 s0    Y  | t |t   W d    n1 s0    Y  | t ||   W d    n1 s>0    Y  G d	d
 d
|| }| |t  | | t |t d W d    n1 s0    Y  d S )Nc                   @   s   e Zd ZdS )z.ProtocolTests.test_no_instantiation.<locals>.PNrI   r;   r;   r;   r<   r,    r   r,  c                   @   s   e Zd ZdS )z.ProtocolTests.test_no_instantiation.<locals>.CNrI   r;   r;   r;   r<   r     r   r   rO   r   c                   @   s   e Zd ZdS )z/ProtocolTests.test_no_instantiation.<locals>.PGNrI   r;   r;   r;   r<   PG  r   r9  c                   @   s   e Zd ZdS )z/ProtocolTests.test_no_instantiation.<locals>.CGNrI   r;   r;   r;   r<   CG  r   r:  )r   rP   rQ   rk   r
   rY   )r7   r,  r   r   r9  r:  r;   r;   r<   test_no_instantiation  s&    $&$**z#ProtocolTests.test_no_instantiationc                 C   sv   t G dd dt}G dd d|}G dd d|}| t |  W d    n1 sZ0    Y  | | | d S )Nc                   @   s    e Zd ZejedddZdS )z9ProtocolTests.test_cannot_instantiate_abstract.<locals>.Pr   c                 S   s   t d S r?   )NotImplementedErrorrS   r;   r;   r<   ameth  s    z?ProtocolTests.test_cannot_instantiate_abstract.<locals>.P.amethN)rE   rF   rG   abcabstractmethodrY   r=  r;   r;   r;   r<   r,    s   r,  c                   @   s   e Zd ZdS )z9ProtocolTests.test_cannot_instantiate_abstract.<locals>.BNrI   r;   r;   r;   r<   B  s   r@  c                   @   s   e Zd ZedddZdS )z9ProtocolTests.test_cannot_instantiate_abstract.<locals>.Cr   c                 S   s   dS )N   r;   rS   r;   r;   r<   r=    s    z?ProtocolTests.test_cannot_instantiate_abstract.<locals>.C.amethN)rE   rF   rG   rY   r=  r;   r;   r;   r<   r     s   r   )r   r   rP   rQ   rk   )r7   r,  r@  r   r;   r;   r<    test_cannot_instantiate_abstract  s    $z.ProtocolTests.test_cannot_instantiate_abstractc                 C   s   G dd dt }tG dd d|t }G dd d}G dd d}G d	d
 d
}| | | | | | | || | || | | | | || d S )Nc                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_subprotocols_extending.<locals>.P1c                 S   s   d S r?   r;   rS   r;   r;   r<   meth1  s    z;ProtocolTests.test_subprotocols_extending.<locals>.P1.meth1NrE   rF   rG   rC  r;   r;   r;   r<   P1  s   rE  c                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_subprotocols_extending.<locals>.P2c                 S   s   d S r?   r;   rS   r;   r;   r<   meth2$  s    z;ProtocolTests.test_subprotocols_extending.<locals>.P2.meth2NrE   rF   rG   rF  r;   r;   r;   r<   P2"  s   rH  c                   @   s   e Zd Zdd Zdd ZdS )z4ProtocolTests.test_subprotocols_extending.<locals>.Cc                 S   s   d S r?   r;   rS   r;   r;   r<   rC  (  s    z:ProtocolTests.test_subprotocols_extending.<locals>.C.meth1c                 S   s   d S r?   r;   rS   r;   r;   r<   rF  +  s    z:ProtocolTests.test_subprotocols_extending.<locals>.C.meth2NrE   rF   rG   rC  rF  r;   r;   r;   r<   r   '  s   r   c                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_subprotocols_extending.<locals>.C1c                 S   s   d S r?   r;   rS   r;   r;   r<   rC  /  s    z;ProtocolTests.test_subprotocols_extending.<locals>.C1.meth1NrD  r;   r;   r;   r<   C1.  s   rJ  c                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_subprotocols_extending.<locals>.C2c                 S   s   d S r?   r;   rS   r;   r;   r<   rF  3  s    z;ProtocolTests.test_subprotocols_extending.<locals>.C2.meth2NrG  r;   r;   r;   r<   C22  s   rK  r   r   r   r>   rk   r=   )r7   rE  rH  r   rJ  rK  r;   r;   r<   test_subprotocols_extending  s    z)ProtocolTests.test_subprotocols_extendingc                 C   s   G dd dt }G dd dt }tG dd d||t }G dd d}G d	d
 d
}G dd d}| | | | | | | || | || | | | | || d S )Nc                   @   s   e Zd Zdd ZdS )z3ProtocolTests.test_subprotocols_merging.<locals>.P1c                 S   s   d S r?   r;   rS   r;   r;   r<   rC  ?  s    z9ProtocolTests.test_subprotocols_merging.<locals>.P1.meth1NrD  r;   r;   r;   r<   rE  >  s   rE  c                   @   s   e Zd Zdd ZdS )z3ProtocolTests.test_subprotocols_merging.<locals>.P2c                 S   s   d S r?   r;   rS   r;   r;   r<   rF  C  s    z9ProtocolTests.test_subprotocols_merging.<locals>.P2.meth2NrG  r;   r;   r;   r<   rH  B  s   rH  c                   @   s   e Zd ZdS )z2ProtocolTests.test_subprotocols_merging.<locals>.PNrI   r;   r;   r;   r<   r,  F  s   r,  c                   @   s   e Zd Zdd Zdd ZdS )z2ProtocolTests.test_subprotocols_merging.<locals>.Cc                 S   s   d S r?   r;   rS   r;   r;   r<   rC  K  s    z8ProtocolTests.test_subprotocols_merging.<locals>.C.meth1c                 S   s   d S r?   r;   rS   r;   r;   r<   rF  N  s    z8ProtocolTests.test_subprotocols_merging.<locals>.C.meth2NrI  r;   r;   r;   r<   r   J  s   r   c                   @   s   e Zd Zdd ZdS )z3ProtocolTests.test_subprotocols_merging.<locals>.C1c                 S   s   d S r?   r;   rS   r;   r;   r<   rC  R  s    z9ProtocolTests.test_subprotocols_merging.<locals>.C1.meth1NrD  r;   r;   r;   r<   rJ  Q  s   rJ  c                   @   s   e Zd Zdd ZdS )z3ProtocolTests.test_subprotocols_merging.<locals>.C2c                 S   s   d S r?   r;   rS   r;   r;   r<   rF  V  s    z9ProtocolTests.test_subprotocols_merging.<locals>.C2.meth2NrG  r;   r;   r;   r<   rK  U  s   rK  rL  )r7   rE  rH  r,  r   rJ  rK  r;   r;   r<   test_subprotocols_merging=  s    z'ProtocolTests.test_subprotocols_mergingc                 C   s  t d}tG dd dt}tG dd dt| }G dd dt}G dd	 d	t| }G d
d d}| || | || | || | t t|||  W d    n1 s0    Y  | t t|||  W d    n1 s0    Y  | t t|| W d    n1 s&0    Y  | t t|| W d    n1 s\0    Y  | t t|||  W d    n1 s0    Y  | t t||t  W d    n1 s0    Y  d S )Nr   c                   @   s   e Zd Zdd ZdS )z2ProtocolTests.test_protocols_issubclass.<locals>.Pc                 S   s   d S r?   r;   rS   r;   r;   r<   r   e  r   z4ProtocolTests.test_protocols_issubclass.<locals>.P.xNrE   rF   rG   r   r;   r;   r;   r<   r,  c  s   r,  c                   @   s   e Zd Zdd ZdS )z3ProtocolTests.test_protocols_issubclass.<locals>.PGc                 S   s   d S r?   r;   rS   r;   r;   r<   r   i  r   z5ProtocolTests.test_protocols_issubclass.<locals>.PG.xNrO  r;   r;   r;   r<   r9  g  s   r9  c                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_protocols_issubclass.<locals>.BadPc                 S   s   d S r?   r;   rS   r;   r;   r<   r   l  r   z7ProtocolTests.test_protocols_issubclass.<locals>.BadP.xNrO  r;   r;   r;   r<   BadPk  s   rP  c                   @   s   e Zd Zdd ZdS )z6ProtocolTests.test_protocols_issubclass.<locals>.BadPGc                 S   s   d S r?   r;   rS   r;   r;   r<   r   o  r   z8ProtocolTests.test_protocols_issubclass.<locals>.BadPG.xNrO  r;   r;   r;   r<   BadPGn  s   rQ  c                   @   s   e Zd Zdd ZdS )z2ProtocolTests.test_protocols_issubclass.<locals>.Cc                 S   s   d S r?   r;   rS   r;   r;   r<   r   r  r   z4ProtocolTests.test_protocols_issubclass.<locals>.C.xNrO  r;   r;   r;   r<   r   q  s   r   )r
   r   r   r=   rP   rQ   r5   rY   r7   r   r,  r9  rP  rQ  r   r;   r;   r<   test_protocols_issubclass`  s.    ,,**.z'ProtocolTests.test_protocols_issubclassc                 C   s8  G dd d}t G dd dt}| t t|| W d    n1 sL0    Y  | | | || | t t|| W d    n1 s0    Y  | | | G dd d|}| || | | | || | 	|| | | | | t t|| W d    n1 s*0    Y  d S )Nc                   @   s   e Zd ZdZdS )z?ProtocolTests.test_protocols_issubclass_non_callable.<locals>.Cr   NrO  r;   r;   r;   r<   r     s   r   c                   @   s   e Zd ZdZdS )zFProtocolTests.test_protocols_issubclass_non_callable.<locals>.PNonCallr   NrO  r;   r;   r;   r<   PNonCall  s   rT  c                   @   s   e Zd ZdS )z?ProtocolTests.test_protocols_issubclass_non_callable.<locals>.DNrI   r;   r;   r;   r<   r-    r   r-  )
r   r   rP   rQ   r5   rk   registerr>   r   r=   )r7   r   rT  r-  r;   r;   r<   &test_protocols_issubclass_non_callable  s$    (
(
z4ProtocolTests.test_protocols_issubclass_non_callablec                 C   sj  t d}tG dd dt}tG dd dt| }G dd dt}G dd	 d	t| }G d
d d}| | | | | | | t  t| ||  W d    n1 s0    Y  | t  t| ||  W d    n1 s0    Y  | t t| | W d    n1 s$0    Y  | t t| | W d    n1 s\0    Y  d S )Nr   c                   @   s   e Zd Zdd ZdS )z2ProtocolTests.test_protocols_isinstance.<locals>.Pc                 S   s   d S r?   r;   r   r;   r;   r<   r#    r   z7ProtocolTests.test_protocols_isinstance.<locals>.P.methNr+  r;   r;   r;   r<   r,    s   r,  c                   @   s   e Zd Zdd ZdS )z3ProtocolTests.test_protocols_isinstance.<locals>.PGc                 S   s   d S r?   r;   r   r;   r;   r<   r#    r   z8ProtocolTests.test_protocols_isinstance.<locals>.PG.methNr+  r;   r;   r;   r<   r9    s   r9  c                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_protocols_isinstance.<locals>.BadPc                 S   s   d S r?   r;   r   r;   r;   r<   r#    r   z:ProtocolTests.test_protocols_isinstance.<locals>.BadP.methNr+  r;   r;   r;   r<   rP    s   rP  c                   @   s   e Zd Zdd ZdS )z6ProtocolTests.test_protocols_isinstance.<locals>.BadPGc                 S   s   d S r?   r;   r   r;   r;   r<   r#    r   z;ProtocolTests.test_protocols_isinstance.<locals>.BadPG.methNr+  r;   r;   r;   r<   rQ    s   rQ  c                   @   s   e Zd Zdd ZdS )z2ProtocolTests.test_protocols_isinstance.<locals>.Cc                 S   s   d S r?   r;   r   r;   r;   r<   r#    r   z7ProtocolTests.test_protocols_isinstance.<locals>.C.methNr+  r;   r;   r;   r<   r     s   r   )r
   r   r   rk   rP   rQ   rR   rR  r;   r;   r<   test_protocols_isinstance  s$    ..,z'ProtocolTests.test_protocols_isinstancec                 C   s  G dd d}G dd d}G dd d}G dd d}|  |d	d
dt |  |d	d
t | t t |  |d	d
t |  t t |  t t |  |dt | | t | | t | | t | | t | t t |  td	d
t d S )Nc                   @   s   e Zd Zdd ZdS )z<ProtocolTests.test_protocols_isinstance_py36.<locals>.APointc                 S   s   || _ || _|| _d S r?   r   r   r  )r7   r   r   r  r;   r;   r<   r    s    zEProtocolTests.test_protocols_isinstance_py36.<locals>.APoint.__init__NrE   rF   rG   r  r;   r;   r;   r<   APoint  s   rZ  c                   @   s   e Zd ZdZdd ZdS )z<ProtocolTests.test_protocols_isinstance_py36.<locals>.BPointr@  c                 S   s   || _ || _d S r?   r   r   )r7   r   r   r;   r;   r<   r    s    zEProtocolTests.test_protocols_isinstance_py36.<locals>.BPoint.__init__N)rE   rF   rG   r  r  r;   r;   r;   r<   BPoint  s   r\  c                   @   s   e Zd Zdd Zdd ZdS )z7ProtocolTests.test_protocols_isinstance_py36.<locals>.Cc                 S   s
   || _ d S r?   r  r7   r  r;   r;   r<   r    s    z@ProtocolTests.test_protocols_isinstance_py36.<locals>.C.__init__c                 S   s   dS Nr   r;   r"  r;   r;   r<   r#    s    z<ProtocolTests.test_protocols_isinstance_py36.<locals>.C.methN)rE   rF   rG   r  r#  r;   r;   r;   r<   r     s   r   c                   @   s   e Zd ZdS )z9ProtocolTests.test_protocols_isinstance_py36.<locals>.BadNrI   r;   r;   r;   r<   Bad  r   r`  r   r   r\   rO   )	rk   r  r   r  r  r%  r  r$  r'  )r7   rZ  r\  r   r`  r;   r;   r<   test_protocols_isinstance_py36  s"    z,ProtocolTests.test_protocols_isinstance_py36c                 C   sf   t d}tG dd dt}tG dd dt| }G dd d}| |d| | |d| d S )	Nr   c                   @   s   e Zd ZdZdS )z7ProtocolTests.test_protocols_isinstance_init.<locals>.Pr   NrO  r;   r;   r;   r<   r,    s   r,  c                   @   s   e Zd ZdZdS )z8ProtocolTests.test_protocols_isinstance_init.<locals>.PGr   NrO  r;   r;   r;   r<   r9    s   r9  c                   @   s   e Zd Zdd ZdS )z7ProtocolTests.test_protocols_isinstance_init.<locals>.Cc                 S   s
   || _ d S r?   r   r7   r   r;   r;   r<   r    s    z@ProtocolTests.test_protocols_isinstance_init.<locals>.C.__init__NrY  r;   r;   r;   r<   r     s   r   r   )r
   r   r   rk   )r7   r   r,  r9  r   r;   r;   r<   test_protocols_isinstance_init  s    z,ProtocolTests.test_protocols_isinstance_initc           	      C   s   G dd dt t }G dd d|t }G dd d}G dd d}|t }| | | | || G d	d
 d
|t }G dd d|t }|t }| | | | || d S )Nc                   @   s   e Zd ZdS )z=ProtocolTests.test_protocol_checks_after_subscript.<locals>.PNrI   r;   r;   r;   r<   r,    r   r,  c                   @   s   e Zd ZdS )z=ProtocolTests.test_protocol_checks_after_subscript.<locals>.CNrI   r;   r;   r;   r<   r     r   r   c                   @   s   e Zd ZdS )zBProtocolTests.test_protocol_checks_after_subscript.<locals>.Other1NrI   r;   r;   r;   r<   Other1  r   rd  c                   @   s   e Zd ZdS )zBProtocolTests.test_protocol_checks_after_subscript.<locals>.Other2NrI   r;   r;   r;   r<   Other2  r   re  c                   @   s   e Zd ZdS )z>ProtocolTests.test_protocol_checks_after_subscript.<locals>.D1NrI   r;   r;   r;   r<   D1   r   rf  c                   @   s   e Zd ZdS )z>ProtocolTests.test_protocol_checks_after_subscript.<locals>.D2NrI   r;   r;   r;   r<   D2  r   rg  )r   r   r   r   r>   rY   rk   r=   )	r7   r,  r   rd  re  ZCArf  rg  CIr;   r;   r<   $test_protocol_checks_after_subscript  s    z2ProtocolTests.test_protocol_checks_after_subscriptc                 C   sv   t G dd dt}G dd dt}G dd d|}G dd d}|| || | | | | | | d S )	Nc                   @   s   e Zd ZdZdS )z8ProtocolTests.test_protocols_support_register.<locals>.Pr   NrO  r;   r;   r;   r<   r,    s   r,  c                   @   s   e Zd Zdd ZdS )z9ProtocolTests.test_protocols_support_register.<locals>.PMc                 S   s   d S r?   r;   rS   r;   r;   r<   r#    r   z>ProtocolTests.test_protocols_support_register.<locals>.PM.methNr+  r;   r;   r;   r<   PM  s   rj  c                   @   s   e Zd ZdS )z8ProtocolTests.test_protocols_support_register.<locals>.DNrI   r;   r;   r;   r<   r-    r   r-  c                   @   s   e Zd ZdS )z8ProtocolTests.test_protocols_support_register.<locals>.CNrI   r;   r;   r;   r<   r     r   r   )r   r   rU  rk   )r7   r,  rj  r-  r   r;   r;   r<   test_protocols_support_register  s    

z-ProtocolTests.test_protocols_support_registerc                 C   s`   t G dd dt}G dd d}G dd d|}G dd d}| | | | | | d S )	Nc                   @   s   e Zd ZdZdS )zNProtocolTests.test_none_on_non_callable_doesnt_block_implementation.<locals>.Pr   NrO  r;   r;   r;   r<   r,    s   r,  c                   @   s   e Zd ZdZdS )zNProtocolTests.test_none_on_non_callable_doesnt_block_implementation.<locals>.Ar   NrO  r;   r;   r;   r<   r\     s   r\   c                   @   s   e Zd ZdZdS )zNProtocolTests.test_none_on_non_callable_doesnt_block_implementation.<locals>.BNrO  r;   r;   r;   r<   r@     s   r@  c                   @   s   e Zd Zdd ZdS )zNProtocolTests.test_none_on_non_callable_doesnt_block_implementation.<locals>.Cc                 S   s
   d | _ d S r?   r   rS   r;   r;   r<   r  $  s    zWProtocolTests.test_none_on_non_callable_doesnt_block_implementation.<locals>.C.__init__NrY  r;   r;   r;   r<   r   #  s   r   )r   r   rk   r7   r,  r\   r@  r   r;   r;   r<   5test_none_on_non_callable_doesnt_block_implementation  s    zCProtocolTests.test_none_on_non_callable_doesnt_block_implementationc                 C   s`   t G dd dt}G dd d}G dd d|}G dd d}| | | | | | d S )	Nc                   @   s   e Zd Zdd ZdS )zDProtocolTests.test_none_on_callable_blocks_implementation.<locals>.Pc                 S   s   d S r?   r;   rS   r;   r;   r<   r   -  r   zFProtocolTests.test_none_on_callable_blocks_implementation.<locals>.P.xNrO  r;   r;   r;   r<   r,  +  s   r,  c                   @   s   e Zd Zdd ZdS )zDProtocolTests.test_none_on_callable_blocks_implementation.<locals>.Ac                 S   s   d S r?   r;   rS   r;   r;   r<   r   0  r   zFProtocolTests.test_none_on_callable_blocks_implementation.<locals>.A.xNrO  r;   r;   r;   r<   r\   /  s   r\   c                   @   s   e Zd ZdZdS )zDProtocolTests.test_none_on_callable_blocks_implementation.<locals>.BNrO  r;   r;   r;   r<   r@  2  s   r@  c                   @   s   e Zd Zdd ZdS )zDProtocolTests.test_none_on_callable_blocks_implementation.<locals>.Cc                 S   s
   d | _ d S r?   r   rS   r;   r;   r<   r  6  s    zMProtocolTests.test_none_on_callable_blocks_implementation.<locals>.C.__init__NrY  r;   r;   r;   r<   r   5  s   r   )r   r   r   rl  r;   r;   r<   +test_none_on_callable_blocks_implementation*  s    z9ProtocolTests.test_none_on_callable_blocks_implementationc                 C   s   G dd dt }tG dd dt }G dd d|}G dd d|}G d	d
 d
}G dd d}| | | | | | | || | || | | | | || d S )Nc                   @   s   e Zd ZdZdS )z5ProtocolTests.test_non_protocol_subclasses.<locals>.Pr   NrO  r;   r;   r;   r<   r,  =  s   r,  c                   @   s   e Zd Zdd ZdS )z6ProtocolTests.test_non_protocol_subclasses.<locals>.PRc                 S   s   d S r?   r;   rS   r;   r;   r<   r#  B  r   z;ProtocolTests.test_non_protocol_subclasses.<locals>.PR.methNr+  r;   r;   r;   r<   PR@  s   ro  c                   @   s   e Zd ZdZdS )z8ProtocolTests.test_non_protocol_subclasses.<locals>.NonPr   NrO  r;   r;   r;   r<   NonPD  s   rp  c                   @   s   e Zd ZdS )z9ProtocolTests.test_non_protocol_subclasses.<locals>.NonPRNrI   r;   r;   r;   r<   NonPRG  r   rq  c                   @   s   e Zd ZdZdS )z5ProtocolTests.test_non_protocol_subclasses.<locals>.Cr   NrO  r;   r;   r;   r<   r   I  s   r   c                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_non_protocol_subclasses.<locals>.Dc                 S   s   d S r?   r;   rS   r;   r;   r<   r#  M  r   z:ProtocolTests.test_non_protocol_subclasses.<locals>.D.methNr+  r;   r;   r;   r<   r-  L  s   r-  rL  )r7   r,  ro  rp  rq  r   r-  r;   r;   r<   test_non_protocol_subclasses<  s    z*ProtocolTests.test_non_protocol_subclassesc                 C   st   G dd dt }G dd d}G dd d}G dd d|}| | | | | | | || | || d S )	Nc                   @   s   e Zd ZdZdS )z1ProtocolTests.test_custom_subclasshook.<locals>.Pr   NrO  r;   r;   r;   r<   r,  W  s   r,  c                   @   s   e Zd ZdS )z7ProtocolTests.test_custom_subclasshook.<locals>.OKClassNrI   r;   r;   r;   r<   OKClassZ  r   rs  c                   @   s   e Zd ZdZdS )z8ProtocolTests.test_custom_subclasshook.<locals>.BadClassr   NrO  r;   r;   r;   r<   BadClass\  s   rt  c                   @   s   e Zd Zedd ZdS )z1ProtocolTests.test_custom_subclasshook.<locals>.Cc                 S   s   |j dS NOK)rE   
startswithr8   otherr;   r;   r<   __subclasshook__`  s    zBProtocolTests.test_custom_subclasshook.<locals>.C.__subclasshook__NrE   rF   rG   classmethodrz  r;   r;   r;   r<   r   _  s   r   )r   rk   r   r=   r>   )r7   r,  rs  rt  r   r;   r;   r<   test_custom_subclasshookV  s    z&ProtocolTests.test_custom_subclasshookc                 C   s\   t G dd dt}G dd d}| t t| | W d    n1 sN0    Y  d S )Nc                   @   s   e Zd ZdZdS )z8ProtocolTests.test_issubclass_fails_correctly.<locals>.Pr   NrO  r;   r;   r;   r<   r,  j  s   r,  c                   @   s   e Zd ZdS )z8ProtocolTests.test_issubclass_fails_correctly.<locals>.CNrI   r;   r;   r;   r<   r   n  r   r   )r   r   rP   rQ   r5   )r7   r,  r   r;   r;   r<   test_issubclass_fails_correctlyi  s
    z-ProtocolTests.test_issubclass_fails_correctlyc                 C   sN  t d}t d}tG dd dt||f }G dd d|t|f t| }| t |t  W d    n1 sr0    Y  | t |ttf  W d    n1 s0    Y  | t |tdf  W d    n1 s0    Y  | t |ttf  W d    n1 s0    Y  G dd	 d	|t|f }| |t  | d S )
Nr   Sc                   @   s   e Zd Zdd ZdS )z9ProtocolTests.test_defining_generic_protocols.<locals>.PRc                 S   s   d S r?   r;   rS   r;   r;   r<   r#  y  r   z>ProtocolTests.test_defining_generic_protocols.<locals>.PR.methNr+  r;   r;   r;   r<   ro  w  s   ro  c                   @   s   e Zd ZdZdS )z8ProtocolTests.test_defining_generic_protocols.<locals>.Pr   NrE   rF   rG   r   r;   r;   r;   r<   r,  {  s   r,  r   c                   @   s   e Zd ZdS )z8ProtocolTests.test_defining_generic_protocols.<locals>.CNrI   r;   r;   r;   r<   r     r   r   )	r
   r   r   rY   rP   rQ   r{   r   rk   )r7   r   r  ro  r,  r   r;   r;   r<   test_defining_generic_protocolss  s    &**,z-ProtocolTests.test_defining_generic_protocolsc                    s  t d t d}tG dd dtt |f }G dd d|ttf t}| t" t|ttf | W d    n1 sz0    Y  | 	|| | t |t  W d    n1 s0    Y  | t |tdf  W d    n1 s0    Y  G  fdd	d	tt  }G  fd
ddt  t}tG dd d|t t}G dd d}| 
| | | t |ttf  W d    n1 s0    Y  d S )Nr   r  c                   @   s   e Zd Zdd ZdS )zCProtocolTests.test_defining_generic_protocols_old_style.<locals>.PRc                 S   s   d S r?   r;   rS   r;   r;   r<   r#    r   zHProtocolTests.test_defining_generic_protocols_old_style.<locals>.PR.methNr+  r;   r;   r;   r<   ro    s   ro  c                   @   s   e Zd ZdZdS )zBProtocolTests.test_defining_generic_protocols_old_style.<locals>.Pr   Nr  r;   r;   r;   r<   r,    s   r,  r   c                       s   e Zd Z edddZdS )zCProtocolTests.test_defining_generic_protocols_old_style.<locals>.P1r   r   c                 S   s   d S r?   r;   rb  r;   r;   r<   r     r   zGProtocolTests.test_defining_generic_protocols_old_style.<locals>.P1.barNrE   rF   rG   r{   r   r;   r   r;   r<   rE    s   rE  c                       s   e Zd Z edddZdS )zCProtocolTests.test_defining_generic_protocols_old_style.<locals>.P2r  c                 S   s   d S r?   r;   rb  r;   r;   r<   r     r   zGProtocolTests.test_defining_generic_protocols_old_style.<locals>.P2.barNr  r;   r  r;   r<   rH    s   rH  c                   @   s   e Zd ZdZdS )zEProtocolTests.test_defining_generic_protocols_old_style.<locals>.PSubr   NrO  r;   r;   r;   r<   PSub  s   r  c                   @   s    e Zd ZdZeedddZdS )zEProtocolTests.test_defining_generic_protocols_old_style.<locals>.Testr   r  c                 S   s   |S r?   r;   rb  r;   r;   r<   r     s    zIProtocolTests.test_defining_generic_protocols_old_style.<locals>.Test.barN)rE   rF   rG   r   r{   r   r;   r;   r;   r<   Test  s   r  )r
   r   r   r   rY   r{   rP   rQ   r5   r=   rk   r   )r7   r  ro  r,  rE  rH  r  r  r;   r  r<   )test_defining_generic_protocols_old_style  s(    0&*z7ProtocolTests.test_defining_generic_protocols_old_stylec                 C   s   t d}G dd dt| }G dd d|| }| |t  jd G dd d}G d	d
 d
||| }| |t  jd G dd d|| |}| |t  jd d S )Nr   c                   @   s   e Zd ZdS )z)ProtocolTests.test_init_called.<locals>.PNrI   r;   r;   r;   r<   r,    r   r,  c                   @   s   e Zd Zdd ZdS )z)ProtocolTests.test_init_called.<locals>.Cc                 S   s
   d| _ d S ru  testrS   r;   r;   r<   r    s    z2ProtocolTests.test_init_called.<locals>.C.__init__NrY  r;   r;   r;   r<   r     s   r   rv  c                   @   s   e Zd Zdd ZdS )z)ProtocolTests.test_init_called.<locals>.Bc                 S   s
   d| _ d S ru  r  rS   r;   r;   r<   r    s    z2ProtocolTests.test_init_called.<locals>.B.__init__NrY  r;   r;   r;   r<   r@    s   r@  c                   @   s   e Zd ZdS )z*ProtocolTests.test_init_called.<locals>.D1NrI   r;   r;   r;   r<   rf    s   rf  c                   @   s   e Zd ZdS )z*ProtocolTests.test_init_called.<locals>.D2NrI   r;   r;   r;   r<   rg    s   rg  )r
   r   rV   rY   r  )r7   r   r,  r   r@  rf  rg  r;   r;   r<   test_init_called  s    zProtocolTests.test_init_calledc                 C   s   t d}G dd dt| }G dd d|| }| |t  jd | t |t d W d    n1 sp0    Y  | t |t dd W d    n1 s0    Y  d S )	Nr   c                   @   s   e Zd ZdS )z(ProtocolTests.test_new_called.<locals>.PNrI   r;   r;   r;   r<   r,    r   r,  c                       s   e Zd Z fddZ  ZS )z(ProtocolTests.test_new_called.<locals>.Cc                    s   t  j| g|R  }d|_|S ru  )super__new__r  )r8   r   r7   	__class__r;   r<   r    s    z0ProtocolTests.test_new_called.<locals>.C.__new__rE   rF   rG   r  __classcell__r;   r;   r  r<   r     s   r   rv  rO   r   )r
   r   rV   rY   r  rP   rQ   )r7   r   r,  r   r;   r;   r<   test_new_called  s    *zProtocolTests.test_new_calledc                 C   s$  t d}t d}| t( G dd dt||f }W d    n1 sH0    Y  | t$ G dd dtt }W d    n1 s0    Y  | t* G dd dt| t| }W d    n1 s0    Y  | t0 G dd dtj||f t| }W d    n1 s0    Y  d S )Nr   r  c                   @   s   e Zd ZdS z6ProtocolTests.test_protocols_bad_subscripts.<locals>.PNrI   r;   r;   r;   r<   r,    r   r,  c                   @   s   e Zd ZdS r  rI   r;   r;   r;   r<   r,    r   c                   @   s   e Zd ZdS r  rI   r;   r;   r;   r<   r,    r   c                   @   s   e Zd ZdS r  rI   r;   r;   r;   r<   r,    r   )r
   rP   rQ   r   rY   r@   r   r7   r   r  r,  r;   r;   r<   test_protocols_bad_subscripts  s    628z+ProtocolTests.test_protocols_bad_subscriptsc                 C   sd   t d}t d}G dd dt||f }| t|||f d | t|ttf d d S )Nr   r  c                   @   s   e Zd ZdS )z4ProtocolTests.test_generic_protocols_repr.<locals>.PNrI   r;   r;   r;   r<   r,    r   r,  z	P[~T, ~S]zP[int, str])r
   r   r   rW   endswithrY   r{   r  r;   r;   r<   test_generic_protocols_repr  s
    z)ProtocolTests.test_generic_protocols_reprc                 C   s   t d}t d}G dd dt||f }| || | |t|f |t|f  | |||f t||f  ttf |tttf tttf f  d S )Nr   r  c                   @   s   e Zd ZdS )z2ProtocolTests.test_generic_protocols_eq.<locals>.PNrI   r;   r;   r;   r<   r,    r   r,  )r
   r   rV   rY   r   r{   r  r;   r;   r<   test_generic_protocols_eq  s    "z'ProtocolTests.test_generic_protocols_eqc                 C   sh   t d}G dd dt| }| |j|f | |t jd | |t jtf | |t j| d S )Nr   c                   @   s   e Zd ZdS )zDProtocolTests.test_generic_protocols_special_from_generic.<locals>.PNrI   r;   r;   r;   r<   r,    r   r,  r;   )r
   r   rV   rv   rY   ru   rw   rx   )r7   r   r,  r;   r;   r<   +test_generic_protocols_special_from_generic  s    z9ProtocolTests.test_generic_protocols_special_from_genericc                 C   s   t G dd dt}G dd dt}td}G dd dt| }| |j | |j | |j | |j | |j | |t j | t	
|dh | t	
|d	h | tt	
|td	dh d S )
Nc                   @   s   e Zd ZdZdS )zFProtocolTests.test_generic_protocols_special_from_protocol.<locals>.PRr   NrO  r;   r;   r;   r<   ro    s   ro  c                   @   s   e Zd Zdd ZdS )zEProtocolTests.test_generic_protocols_special_from_protocol.<locals>.Pc                 S   s   d S r?   r;   rS   r;   r;   r<   r#    s    zJProtocolTests.test_generic_protocols_special_from_protocol.<locals>.P.methNr+  r;   r;   r;   r<   r,    s   r,  r   c                   @   s   e Zd ZdZdd ZdS )zFProtocolTests.test_generic_protocols_special_from_protocol.<locals>.PGr   c                 S   s   d S r?   r;   rS   r;   r;   r<   r#    s    zKProtocolTests.test_generic_protocols_special_from_protocol.<locals>.PG.methN)rE   rF   rG   r   r#  r;   r;   r;   r<   r9    s   r9  r#  r   )r   r   r
   r   _is_protocolr   _is_runtime_protocolrY   rV   r@   _get_protocol_attrs	frozenset)r7   ro  r,  r   r9  r;   r;   r<   ,test_generic_protocols_special_from_protocol  s     
z:ProtocolTests.test_generic_protocols_special_from_protocolc                 C   s   |  t" tG dd d}W d    n1 s20    Y  G dd dt}|  t$ tG dd d|}W d    n1 s0    Y  d S )Nc                   @   s   e Zd ZdS )z8ProtocolTests.test_no_runtime_deco_on_nominal.<locals>.CNrI   r;   r;   r;   r<   r   $  s   r   c                   @   s   e Zd ZdZdS )z<ProtocolTests.test_no_runtime_deco_on_nominal.<locals>.Protor   NrO  r;   r;   r;   r<   r  '  s   r  c                   @   s   e Zd ZdS )z?ProtocolTests.test_no_runtime_deco_on_nominal.<locals>.ConcreteNrI   r;   r;   r;   r<   r$  +  s   r$  )rP   rQ   r   r   )r7   r   r  r$  r;   r;   r<   test_no_runtime_deco_on_nominal"  s    .z-ProtocolTests.test_no_runtime_deco_on_nominalc                 C   s   t G dd dt}G dd dt}| | | G dd d}G dd d}| | | | | | G d	d
 d
}G dd d}| | | | | | d S )Nc                   @   s   e Zd ZdZdS )z4ProtocolTests.test_none_treated_correctly.<locals>.PNrO  r;   r;   r;   r<   r,  0  s   r,  c                   @   s   e Zd ZdS )z4ProtocolTests.test_none_treated_correctly.<locals>.BNrI   r;   r;   r;   r<   r@  4  r   r@  c                   @   s   e Zd ZdZdS )z4ProtocolTests.test_none_treated_correctly.<locals>.Cr   NrO  r;   r;   r;   r<   r   8  s   r   c                   @   s   e Zd ZdZdS )z4ProtocolTests.test_none_treated_correctly.<locals>.DNrO  r;   r;   r;   r<   r-  ;  s   r-  c                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_none_treated_correctly.<locals>.CIc                 S   s
   d| _ d S r   r   rS   r;   r;   r<   r  B  s    z>ProtocolTests.test_none_treated_correctly.<locals>.CI.__init__NrY  r;   r;   r;   r<   rh  A  s   rh  c                   @   s   e Zd Zdd ZdS )z5ProtocolTests.test_none_treated_correctly.<locals>.DIc                 S   s
   d | _ d S r?   r   rS   r;   r;   r<   r  F  s    z>ProtocolTests.test_none_treated_correctly.<locals>.DI.__init__NrY  r;   r;   r;   r<   DIE  s   r  )r   r   r   r   rk   )r7   r,  r@  r   r-  rh  r  r;   r;   r<   test_none_treated_correctly/  s    z)ProtocolTests.test_none_treated_correctlyc                 C   s@   G dd dt }tjtj|f }tj|tjf }| || d S )Nc                   @   s   e Zd ZdZdS )z1ProtocolTests.test_protocols_in_unions.<locals>.PNrO  r;   r;   r;   r<   r,  M  s   r,  )r   r@   r   r   rV   )r7   r,  ZAliasZAlias2r;   r;   r<   test_protocols_in_unionsL  s    z&ProtocolTests.test_protocols_in_unionsc           	      C   s   t d}tG dd dt| aG dd dtt at }d|_d|_tt	j
d D ]}t	||}t	|}| |jd | |jd | |jd | |jddd	 t	t}t	|}G d
d d}| | | qTd S )Nr   c                   @   s   e Zd ZdZdS )r,  r   NrO  r;   r;   r;   r<   r,  X  s   r,  c                   @   s   e Zd ZdS )CPNrI   r;   r;   r;   r<   r  \  s   r  rO   r>  r   r   c                   @   s   e Zd ZdZdS )z2ProtocolTests.test_protocols_pickleable.<locals>.Er   NrO  r;   r;   r;   r<   r7  l  s   r7  )r
   r   r   r,  rY   r  r   r   rangepickleHIGHEST_PROTOCOLdumpsloadsrV   r   __dict__rk   )	r7   r   r   protor   r   sr-  r7  r;   r;   r<   test_protocols_pickleableT  s$    


z'ProtocolTests.test_protocols_pickleablec                 C   s    |  ttj | ttj d S r?   )r=   rY   r@   SupportsIntr>   r{   rS   r;   r;   r<   test_supports_intq  s    zProtocolTests.test_supports_intc                 C   s    |  ttj | ttj d S r?   )r=   r   r@   SupportsFloatr>   r{   rS   r;   r;   r<   test_supports_floatu  s    z!ProtocolTests.test_supports_floatc                 C   s.   G dd d}|  |tj | ttj d S )Nc                   @   s   e Zd Zdd ZdS )z.ProtocolTests.test_supports_complex.<locals>.Cc                 S   s   dS )Ny                r;   rS   r;   r;   r<   __complex__}  s    z:ProtocolTests.test_supports_complex.<locals>.C.__complex__N)rE   rF   rG   r  r;   r;   r;   r<   r   |  s   r   )r=   r@   SupportsComplexr>   r{   r   r;   r;   r<   test_supports_complexy  s    z#ProtocolTests.test_supports_complexc                 C   s.   G dd d}|  |tj | ttj d S )Nc                   @   s   e Zd Zdd ZdS )z,ProtocolTests.test_supports_bytes.<locals>.Bc                 S   s   dS Nr   r;   rS   r;   r;   r<   	__bytes__  s    z6ProtocolTests.test_supports_bytes.<locals>.B.__bytes__N)rE   rF   rG   r  r;   r;   r;   r<   r@    s   r@  )r=   r@   SupportsBytesr>   r{   )r7   r@  r;   r;   r<   test_supports_bytes  s    z!ProtocolTests.test_supports_bytesc                 C   s.   |  ttj |  ttj | ttj d S r?   )r=   r   r@   SupportsAbsrY   r>   r{   rS   r;   r;   r<   test_supports_abs  s    zProtocolTests.test_supports_absc                 C   s:   t ttj | ttj | ttj | ttj d S r?   )r5   r   r@   SupportsRoundr=   rY   r>   r{   rS   r;   r;   r<   test_supports_round  s    z!ProtocolTests.test_supports_roundc                 C   s    |  ttj | ttj d S r?   )r=   r   r@   
Reversibler>   rY   rS   r;   r;   r<   test_reversible  s    zProtocolTests.test_reversiblec                 C   s    |  ttj | ttj d S r?   )r=   rY   r@   SupportsIndexr>   r{   rS   r;   r;   r<   test_supports_index  s    z!ProtocolTests.test_supports_indexc                 C   sF   |  dtj G dd dtj}G dd d|}| }|  || d S )Nr   c                   @   s   e Zd ZedddZdS )z>ProtocolTests.test_bundled_protocol_instance_works.<locals>.C1r   c                 S   s   dS rN   r;   rS   r;   r;   r<   __int__  s    zFProtocolTests.test_bundled_protocol_instance_works.<locals>.C1.__int__N)rE   rF   rG   rY   r  r;   r;   r;   r<   rJ    s   rJ  c                   @   s   e Zd ZdS )z>ProtocolTests.test_bundled_protocol_instance_works.<locals>.C2NrI   r;   r;   r;   r<   rK    s   rK  )rk   r@   r  r  )r7   rJ  rK  r   r;   r;   r<   $test_bundled_protocol_instance_works  s
    z2ProtocolTests.test_bundled_protocol_instance_worksc                 C   sR   t G dd dtjjt}G dd d}G dd d}| || | || d S )Nc                   @   s   e Zd Zdd ZdS )z@ProtocolTests.test_collections_protocols_allowed.<locals>.Customc                 S   s   d S r?   r;   rS   r;   r;   r<   close  r   zFProtocolTests.test_collections_protocols_allowed.<locals>.Custom.closeN)rE   rF   rG   r  r;   r;   r;   r<   Custom  s   r  c                   @   s   e Zd ZdS )z;ProtocolTests.test_collections_protocols_allowed.<locals>.ANrI   r;   r;   r;   r<   r\     r   r\   c                   @   s   e Zd Zdd Zdd ZdS )z;ProtocolTests.test_collections_protocols_allowed.<locals>.Bc                 S   s   g S r?   r;   rS   r;   r;   r<   __iter__  s    zDProtocolTests.test_collections_protocols_allowed.<locals>.B.__iter__c                 S   s   dS r_  r;   rS   r;   r;   r<   r    s    zAProtocolTests.test_collections_protocols_allowed.<locals>.B.closeN)rE   rF   rG   r  r  r;   r;   r;   r<   r@    s   r@  )r   collectionsr>  r   r   r=   r>   )r7   r  r\   r@  r;   r;   r<   "test_collections_protocols_allowed  s    z0ProtocolTests.test_collections_protocols_allowedc                 C   sT   |  t" G dd dtt}W d    n1 s20    Y  G dd dtjt}d S )Nc                   @   s   e Zd ZdS )zEProtocolTests.test_builtin_protocol_whitelist.<locals>.CustomProtocolNrI   r;   r;   r;   r<   CustomProtocol  s   r  c                   @   s   e Zd ZdS )zKProtocolTests.test_builtin_protocol_whitelist.<locals>.CustomContextManagerNrI   r;   r;   r;   r<   CustomContextManager  s   r  )rP   rQ   r   r   r@   ContextManager)r7   r  r  r;   r;   r<   test_builtin_protocol_whitelist  s    0z-ProtocolTests.test_builtin_protocol_whitelistc                 C   s*   G dd dt }G dd d|}|  d S )Nc                   @   s   e Zd ZU eed< dS )z-ProtocolTests.test_super_call_init.<locals>.Pr   Nr  r;   r;   r;   r<   r,    s   
r,  c                       s   e Zd Z fddZ  ZS )z/ProtocolTests.test_super_call_init.<locals>.Fooc                    s   t    d S r?   )r  r  rS   r  r;   r<   r    s    z8ProtocolTests.test_super_call_init.<locals>.Foo.__init__rE   rF   rG   r  r  r;   r;   r  r<   r     s   r   )r   )r7   r,  r   r;   r;   r<   test_super_call_init  s    z"ProtocolTests.test_super_call_initN)0rE   rF   rG   r0  r3  r4  r8  r;  rB  rM  rN  rS  rV  rW  ra  rc  ri  rk  rm  rn  rr  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*    sZ    #%%
'	



r*  c                   @   s  e Z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)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'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2daS )bGenericTestsc                 C   s0  t ttf }| |jd | t |t  W d    n1 sB0    Y  | t |ttf  W d    n1 sx0    Y  t ttf }| |jtf |t  | t |ttf  W d    n1 s0    Y  t ttf }| t t	|t  W d    n1 s0    Y  | 
| t  d S r   )r  r{   r   rV   rv   rP   rQ   r  rY   r5   rk   )r7   rp   rs   ZSM1r;   r;   r<   r     s    &***zGenericTests.test_basicsc                 C   s  t d}t d}| t t| |  W d    n1 s<0    Y  | t t| |  W d    n1 sr0    Y  | t* G dd dt| t| }W d    n1 s0    Y  | t tg tt  W d    n1 s0    Y  | t tttt  W d    n1 s(0    Y  | t  G dd dt}W d    n1 sd0    Y  | t* G dd dt| t| }W d    n1 s0    Y  | t* G d	d dt| t| }W d    n1 s0    Y  d S )
Nr   r  c                   @   s   e Zd ZdS )z+GenericTests.test_generic_errors.<locals>.CNrI   r;   r;   r;   r<   r     r   r   c                   @   s   e Zd ZdS )z4GenericTests.test_generic_errors.<locals>.NewGenericNrI   r;   r;   r;   r<   
NewGeneric  r   r  c                   @   s   e Zd ZdS z3GenericTests.test_generic_errors.<locals>.MyGenericNrI   r;   r;   r;   r<   	MyGeneric  r   r  c                   @   s   e Zd ZdS r  rI   r;   r;   r;   r<   r    r   )	r
   rP   rQ   r   rR   r   rY   r5   r   )r7   r   r  r   r  r  r;   r;   r<   test_generic_errors  s$    **8,.0:z GenericTests.test_generic_errorsc                 C   s   t d}t d}| t t||f  W d    n1 s<0    Y  | t t|||f  W d    n1 st0    Y  d S )Nr   r  )r
   rP   rQ   r   )r7   r   r  r;   r;   r<   	test_init  s    *zGenericTests.test_initc                 C   s   G dd dt jt }G dd d|}| |jd | t |j W d    n1 sZ0    Y  d|_d|_G dd	 d	|}G d
d d|t }| |jd | |jd | |jd d S )Nc                       s   e Zd Z fddZ  ZS )z*GenericTests.test_init_subclass.<locals>.Xc                    s   t  jf i | d| _d S rN   )r  __init_subclass__r  )r8   kwargsr  r;   r<   r    s    z<GenericTests.test_init_subclass.<locals>.X.__init_subclass__rE   rF   rG   r  r  r;   r;   r  r<   rp     s   rp   c                   @   s   e Zd ZdS )z*GenericTests.test_init_subclass.<locals>.YNrI   r;   r;   r;   r<   rs      s   rs   rO   r   r   c                   @   s   e Zd ZdS )z*GenericTests.test_init_subclass.<locals>.ZNrI   r;   r;   r;   r<   Z  s   r  c                   @   s   e Zd ZdS )z*GenericTests.test_init_subclass.<locals>.WNrI   r;   r;   r;   r<   W	  s   r  )r@   r   r   rV   r  rP   AttributeErrorrY   )r7   rp   rs   r  r  r;   r;   r<   test_init_subclass  s    $zGenericTests.test_init_subclassc                 C   s4   |  ttdt d |  ttdt d d S )Nz<class 'z.SimpleMapping'>z.MySimpleMapping'>)rV   rW   r  rE   r  rS   r;   r;   r<   rX     s    



zGenericTests.test_reprc                 C   s   t d}t d}G dd dt| }|t||f  }| ||t||f   | ||t||f   ||tf }| |||tf  | |||tf  | |||tf  |t }| ||t  | ||t  | |||  | t|d d S )Nr   r  c                   @   s   e Zd ZdS )z'GenericTests.test_chain_repr.<locals>.CNrI   r;   r;   r;   r<   r     s   r   z.C[typing.Tuple[str, int]])	r
   r   r   rV   rt   rY   r{   r   r  )r7   r   r  r   rp   rs   r  r;   r;   r<   test_chain_repr  s"    zGenericTests.test_chain_reprc                 C   s   t d}t ddd}t d}| ttd | tt| d | tt| d | tt| | t d	 | ttt d	 d S )
Nr   UTr   r  ztyping.Listztyping.List[~T]ztyping.List[+U]ztyping.List[int])r
   rV   rW   r   rY   )r7   r   r  r  r;   r;   r<   test_new_repr-  s    zGenericTests.test_new_reprc                 C   s~   t d}t d}| ttj||f ||f d | ttt||f  t|f d | ttt||f  tt  d d S )Nr   TSztyping.Mapping[~TS, ~T]z"typing.List[typing.Tuple[int, ~T]]z=typing.List[typing.Tuple[typing.List[int], typing.List[int]]])r
   rV   rW   r@   r   r   r   rY   )r7   r   r  r;   r;   r<   test_new_repr_complex8  s    "z"GenericTests.test_new_repr_complexc                 C   sZ   t d}| tt| d | ttj| d G dd dtjttf }t|j d S )Nr   ztyping.Generic[~T]ztyping.Protocol[~T]c                   @   s   e Zd ZdS )z*GenericTests.test_new_repr_bare.<locals>.CNrI   r;   r;   r;   r<   r   H  r   r   )	r
   rV   rW   r   r@   r   r   r   __mro__r7   r   r   r;   r;   r<   test_new_repr_bareD  s
    zGenericTests.test_new_repr_barec                 C   sp   t d}G dd dt| }| }d|_| |jddi G dd d|t }| }d|_| |jd	di d S )
Nr   c                   @   s   e Zd ZdS )z!GenericTests.test_dict.<locals>.BNrI   r;   r;   r;   r<   r@  O  s   r@  rO   r   c                   @   s   e Zd ZdS )z!GenericTests.test_dict.<locals>.CNrI   r;   r;   r;   r<   r   V  s   r   r>  r   )r
   r   r   rV   r  rY   r   )r7   r   r@  br   r   r;   r;   r<   	test_dictL  s    zGenericTests.test_dictc                 C   sT  t d}G dd dt| }| |t jd | ||t  jd d||t  _| |jd | |t jd d|tt  _| |jd | |tt  jd | | jd | |tt   jd G dd d|| }| |t jd | |jd d	|_d
|t _| |jd | |t jd | |jd
 | |t jd	 d S )Nr   c                   @   s   e Zd ZdZdS )z<GenericTests.test_subscripted_generics_as_proxies.<locals>.CdefNrO  r;   r;   r;   r<   r   _  s   r   r  changednewc                   @   s   e Zd ZdS )z<GenericTests.test_subscripted_generics_as_proxies.<locals>.DNrI   r;   r;   r;   r<   r-  m  s   r-  zfrom derived zzfrom derived x)	r
   r   rV   rY   r   r{   r   r   r   r7   r   r   r-  r;   r;   r<   $test_subscripted_generics_as_proxies]  s*    
z1GenericTests.test_subscripted_generics_as_proxiesc                 C   s`   t d}G dd dtjjt| }|t | d| |t  | d| |  |	  d S )Nr   c                   @   s   e Zd ZdS )z.GenericTests.test_abc_registry_kept.<locals>.CNrI   r;   r;   r;   r<   r   z  r   r   r   )
r
   r  r>  r   r   rU  rY   rk   _abc_registry_clear_abc_caches_clearr  r;   r;   r<   test_abc_registry_keptx  s    
z#GenericTests.test_abc_registry_keptc                 C   s4   G dd dt ttf }| i | | t| d S )Nc                   @   s   e Zd ZdS )z5GenericTests.test_false_subclasses.<locals>.MyMappingNrI   r;   r;   r;   r<   	MyMapping  r   r  )r   r{   r   r>   r   )r7   r  r;   r;   r<   test_false_subclasses  s    z"GenericTests.test_false_subclassesc                 C   s`   G dd dt ttf }|   | | tjj  | | t  | | t | i | d S )Nc                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )z'GenericTests.test_abc_bases.<locals>.MMc                 S   s   d S r?   r;   r7   kr;   r;   r<   r    s    z3GenericTests.test_abc_bases.<locals>.MM.__getitem__c                 S   s   d S r?   r;   r7   r  r   r;   r;   r<   r
    s    z3GenericTests.test_abc_bases.<locals>.MM.__setitem__c                 S   s   d S r?   r;   r  r;   r;   r<   __delitem__  s    z3GenericTests.test_abc_bases.<locals>.MM.__delitem__c                 S   s   t dS r   iterrS   r;   r;   r<   r    s    z0GenericTests.test_abc_bases.<locals>.MM.__iter__c                 S   s   dS r_  r;   rS   r;   r;   r<   __len__  s    z/GenericTests.test_abc_bases.<locals>.MM.__len__NrE   rF   rG   r  r
  r  r  r  r;   r;   r;   r<   MM  s
   r  )r   r{   updaterk   r  r>  r   r   )r7   r  r;   r;   r<   test_abc_bases  s    
zGenericTests.test_abc_basesc                 C   sV   G dd dt ttf tjj }G dd dtjj t ttf }| |jtjj tf d S )Nc                   @   s   e Zd ZdS )z-GenericTests.test_multiple_bases.<locals>.MM1NrI   r;   r;   r;   r<   MM1  s   r  c                   @   s   e Zd ZdS )z-GenericTests.test_multiple_bases.<locals>.MM2NrI   r;   r;   r;   r<   MM2  s   r  )r   r{   r  r>  rV   	__bases__r   )r7   r  r  r;   r;   r<   test_multiple_bases  s    z GenericTests.test_multiple_basesc                 C   s@   t d}G dd dtjt|f }| |jtjt|f f d S )Nr   c                   @   s   e Zd ZdS )z'GenericTests.test_orig_bases.<locals>.CNrI   r;   r;   r;   r<   r     r   r   )r
   r@   r   r{   rV   __orig_bases__r  r;   r;   r<   test_orig_bases  s    zGenericTests.test_orig_basesc                 C   sr  dd }|  |dditjttf  | |dditjttf  | t( |dditjttf  W d    n1 s|0    Y  dd }G dd dt	t }|  ||t  |t  | ||t  |t  | ||t  t
 | t" |g d	|t  W d    n1 s 0    Y  d
d }G dd dt
t }|  |g d	| | |ddg| d S )Nc                    sB   t |jdkrt|jr>|j\ t fdd|  D S d S )Nr   c                 3   s&   | ]\}}t | ot |V  qd S r?   )rR   .0r  r   r   r   r;   r<   	<genexpr>  s   zSGenericTests.test_naive_runtime_checks.<locals>.naive_dict_check.<locals>.<genexpr>)r   rv   r<  ru   allitemsobjtpr;   r   r<   naive_dict_check  s    
z@GenericTests.test_naive_runtime_checks.<locals>.naive_dict_checkr   r   c                 S   s   t | dst| j|kS )N__orig_class__)hasattrr<  r  r  r;   r;   r<   naive_generic_check  s    
zCGenericTests.test_naive_runtime_checks.<locals>.naive_generic_checkc                   @   s   e Zd ZdS )z4GenericTests.test_naive_runtime_checks.<locals>.NodeNrI   r;   r;   r;   r<   Node  r   r  r   c                    s   t  fdd| D S )Nc                 3   s$   | ]}t | jd  jd  V  qdS )r   N)rR   r  ru   )r  r   r  r;   r<   r    s   zXGenericTests.test_naive_runtime_checks.<locals>.naive_list_base_check.<locals>.<genexpr>)r  r  r;   r  r<   naive_list_base_check  s    zEGenericTests.test_naive_runtime_checks.<locals>.naive_list_base_checkc                   @   s   e Zd ZdS )z1GenericTests.test_naive_runtime_checks.<locals>.CNrI   r;   r;   r;   r<   r     r   r   r   r  )r   r@   r   r{   rY   r   rP   r<  r   r   r   )r7   r  r
  r  r  r   r;   r;   r<   test_naive_runtime_checks  s     
62z&GenericTests.test_naive_runtime_checksc                 C   s"  t d}t d}t d}G dd dt| | | }G dd d|t| | | }| |j|f | |j|f | |t jd | |t jd | |t jtf | |t jtf | |jttf | |j|ttf | |j	t| | | f | |j	|t| | | f d S )	Nr   r  r   c                   @   s   e Zd ZdS )z.GenericTests.test_multi_subscr_base.<locals>.CNrI   r;   r;   r;   r<   r     r   r   c                   @   s   e Zd ZdS )z.GenericTests.test_multi_subscr_base.<locals>.DNrI   r;   r;   r;   r<   r-    r   r-  r;   )
r
   r   rV   rv   rY   ru   r  r   r   r  )r7   r   r  r   r   r-  r;   r;   r<   test_multi_subscr_base  s    z#GenericTests.test_multi_subscr_basec                 C   sj   t d}G dd dt}| t| t|  | t|tf | t|tf  | td|f jt|f d S )Nr   c                   @   s   e Zd ZdS )z.GenericTests.test_subscript_meta.<locals>.MetaNrI   r;   r;   r;   r<   Meta  r   r  .)	r
   r^   rV   r$   r   rY   r   ru   Ellipsis)r7   r   r  r;   r;   r<   test_subscript_meta  s
     z GenericTests.test_subscript_metac                 C   s  G dd dt t }G dd dt t }| || | tjt tjt  | |j|j | tjj|jt  tjj|jt   | ||j | |tj | |tjj | |jtj | |jtjj | |t |jt  | |tt	  |jtt	   | |t tjt  | |t tjjt  | |jt
 tjt
  | |jtt	  tjjtt	   | t|t  t|jt   | t|tt	   t|jtt	    | tt|t f tttjt f  | t|t |t f t|t tjt f  | tj|t  tjtjjt   tjd d dkr| tt|t  d | tt|jt  d | tttjt  d	 | tttjjt  d
 d S )Nc                   @   s   e Zd ZdS )z+GenericTests.test_generic_hashes.<locals>.ANrI   r;   r;   r;   r<   r\     s   r\   c                   @   s    e Zd ZG dd dee ZdS )z+GenericTests.test_generic_hashes.<locals>.Bc                   @   s   e Zd ZdS )z-GenericTests.test_generic_hashes.<locals>.B.ANrI   r;   r;   r;   r<   r\     s   r\   N)rE   rF   rG   r   r   r\   r;   r;   r;   r<   r@    s   r@  r   )r   r   z<locals>.A[str]]z<locals>.B.A[str]]zmod_generics_cache.A[str]]zmod_generics_cache.B.A[str]])r   r   rV   r0   r\   r{   r@  rt   r   r   rY   r   r   r@   	FrozenSetsysversion_infor   rW   r  r7   r\   r@  r;   r;   r<   test_generic_hashes  sJ    "&&z GenericTests.test_generic_hashesc                 C   sn  t d}t d}| t||f t tttf  | tjt||f  | tjt||f   | t  t|tf d  W d    n1 s0    Y  | t$ t||f |df  W d    n1 s0    Y  | t|tf t t | t||f tttt	f f ttt	f  G dd d}G dd d|}| t||f t||f  t||f  | t  t|tf d	  W d    n1 s0    Y  | t
|g|f t t
tgtf  | t
dt| f t t
dtt f  | t& t
|g|f dtf  W d    n1 s0    Y  | t& t
|g|f g tf  W d    n1 s`0    Y  d S )
Nr   r  r;   .c                   @   s   e Zd ZdS )z9GenericTests.test_extended_generic_rules_eq.<locals>.BaseNrI   r;   r;   r;   r<   Base  r   r  c                   @   s   e Zd ZdS )z<GenericTests.test_extended_generic_rules_eq.<locals>.DerivedNrI   r;   r;   r;   r<   Derived  r   r  r   )r
   rV   r   rY   r@   r   rP   rQ   r   r{   r   r   r   )r7   r   r  r  r  r;   r;   r<   test_extended_generic_rules_eq  s*     ,.2,(0$(6z+GenericTests.test_extended_generic_rules_eqc                 C   s   t d}| ttttf ddd | ttttt f ddd | ttdt| f t ddd | ttg t	| f t ddd d S )	Nr   ztyping. zUnion[Tuple, Callable]zUnion[Tuple, Tuple[int]].zCallable[..., Optional[int]]zCallable[[], List[int]])
r
   rV   rW   r   r   r   replacerY   r   r   rl   r;   r;   r<    test_extended_generic_rules_repr&  s    ""z-GenericTests.test_extended_generic_rules_reprc           	      C   s  t t d  ddd}tttd  ddd}G dd d}| t|t t dt t |  i | t|t t dtt|  i td	}t|d
f }|ddd}| 	t|t t d | t
d
t | f }|ddd}| 	t|t t d | d S )NCCr   c                 S   s   d S r?   r;   r   r;   r;   r<   foobar2  r   z5GenericTests.test_generic_forward_ref.<locals>.foobarc                 S   s   d S r?   r;   r   r;   r;   r<   foobar23  r   z6GenericTests.test_generic_forward_ref.<locals>.foobar2c                   @   s   e Zd ZdS )z1GenericTests.test_generic_forward_ref.<locals>.CCNrI   r;   r;   r;   r<   r  4  r   r   r   .c                 S   s   d S r?   r;   r   r;   r;   r<   barfoo@  r   z5GenericTests.test_generic_forward_ref.<locals>.barfooc                 S   s   d S r?   r;   r   r;   r;   r<   barfoo2C  r   z6GenericTests.test_generic_forward_ref.<locals>.barfoo2)r   r   r/   rV   r   r   r   r
   r   rw   r   )	r7   r  r   r  r   ATr!  ZCTr"  r;   r;   r<   test_generic_forward_ref1  s$    z%GenericTests.test_generic_forward_refc                 C   s  G dd dt ttf }G dd dt tdf }G dd dttgtf }G dd	 d	tdtf }| |jttf | |ttf jttf | |ttf j	| | |jtf | t
|t d
d d | |jd | | tjj | |tjj | |tjj | | t | |t | t$ tt tdf tj W d    n1 sb0    Y  | t$ tt tdf tj W d    n1 s0    Y  d S )Nc                   @   s   e Zd ZdS )z@GenericTests.test_extended_generic_rules_subclassing.<locals>.T1NrI   r;   r;   r;   r<   T1G  r   r%  c                   @   s   e Zd ZdS )z@GenericTests.test_extended_generic_rules_subclassing.<locals>.T2NrI   r;   r;   r;   r<   T2H  r   r&  .c                   @   s   e Zd ZdS )z@GenericTests.test_extended_generic_rules_subclassing.<locals>.C1NrI   r;   r;   r;   r<   rJ  I  r   rJ  c                   @   s   e Zd Zdd ZdS )z@GenericTests.test_extended_generic_rules_subclassing.<locals>.C2c                 S   s   d S r?   r;   rS   r;   r;   r<   r)  K  s    zIGenericTests.test_extended_generic_rules_subclassing.<locals>.C2.__call__NrE   rF   rG   r)  r;   r;   r;   r<   rK  J  s   rK  .zC1[int]r;   )r   r   r   r   rY   rV   rv   r{   ru   rx   rW   splitrk   r  r>  r=   r   rP   rQ   r5   r@   Sequencer   )r7   r%  r&  rJ  rK  r;   r;   r<   'test_extended_generic_rules_subclassingF  s&    4z4GenericTests.test_extended_generic_rules_subclassingc                 C   s   |  t tt  W d    n1 s(0    Y  |  t tt  W d    n1 sZ0    Y  |  t tt  W d    n1 s0    Y  |  t ttt   W d    n1 s0    Y  d S r?   )rP   rQ   r   r   r   r   r   rY   rS   r;   r;   r<   test_fail_with_bare_unione  s    &&&z&GenericTests.test_fail_with_bare_unionc                 C   s   t d}| t tt  W d    n1 s00    Y  | t tt|   W d    n1 sf0    Y  | t ttj  W d    n1 s0    Y  d S rj   )r
   rP   rQ   r   r   r   r@   r   rl   r;   r;   r<   test_fail_with_bare_generico  s    &*z(GenericTests.test_fail_with_bare_genericc                 C   sz  t d}|   G dd dt||f }| |t  j| | |t  j|t  G dd dtd|f }| ||  j| | ||  j||  G dd dt	j
||f }| |t  j| | |t  j|t  G d	d
 d
t	jt|f }| |t  j| | |t  j|t  tjdkrvG dd dt	jt|f }| |t  j| | |t  j|t  d S )Nr   c                   @   s   e Zd ZdS )z5GenericTests.test_type_erasure_special.<locals>.MyTupNrI   r;   r;   r;   r<   MyTup|  r   r/  c                   @   s   e Zd Zdd ZdS )z6GenericTests.test_type_erasure_special.<locals>.MyCallc                 S   s   d S r?   r;   rS   r;   r;   r<   r)    r   z?GenericTests.test_type_erasure_special.<locals>.MyCall.__call__Nr'  r;   r;   r;   r<   MyCall  s   r0  .c                   @   s   e Zd ZdS )z6GenericTests.test_type_erasure_special.<locals>.MyDictNrI   r;   r;   r;   r<   MyDict  r   r1  c                   @   s   e Zd ZdS )z5GenericTests.test_type_erasure_special.<locals>.MyDefNrI   r;   r;   r;   r<   MyDef  r   r2  r   r   c                   @   s   e Zd ZdS )z7GenericTests.test_type_erasure_special.<locals>.MyChainNrI   r;   r;   r;   r<   MyChain  r   r4  )r
   rD   r   rw   rY   r  rV   r  r   r@   r   DefaultDictr{   r  r  ChainMap)r7   r   r/  r0  r1  r2  r4  r;   r;   r<   test_type_erasure_specialx  s$    z&GenericTests.test_type_erasure_specialc                 C   s   dd t jD }|D ]}| t|d | || t|dd rbt|jdkrb| |t j	tf t
|tr|jD ] }| t|d | || qrqd S )Nc                 s   s   | ]}t t|V  qd S r?   )getattrr@   )r  elr;   r;   r<   r    r   z4GenericTests.test_all_repr_eq_any.<locals>.<genexpr>r  rv   r   )r@   __all__rt   rW   rV   r8  r   rv   r   ru   rR   r^   r  )r7   Zobjsr  baser;   r;   r<   test_all_repr_eq_any  s    

z!GenericTests.test_all_repr_eq_anyc           
      C   s  t d}G dd dt| }G dd d|t at }d|_d|_ttjd D ]J}t	||}t
|}| |jd | |jd | |jddd	 qPttttttttf tt ttd
f ttgtf tjtjt g}|D ]:}ttjd D ]&}t	||}t
|}| || qqttjtjtt tjtj tjtttf  g}	|	D ]>}ttjd D ](}t	||}t
|}| || q`qNd S )Nr   c                   @   s   e Zd ZdS )z#GenericTests.test_pickle.<locals>.BNrI   r;   r;   r;   r<   r@    s   r@  c                   @   s   e Zd ZdS )r   NrI   r;   r;   r;   r<   r     s   r   rO   r>  r   r   .)r
   r   rY   r   r   r   r  r  r  r  r  rV   r  r   r   r   r   r   r{   r   r|   r@   r5  r  r   r$   r   AbstractSet)
r7   r   r@  r   r  r   r   samplesr  Zmore_samplesr;   r;   r<   test_pickle  s:    

&

zGenericTests.test_picklec                 C   s   t d}G dd dt| }t|tf t|tf td|f ttgtf tttf || |t |t tj| tjt tjt tj	tt
f tj	|tf tt tt|  td tdtf td tjdtf g}|tg D ]$}| |t| | |t| qd S )Nr   c                   @   s   e Zd ZdS )z1GenericTests.test_copy_and_deepcopy.<locals>.NodeNrI   r;   r;   r;   r<   r    r   r  .)r   r   )r
   r   r   rY   r   r   r   r@   r   r   r{   r   r   r   rV   r   r   )r7   r   r  thingsr   r;   r;   r<   test_copy_and_deepcopy  s    *$"z#GenericTests.test_copy_and_deepcopyc                 C   s   t dat dtdat dttatttttj	t
tjttttfD ]<}| t|| | t|| | tt|| q>t d}t dtd}t dtt}|||fD ]$}| t|| | t|| qd S )Nr   TPBr   TPVTLTLBTLV)r
   r   rY   rB  r|   r{   rC  r   r@   r   r   r   r   r   r   r   rw   r   r   r  r  r  )r7   rp   rD  rE  rF  r;   r;   r<   $test_immutability_by_copy_and_pickle  s    z1GenericTests.test_immutability_by_copy_and_picklec                    s&  t d G  fdddt  }|d}| t|jd | t|jd | t|| | t|| d|_| t|jd | t|jd |t d}| t|jd | t|jd | t|| | t|| d|_| t|jd | t|jd | |j|t  d S )Nr   c                       s   e Zd Z ddddZdS )z3GenericTests.test_copy_generic_instances.<locals>.CN)r  r   c                 S   s
   || _ d S r?   r]  r^  r;   r;   r<   r    s    z<GenericTests.test_copy_generic_instances.<locals>.C.__init__rY  r;   r  r;   r<   r     s   r   rO   r   )	r
   r   rV   r   r  r   assertIsNotrY   r  )r7   r   r   Zcir;   r  r<   test_copy_generic_instances  s&    z(GenericTests.test_copy_generic_instancesc              	   C   sv   t d}tt|tf td|f tttf ttt  tj	tt
f tjjt tjd g}|D ]}| t| | qXd S )Nr   .whatever)r
   r   r   rY   r   r   r   r   r@   r   r{   rer-   r|   r   rV   weakrefref)r7   r   r@  r   r;   r;   r<   test_weakref_all  s     zGenericTests.test_weakref_allc                 C   s   t d}G dd dt| }| }|t  }d|_d|_| t d|_W d    n1 s^0    Y  | t d|_W d    n1 s0    Y  |d ddd}| t|t	 t
 d ||  | t|t t|t  d S )	Nr   c                   @   s   e Zd ZdZdS )z0GenericTests.test_parameterized_slots.<locals>.C)potatoNrE   rF   rG   	__slots__r;   r;   r;   r<   r      s   r   r   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r     r   z2GenericTests.test_parameterized_slots.<locals>.foor   )r
   r   rY   rO  rP   r  ZtomatorV   r   r   r   r   r   )r7   r   r   r   Zc_intr   r;   r;   r<   test_parameterized_slots  s    
$$ z%GenericTests.test_parameterized_slotsc                 C   s   t d}G dd dt| }| }|t  }d|_d|_| t d|_W d    n1 s^0    Y  | t d|_W d    n1 s0    Y  d S )Nr   c                   @   s   e Zd ZddiZdS )z5GenericTests.test_parameterized_slots_dict.<locals>.DbananarO   NrP  r;   r;   r;   r<   r-    s   r-  Zyesno)r
   r   rY   rS  rP   r  r  )r7   r   r-  dZd_intr;   r;   r<   test_parameterized_slots_dict  s    
$z*GenericTests.test_parameterized_slots_dictc                 C   sN   |  t0 tttf }G dd dt| }W d    n1 s@0    Y  d S )Nc                   @   s   e Zd ZdS )z#GenericTests.test_errors.<locals>.CNrI   r;   r;   r;   r<   r   $  s   r   )rP   rQ   r  r  r   r   )r7   r@  r   r;   r;   r<   rZ      s    zGenericTests.test_errorsc                 C   s   G dd dt t }| |jt | |jd |t }| |jt | t|dd d G dd d|t }| |jt | |jd	 d S )
Nc                   @   s   e Zd ZdS )#GenericTests.test_repr_2.<locals>.CNrI   r;   r;   r;   r<   r   (  s   r   rW  r(  r)  zC[int]c                   @   s   e Zd ZdS )#GenericTests.test_repr_2.<locals>.YNrI   r;   r;   r;   r<   rs   2  s   rs   rX  )	r   r   rV   rF   rE   rG   rY   rW   r*  )r7   r   rp   rs   r;   r;   r<   test_repr_2'  s    zGenericTests.test_repr_2c                 C   s8   |  tt |  tt tt  | tt tt  d S r?   )rV   r   r   rt   r   r   rS   r;   r;   r<   	test_eq_19  s    zGenericTests.test_eq_1c                 C   sl   G dd dt t }G dd dt t }| || | || | |t |t  | |t |t  d S )Nc                   @   s   e Zd ZdS )z!GenericTests.test_eq_2.<locals>.ANrI   r;   r;   r;   r<   r\   @  s   r\   c                   @   s   e Zd ZdS )z!GenericTests.test_eq_2.<locals>.BNrI   r;   r;   r;   r<   r@  C  s   r@  )r   r   rV   rt   r  r;   r;   r<   	test_eq_2>  s    zGenericTests.test_eq_2c                 C   sv   G dd dt ttf }G dd dt ttf }G dd d|ttf t tttf |ttf }| |jtttf d S )Nc                   @   s   e Zd ZdS )z1GenericTests.test_multiple_inheritance.<locals>.ANrI   r;   r;   r;   r<   r\   M  s   r\   c                   @   s   e Zd ZdS )z1GenericTests.test_multiple_inheritance.<locals>.BNrI   r;   r;   r;   r<   r@  P  s   r@  c                   @   s   e Zd ZdS )z1GenericTests.test_multiple_inheritance.<locals>.CNrI   r;   r;   r;   r<   r   S  s   r   )r   r   r   r   rV   rv   )r7   r\   r@  r   r;   r;   r<   test_multiple_inheritanceK  s    .z&GenericTests.test_multiple_inheritancec                 C   sN   t d}G dd dt| }G dd dtt |}| |j|t|ttf d S )Nr  c                   @   s   e Zd ZdS )z9GenericTests.test_multiple_inheritance_special.<locals>.BNrI   r;   r;   r;   r<   r@  Z  r   r@  c                   @   s   e Zd ZdS )z9GenericTests.test_multiple_inheritance_special.<locals>.CNrI   r;   r;   r;   r<   r   [  r   r   )r
   r   r   rY   rV   r  r   r   )r7   r  r@  r   r;   r;   r<   !test_multiple_inheritance_specialX  s    z.GenericTests.test_multiple_inheritance_specialc                    s   G dd dt G  fddd G dd dtt  }|   G dd d|}W d    n1 sj0    Y  | $ G d	d d|t }W d    n1 s0    Y  d S )
Nc                   @   s   e Zd ZdS )zDGenericTests.test_init_subclass_super_called.<locals>.FinalExceptionNrI   r;   r;   r;   r<   FinalException_  s   r^  c                       s&   e Zd Zdd fddZ  ZS )z;GenericTests.test_init_subclass_super_called.<locals>.FinalNr   c                    s<   | j D ]}| urt| r|qt jf i | d S r?   )r  r5   r  r  )r8   r  r;  )r   r^  r  r;   r<   r  c  s    

zMGenericTests.test_init_subclass_super_called.<locals>.Final.__init_subclass__r  r;   r   r^  r  r<   r   b  s   r   c                   @   s   e Zd ZdS )z:GenericTests.test_init_subclass_super_called.<locals>.TestNrI   r;   r;   r;   r<   r  h  s   r  c                   @   s   e Zd ZdS z>GenericTests.test_init_subclass_super_called.<locals>.SubclassNrI   r;   r;   r;   r<   Subclassk  s   ra  c                   @   s   e Zd ZdS r`  rI   r;   r;   r;   r<   ra  n  s   )	Exceptionr   r   rP   rY   )r7   r  ra  r;   r_  r<   test_init_subclass_super_called^  s    .z,GenericTests.test_init_subclass_super_calledc                 C   sr   t }G dd d|t }|tjt  }G dd d|}| }|g  |d |d | | ddg d S )Nc                   @   s4   e Zd ZdZedddZdd Zeddd	ZdS )
z)GenericTests.test_nested.<locals>.VisitorNr   c                 S   s
   || _ d S r?   r   r7   r   r;   r;   r<   sety  s    z-GenericTests.test_nested.<locals>.Visitor.setc                 S   s   | j S r?   r   rS   r;   r;   r<   r  |  s    z-GenericTests.test_nested.<locals>.Visitor.getr   c                 S   s   | j S r?   r   rS   r;   r;   r<   visit  s    z/GenericTests.test_nested.<locals>.Visitor.visit)rE   rF   rG   r   r   re  r  rf  r;   r;   r;   r<   Visitoru  s   rg  c                   @   s   e Zd ZedddZdS )z0GenericTests.test_nested.<locals>.IntListVisitorr   c                 S   s   | j | d S r?   )r   appendrb  r;   r;   r<   rh    s    z7GenericTests.test_nested.<locals>.IntListVisitor.appendN)rE   rF   rG   rY   rh  r;   r;   r;   r<   IntListVisitor  s   ri  r   rO   )	r   r   r@   r   rY   re  rh  rV   r  )r7   Grg  r   ri  r   r;   r;   r<   test_nestedq  s    


zGenericTests.test_nestedc                    sB   t dG fdddt  d fdd}|d d S )Nr   c                       s    e Zd Zd dddddZdS )z,GenericTests.test_type_erasure.<locals>.NodeNNode[T]r  leftrightc                 S   s   || _ || _|| _d S r?   rm  )r7   r  rn  ro  r;   r;   r<   r    s    z5GenericTests.test_type_erasure.<locals>.Node.__init__)NNrY  r;   r  r;   r<   r    s     r  r   c                    s~    | }  | } t  | }t|  t|  t|  |j|  |j|  |j|  d S r?   )r   rw   r^   rV   r  )r   r   r  r   r  r   r7   r;   r<   r     s    z+GenericTests.test_type_erasure.<locals>.foorO   )r
   r   r   r;   rp  r<   test_type_erasure  s    zGenericTests.test_type_erasurec                 C   s   t d}G dd dt| }G dd d|}| |jd | t |t  W d    n1 sb0    Y  | t |t  W d    n1 s0    Y  | t ||  W d    n1 s0    Y  d S )Nr   c                   @   s   e Zd ZdS )z)GenericTests.test_implicit_any.<locals>.CNrI   r;   r;   r;   r<   r     s   r   c                   @   s   e Zd ZdS )z)GenericTests.test_implicit_any.<locals>.DNrI   r;   r;   r;   r<   r-    s   r-  r;   )r
   r   rV   rv   rP   rb  rY   r   r  r;   r;   r<   test_implicit_any  s    &&zGenericTests.test_implicit_anyc                 C   sN   G dd dt t }G dd d}G dd d||}|d}| |jd d S )Nc                   @   s   e Zd ZdS )z*GenericTests.test_new_with_args.<locals>.ANrI   r;   r;   r;   r<   r\     s   r\   c                       s   e Zd Z fddZ  ZS )z*GenericTests.test_new_with_args.<locals>.Bc                    s   t  | }||_|S r?   )r  r  r!  r8   r!  r  r  r;   r<   r    s    z2GenericTests.test_new_with_args.<locals>.B.__new__r  r;   r;   r  r<   r@    s   r@  c                   @   s   e Zd ZdS )z*GenericTests.test_new_with_args.<locals>.CNrI   r;   r;   r;   r<   r     s   r   r   )r   r   rV   r!  r7   r\   r@  r   r   r;   r;   r<   test_new_with_args  s
    zGenericTests.test_new_with_argsc                 C   sL   G dd d}G dd dt t |}|d}| |jd | |jd d S )Nc                       s   e Zd Z fddZ  ZS )z+GenericTests.test_new_with_args2.<locals>.Ac                    s   || _ t   d S r?   )from_ar  r  r"  r  r;   r<   r    s    z4GenericTests.test_new_with_args2.<locals>.A.__init__r  r;   r;   r  r<   r\     s   r\   c                       s   e Zd Z fddZ  ZS )z+GenericTests.test_new_with_args2.<locals>.Cc                    s   || _ t | d S r?   )from_cr  r  r"  r  r;   r<   r    s    z4GenericTests.test_new_with_args2.<locals>.C.__init__r  r;   r;   r  r<   r     s   r   r   )r   r   rV   rv  rw  )r7   r\   r   r   r;   r;   r<   test_new_with_args2  s
    z GenericTests.test_new_with_args2c                 C   s   G dd dt t }| t |d W d    n1 s<0    Y  G dd d}G dd d||}|d}| |jd | |jd | |jd	 d S )
Nc                   @   s   e Zd ZdS )z(GenericTests.test_new_no_args.<locals>.ANrI   r;   r;   r;   r<   r\     s   r\   r   c                       s   e Zd Z fddZ  ZS )z(GenericTests.test_new_no_args.<locals>.Bc                    s   t  | }d|_|S )Nr  )r  r  from_b)r8   r  r  r;   r<   r    s    z0GenericTests.test_new_no_args.<locals>.B.__new__r  r;   r;   r  r<   r@    s   r@  c                       s$   e Zd Zdd Z fddZ  ZS )z(GenericTests.test_new_no_args.<locals>.Cc                 S   s
   || _ d S r?   )r!  r"  r;   r;   r<   r    s    z1GenericTests.test_new_no_args.<locals>.C.__init__c                    s   t  | }d|_|S )Nr   )r  r  rw  rs  r  r;   r<   r    s    z0GenericTests.test_new_no_args.<locals>.C.__new__)rE   rF   rG   r  r  r  r;   r;   r  r<   r     s   r   r  r   )r   r   rP   rQ   rV   r!  ry  rw  rt  r;   r;   r<   test_new_no_args  s    &
zGenericTests.test_new_no_argsN)3rE   rF   rG   r   r  r  r  rX   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r$  r,  r-  r.  r7  r<  r?  rA  rG  rI  rN  rR  rV  rZ   rY  rZ  r[  r\  r]  rc  rk  rq  rr  ru  rx  rz  r;   r;   r;   r<   r    s`   
$+
	#r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )ClassVarTestsc                 C   s   |  t td  W d    n1 s(0    Y  |  t tttf  W d    n1 s^0    Y  |  t tt t  W d    n1 s0    Y  d S r   )rP   rQ   r   rY   r{   rS   r;   r;   r<   r   	  s    &*zClassVarTests.test_basicsc                 C   sH   |  ttd tt }|  t|d tt }|  t|dt  d S )Nztyping.ClassVartyping.ClassVar[int]ztyping.ClassVar[%s.Employee])rV   rW   r   rY   rH   rE   r7   Zcvr;   r;   r<   rX   		  s
    zClassVarTests.test_reprc                 C   s   |  t$ G dd dtt}W d    n1 s40    Y  |  t( G dd dttt }W d    n1 sv0    Y  d S )Nc                   @   s   e Zd ZdS z-ClassVarTests.test_cannot_subclass.<locals>.CNrI   r;   r;   r;   r<   r   	  s   r   c                   @   s   e Zd ZdS r~  rI   r;   r;   r;   r<   r   	  s   )rP   rQ   r^   r   rY   r   r;   r;   r<   r`   	  s    2z"ClassVarTests.test_cannot_subclassc                 C   s   |  t t  W d    n1 s&0    Y  |  t tt  W d    n1 sZ0    Y  |  t" tttt    W d    n1 s0    Y  d S r?   )rP   rQ   r   r^   r   rY   rS   r;   r;   r<   r   	  s    $(zClassVarTests.test_cannot_initc                 C   sp   |  t tdtt  W d    n1 s.0    Y  |  t ttt W d    n1 sb0    Y  d S r   )rP   rQ   rR   r   rY   r5   rS   r;   r;   r<   test_no_isinstance 	  s    ,z ClassVarTests.test_no_isinstanceN)rE   rF   rG   r   rX   r`   r   r  r;   r;   r;   r<   r{    s
   r{  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )
FinalTestsc                 C   s   t t  | t t d  W d    n1 s00    Y  | t t ttf  W d    n1 sf0    Y  | t t t t  W d    n1 s0    Y  | t tt t   W d    n1 s0    Y  d S r   )r   rY   rP   rQ   r{   r   rS   r;   r;   r<   r   )	  s    &**zFinalTests.test_basicsc                 C   sd   |  ttd tt }|  t|d tt }|  t|dt  ttt  }|  t|d d S )Nztyping.Finalztyping.Final[int]ztyping.Final[%s.Employee]ztyping.Final[tuple[int]])rV   rW   r   rY   rH   rE   r   r}  r;   r;   r<   rX   4	  s    zFinalTests.test_reprc                 C   s   |  t$ G dd dtt}W d    n1 s40    Y  |  t( G dd dttt }W d    n1 sv0    Y  d S )Nc                   @   s   e Zd ZdS z*FinalTests.test_cannot_subclass.<locals>.CNrI   r;   r;   r;   r<   r   ?	  s   r   c                   @   s   e Zd ZdS r  rI   r;   r;   r;   r<   r   B	  s   )rP   rQ   r^   r   rY   r   r;   r;   r<   r`   =	  s    2zFinalTests.test_cannot_subclassc                 C   s   |  t t  W d    n1 s&0    Y  |  t tt  W d    n1 sZ0    Y  |  t" tttt    W d    n1 s0    Y  d S r?   )rP   rQ   r   r^   r   rY   rS   r;   r;   r<   r   E	  s    $(zFinalTests.test_cannot_initc                 C   sp   |  t tdtt  W d    n1 s.0    Y  |  t ttt W d    n1 sb0    Y  d S r   )rP   rQ   rR   r   rY   r5   rS   r;   r;   r<   r  M	  s    ,zFinalTests.test_no_isinstancec                 C   s   dd }|  |t| d S )Nc                 S   s   d S r?   r;   r   r;   r;   r<   funcT	  r   z.FinalTests.test_final_unmodified.<locals>.func)rw   r   )r7   r  r;   r;   r<   test_final_unmodifiedS	  s    z FinalTests.test_final_unmodifiedN)	rE   rF   rG   r   rX   r`   r   r  r  r;   r;   r;   r<   r  '	  s   	r  c                   @   s   e Zd Zdd Zdd ZdS )	CastTestsc                 C   s   |  ttdd |  ttdd | tttdt |  ttdd |  ttdd |  ttt	tf dd |  tt
dd |  td dd d S rN   )rV   r   rY   r   rw   r^   r   r   r   r{   r   rS   r;   r;   r<   r   Z	  s    zCastTests.test_basicsc                 C   s   t dd t dd d S )NrO   Zhello)r   rS   r;   r;   r<   rZ   d	  s    
zCastTests.test_errorsN)rE   rF   rG   r   rZ   r;   r;   r;   r<   r  X	  s   
r  c                   @   s   e Z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)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;S )<ForwardRefTestsc                 C   s   G dd dt t }|t }t|jt t }| |d t|t   | |d t|t   | |d |d  | |d tt  | 	d| t|j
t t }| |d t|t   t|jt t }| |d t|t   d S )Nc                   @   sP   e Zd ZedddZdddeddd	Zed d
ddZddd
ddZ	dS )z)ForwardRefTests.test_basics.<locals>.Node)r  c                 S   s   || _ d  | _| _d S r?   rm  )r7   r  r;   r;   r<   r  p	  s    z2ForwardRefTests.test_basics.<locals>.Node.__init__NzOptional[Node[T]]rl  )rn  ro  stuffc                 S   s   || _ || _d S r?   )rn  ro  )r7   rn  ro  r  blahr;   r;   r<   add_botht	  s    z2ForwardRefTests.test_basics.<locals>.Node.add_both)nodec                 S   s   |  |d  d S r?   r  r7   r  r;   r;   r<   add_left|	  s    z2ForwardRefTests.test_basics.<locals>.Node.add_leftc                 S   s   |  d | d S r?   r  r  r;   r;   r<   	add_right	  s    z3ForwardRefTests.test_basics.<locals>.Node.add_right)NNN)N)
rE   rF   rG   r   r  rY   r  r   r  r  r;   r;   r;   r<   r  n	  s      r  rn  ro  r  r  r  )r   r   rY   r   r  r   r   rV   r   assertNotInr  r  )r7   r  r   Z
both_hintsZ
left_hintsZright_hintsr;   r;   r<   r   l	  s    zForwardRefTests.test_basicsc                 C   sB   t d}| t td| W d    n1 s40    Y  d S )NrY   rO   )r@   r/   rP   rQ   rR   r7   frr;   r;   r<   #test_forwardref_instance_type_error	  s    
z3ForwardRefTests.test_forwardref_instance_type_errorc                 C   sB   t d}| t tt| W d    n1 s40    Y  d S )NrY   )r@   r/   rP   rQ   r5   rY   r  r;   r;   r<   #test_forwardref_subclass_type_error	  s    
z3ForwardRefTests.test_forwardref_subclass_type_errorc                 C   s8   |  t td W d    n1 s*0    Y  d S r   )rP   rQ   r@   r/   rS   r;   r;   r<   test_forwardref_only_str_arg	  s    z,ForwardRefTests.test_forwardref_only_str_argc                 C   s   t d}| |t d | td tt  | |t jdtd t jdtd}| |t jdtd | |t jddd d S )NrY   module__other_name__)r@   r/   rV   rt   r   rY   rE   )r7   r  Zfrmr;   r;   r<   test_forward_equality	  s    
z%ForwardRefTests.test_forward_equalityc                 C   s   t d}t d}t d}t d}G dd d}||ddd}| t|t t ||d | || | || | || | t| t|  | t| t|  | t| t|  | t||f t|  | t||t	f t|t	f  d S )Nr   c                   @   s   e Zd ZdS )z4ForwardRefTests.test_forward_equality_gth.<locals>.CNrI   r;   r;   r;   r<   r   	  s   r   r  c                 S   s   d S r?   r;   r  r;   r;   r<   r   	  s    z6ForwardRefTests.test_forward_equality_gth.<locals>.foo)
r@   r/   rV   r   r   r   r   rt   r   rY   )r7   c1c1_gthc2c2_gthr   r   r;   r;   r<   test_forward_equality_gth	  s    



z)ForwardRefTests.test_forward_equality_gthc                 C   s   t d}t d}t d}t d}||ddd}t|t t  | t|t| | t|t| | t|t| t jdtd}t jddd}| t|t| | t|t| | t|t| | t|tt jdtd d S )NrY   r  c                 S   s   d S r?   r;   r  r;   r;   r<   r   	  s    z7ForwardRefTests.test_forward_equality_hash.<locals>.foor  r  )	r@   r/   r   r   r   rV   r   rE   rt   )r7   r  r  r  r  r   Zc3Zc4r;   r;   r<   test_forward_equality_hash	  s    



z*ForwardRefTests.test_forward_equality_hashc                 C   sB   G dd d}dd }dd }|  | |  | | |  d S )Nc                   @   s   e Zd ZdS )z:ForwardRefTests.test_forward_equality_namespace.<locals>.ANrI   r;   r;   r;   r<   r\   	  s   r\   c                  S   s,   t d} | ddd}t|t t  | S )Nr\   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   	  s    zPForwardRefTests.test_forward_equality_namespace.<locals>.namespace1.<locals>.funr@   r/   r   r   r   )r   r   r;   r;   r<   
namespace1	  s    
zCForwardRefTests.test_forward_equality_namespace.<locals>.namespace1c                  S   s:   t d} G dd d}| ddd}t|t t  | S )Nr\   c                   @   s   e Zd ZdS )zNForwardRefTests.test_forward_equality_namespace.<locals>.namespace2.<locals>.ANrI   r;   r;   r;   r<   r\   	  s   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   	  s    zPForwardRefTests.test_forward_equality_namespace.<locals>.namespace2.<locals>.funr  )r   r\   r   r;   r;   r<   
namespace2	  s
    
zCForwardRefTests.test_forward_equality_namespace.<locals>.namespace2)rV   rt   )r7   r\   r  r  r;   r;   r<   test_forward_equality_namespace	  s
    z/ForwardRefTests.test_forward_equality_namespacec                 C   s   |  ttd d d S )NrY   ztyping.List[ForwardRef('int')])rV   rW   r   rS   r;   r;   r<   test_forward_repr	  s    z!ForwardRefTests.test_forward_reprc                 C   s6   t d ddd}| t|t t dt t i d S )Nr   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   	  s    z/ForwardRefTests.test_union_forward.<locals>.foor   )r   rV   r   r   r   r   r   r;   r;   r<   test_union_forward	  s    
z"ForwardRefTests.test_union_forwardc                 C   sl   t d ddd}| t|t t dt t i ttd ddd}| t|t t dtt i d S )Nr   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   	  s    z/ForwardRefTests.test_tuple_forward.<locals>.foor   c                 S   s   d S r?   r;   r   r;   r;   r<   r   	  s    )r   rV   r   r   r   r   r   r/   r   r;   r;   r<   test_tuple_forward	  s    

z"ForwardRefTests.test_tuple_forwardc                 C   s2   dddd}|  t|t t dtt i d S )NzList['int']r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   
  s    z0ForwardRefTests.test_double_forward.<locals>.foor   )rV   r   r   r   r   rY   r   r;   r;   r<   test_double_forward
  s    
z#ForwardRefTests.test_double_forwardc                 C   sD   dd }dd }dd }| }| }|  || | t||| d S )Nc                  S   s0   t d} | }| ddd}t|t t }| S )Nr\   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   
  r   zPForwardRefTests.test_forward_recursion_actually.<locals>.namespace1.<locals>.funr  r   r\   r   retr;   r;   r<   r  

  s
    
zCForwardRefTests.test_forward_recursion_actually.<locals>.namespace1c                  S   s0   t d} | }| ddd}t|t t }| S )Nr\   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   
  r   zPForwardRefTests.test_forward_recursion_actually.<locals>.namespace2.<locals>.funr  r  r;   r;   r<   r  
  s
    
zCForwardRefTests.test_forward_recursion_actually.<locals>.namespace2c                 S   s   | |kS r?   r;   )Zo1Zo2r;   r;   r<   cmp
  s    z<ForwardRefTests.test_forward_recursion_actually.<locals>.cmp)rH  rP   RecursionError)r7   r  r  r  Zr1Zr2r;   r;   r<   test_forward_recursion_actually	
  s    z/ForwardRefTests.test_forward_recursion_actuallyc                    s  t d ttf  G  fddd}G  fddd}G  fddd}G  fdd	d	}| t|t t t|t t  | t|t t d
t ttt ttt d f  f  i | t|t t d
ttt ttt d f  f i | t|t t d
tt ttt ttt d f  f  t ttt d f  f i | t|t t d
ttt ttt d f  t ttt ttt d f  f  f i d S )NValuec                       s   e Zd ZU e  ed< dS )z7ForwardRefTests.test_union_forward_recursion.<locals>.Cr   N)rE   rF   rG   r   r  r;   )r  r;   r<   r   &
  s   
r   c                       s   e Zd ZU e f ed< dS )z7ForwardRefTests.test_union_forward_recursion.<locals>.Dr   N)rE   rF   rG   r   r  r;   r  Z	ValueListr;   r<   r-  (
  s   
r-  c                       s"   e Zd ZU ee  f ed< dS )z7ForwardRefTests.test_union_forward_recursion.<locals>.Er   NrE   rF   rG   r   r   r  r;   r  r;   r<   r7  *
  s   
r7  c                       s$   e Zd ZU e e  f ed< dS )z7ForwardRefTests.test_union_forward_recursion.<locals>.Fr   Nr  r;   r  r;   r<   F,
  s   
r  r   )r   r   r{   rV   r   r   r   )r7   r   r-  r7  r  r;   r  r<   test_union_forward_recursion"
  s8    $"z,ForwardRefTests.test_union_forward_recursionc                 C   sB   t dgdf ddd}| t|t t dt tgtf i d S )Nr   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   D
  s    z2ForwardRefTests.test_callable_forward.<locals>.foor   )r   rV   r   r   r   r   r   r;   r;   r<   test_callable_forwardB
  s    z%ForwardRefTests.test_callable_forwardc                 C   s6   dddd}|  t|t t dtdtf i d S )NzCallable[..., T]r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   L
  s    z@ForwardRefTests.test_callable_with_ellipsis_forward.<locals>.foor   .)rV   r   r   r   r   r   r   r;   r;   r<   #test_callable_with_ellipsis_forwardJ
  s    z3ForwardRefTests.test_callable_with_ellipsis_forwardc                 C   s   G dd d}G dd d}|  t|t d tt  |  t|t d tt  | t t|t f W d    n1 s0    Y  d S )Nc                   @   s.   e Zd ZU dZed ed< dZed ed< dS )z5ForwardRefTests.test_special_forms_forward.<locals>.Cr   )ClassVar[int])r   r   r   )
Final[int]constr  N)rE   rF   rG   r   r.   r  r  r;   r;   r;   r<   r   T
  s   
r   c                   @   s   e Zd ZU dZed ed< dS )z6ForwardRefTests.test_special_forms_forward.<locals>.CFr   r  r  N)rE   rF   rG   r  r   r  r;   r;   r;   r<   CFX
  s   
r  r   r  )rV   r   r   r   rY   r   rP   rQ   )r7   r   r  r;   r;   r<   test_special_forms_forwardR
  s    z*ForwardRefTests.test_special_forms_forwardc                 C   s6   |  t td  W d    n1 s(0    Y  d S )Nz/T)rP   SyntaxErrorr   rS   r;   r;   r<   test_syntax_error`
  s    z!ForwardRefTests.test_syntax_errorc                 C   sD   dddd}|  t t| W d    n1 s60    Y  d S )NzNode[Tr   c                 S   s   d S r?   r;   r   r;   r;   r<   r   g
  s    z6ForwardRefTests.test_delayed_syntax_error.<locals>.foo)rP   r  r   r   r;   r;   r<   test_delayed_syntax_errore
  s    z)ForwardRefTests.test_delayed_syntax_errorc                 C   sH   t d ddd}| t t| W d    n1 s:0    Y  d S )NZ42r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   o
  s    z,ForwardRefTests.test_type_error.<locals>.foo)r   rP   rQ   r   r   r;   r;   r<   test_type_errorm
  s    zForwardRefTests.test_type_errorc                 C   sH   dddd}|  t t|t  W d    n1 s:0    Y  d S )NzNoode[T]r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   w
  s    z,ForwardRefTests.test_name_error.<locals>.foo)rP   	NameErrorr   r   r   r;   r;   r<   test_name_erroru
  s    zForwardRefTests.test_name_errorc                 C   s,   t di ddd}t|}| |i  d S )N	whateversr   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r   
  s    z/ForwardRefTests.test_no_type_check.<locals>.foo)r!   r   rV   )r7   r   thr;   r;   r<   test_no_type_check}
  s    z"ForwardRefTests.test_no_type_checkc                 C   sD   t G dd d}t|j}| |i  t| j}| |i  d S )Nc                   @   s   e Zd Zdi dddZdS )z3ForwardRefTests.test_no_type_check_class.<locals>.Cr  r  c                 S   s   d S r?   r;   r   r;   r;   r<   r   
  s    z7ForwardRefTests.test_no_type_check_class.<locals>.C.fooNrE   rF   rG   r   r;   r;   r;   r<   r   
  s   r   )r!   r   r   rV   )r7   r   cthithr;   r;   r<   test_no_type_check_class
  s    
z(ForwardRefTests.test_no_type_check_classc                    s@   G dd d t G  fddd }| t jdti d S )Nc                   @   s   e Zd ZedddZdS )z6ForwardRefTests.test_no_type_check_no_bases.<locals>.Cr   c                 S   s   d S r?   r;   rb  r;   r;   r<   r#  
  r   z;ForwardRefTests.test_no_type_check_no_bases.<locals>.C.methNrE   rF   rG   rY   r#  r;   r;   r;   r<   r   
  s   r   c                       s   e Zd Z ZdS )z6ForwardRefTests.test_no_type_check_no_bases.<locals>.DN)rE   rF   rG   r   r;   r   r;   r<   r-  
  s   r-  r   )r!   rV   r   r#  rY   r7   r-  r;   r  r<   test_no_type_check_no_bases
  s    z+ForwardRefTests.test_no_type_check_no_basesc                 C   sl   G dd d}G dd d}G dd d}G dd d}d	t jt i}||||fD ]}| t|| qRd S )
Nc                   @   s    e Zd ZU dZeje ed< dS )zCForwardRefTests.test_no_type_check_forward_ref_as_string.<locals>.C   r   N)rE   rF   rG   r   r@   r   rY   r  r;   r;   r;   r<   r   
  s   
r   c                   @   s   e Zd ZU dZee ed< dS )zCForwardRefTests.test_no_type_check_forward_ref_as_string.<locals>.Dr  r   N)rE   rF   rG   r   r   rY   r  r;   r;   r;   r<   r-  
  s   
r-  c                   @   s   e Zd ZU dZded< dS )zCForwardRefTests.test_no_type_check_forward_ref_as_string.<locals>.Er  r|  r   NrE   rF   rG   r   r  r;   r;   r;   r<   r7  
  s   
r7  c                   @   s   e Zd ZU dZded< dS )zCForwardRefTests.test_no_type_check_forward_ref_as_string.<locals>.Fr  r  r   Nr  r;   r;   r;   r<   r  
  s   
r  r   )r@   r   rY   rV   r   )r7   r   r-  r7  r  Zexpected_resultclazzr;   r;   r<   (test_no_type_check_forward_ref_as_string
  s    z8ForwardRefTests.test_no_type_check_forward_ref_as_stringc              	   C   s`   G dd d}G dd d}||fD ]6}|  t t| W d    q$1 sP0    Y  q$d S )Nc                   @   s   e Zd ZU dZded< dS )zGForwardRefTests.test_nested_classvar_fails_forward_ref_check.<locals>.Er  z%typing.ClassVar[typing.ClassVar[int]]r   Nr  r;   r;   r;   r<   r7  
  s   
r7  c                   @   s   e Zd ZU dZed ed< dS )zGForwardRefTests.test_nested_classvar_fails_forward_ref_check.<locals>.Fr  r  r   N)rE   rF   rG   r   r   r  r;   r;   r;   r<   r  
  s   
r  )rP   rQ   r   )r7   r7  r  r  r;   r;   r<   ,test_nested_classvar_fails_forward_ref_check
  s
    z<ForwardRefTests.test_nested_classvar_fails_forward_ref_checkc                 C   s   t dd }| |jd |di ddd}|G dd	 d	}| |jd
 t|}| |i  t|j}| |i  t| j}| |i  d S )Nc                 S   s   | S r?   r;   )r  r;   r;   r<   magic_decorator
  s    z@ForwardRefTests.test_meta_no_type_check.<locals>.magic_decoratorr  r  r  c                 S   s   d S r?   r;   r   r;   r;   r<   r   
  s    z4ForwardRefTests.test_meta_no_type_check.<locals>.fooc                   @   s   e Zd Zdi dddZdS )z2ForwardRefTests.test_meta_no_type_check.<locals>.Cr  r  c                 S   s   d S r?   r;   r   r;   r;   r<   r   
  s    z6ForwardRefTests.test_meta_no_type_check.<locals>.C.fooNr  r;   r;   r;   r<   r   
  s   r   r   )r"   rV   rE   r   r   )r7   r  r   r   r  r  r  r;   r;   r<   test_meta_no_type_check
  s    

z'ForwardRefTests.test_meta_no_type_checkc                 C   s>   d}i }t || t|d j}| ||d |d d d S )Nz^class C:
    def foo(self, a: 'C') -> 'D': pass
class D:
    def bar(self, b: 'D') -> C: pass
r   r-  r  )r   r   r   rV   )r7   r   nshintsr;   r;   r<   test_default_globals
  s
    
z$ForwardRefTests.test_default_globalsc                 C   sT   |  ttt d tt  | ttt d tt  | ttt d t d S )Nr  )rV   gthLoopr   r   rt   rY   rS   r;   r;   r<   test_final_forward_ref
  s    z&ForwardRefTests.test_final_forward_refN) rE   rF   rG   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r;   r;   r;   r<   r  j	  s:   $	 		
r  c                   @   s   e Zd Zdd Zdd ZdS )OverloadTestsc                 C   sL   ddl m} | t" |dd }|  W d    n1 s>0    Y  d S )Nr   overloadc                   S   s   d S r?   r;   r;   r;   r;   r<   r  
  s    z/OverloadTests.test_overload_fails.<locals>.blah)r@   r  rP   RuntimeErrorr7   r  r  r;   r;   r<   test_overload_fails
  s
    
z!OverloadTests.test_overload_failsc                 C   s*   ddl m} |dd }dd }|  d S )Nr   r  c                   S   s   d S r?   r;   r;   r;   r;   r<   r  
  s    z2OverloadTests.test_overload_succeeds.<locals>.blahc                   S   s   d S r?   r;   r;   r;   r;   r<   r  
  s    )r@   r  r  r;   r;   r<   test_overload_succeeds
  s
    
z$OverloadTests.test_overload_succeedsN)rE   rF   rG   r  r  r;   r;   r;   r<   r  
  s   r  a  
import asyncio

T_a = TypeVar('T_a')

class AwaitableWrapper(typing.Awaitable[T_a]):

    def __init__(self, value):
        self.value = value

    def __await__(self) -> typing.Iterator[T_a]:
        yield
        return self.value

class AsyncIteratorWrapper(typing.AsyncIterator[T_a]):

    def __init__(self, value: typing.Iterable[T_a]):
        self.value = value

    def __aiter__(self) -> typing.AsyncIterator[T_a]:
        return self

    async def __anext__(self) -> T_a:
        data = await self.value
        if data:
            return data
        else:
            raise StopAsyncIteration

class ACM:
    async def __aenter__(self) -> int:
        return 42
    async def __aexit__(self, etype, eval, tb):
        return None
FT)
ann_moduleann_module2ann_module3ann_module5ann_module6)AsyncContextManagerc                   @   s   e Zd ZU eed< dS )r\   r   N)rE   rF   rG   r   r  r;   r;   r;   r<   r\   '  s   
r\   c                   @   s2   e Zd ZU dZeed   ed< eed< eed< dS )r@  Nr   r   r  )rE   rF   rG   r   r   r   r  rY   r;   r;   r;   r<   r@  )  s   
r@  c                   @   s    e Zd ZU e Zed  ed< dS )CSubr   N)rE   rF   rG   r@  r   r   r  r;   r;   r;   r<   r  -  s   
r  c                   @   s"   e Zd ZU g Zeee  ed< dS )rj  lstN)rE   rF   rG   r  r   r   r   r  r;   r;   r;   r<   rj  /  s   
rj  c                   @   s   e Zd ZU ed  ed< dS )r  r  N)rE   rF   rG   r   r  r;   r;   r;   r<   r  2  s   
r  c                   @   s   e Zd ZU d ed< ded< dS )NoneAndForwardparentNmeaningrE   rF   rG   r  r;   r;   r;   r<   r  5  s   
r  c                   @   s   e Zd ZU eed< eed< dS )CoolEmployeenamecoolNrE   rF   rG   r{   r  rY   r;   r;   r;   r<   r  9  s   
r  c                   @   s"   e Zd ZU eed< dZeed< dS )CoolEmployeeWithDefaultr  r   r  N)rE   rF   rG   r{   r  r  rY   r;   r;   r;   r<   r  =  s   
r  c                   @   s   e Zd ZU eed< dd ZdS )XMethr   c                 C   s
   d| j  S )Nr   r   rS   r;   r;   r<   doubleC  s    zXMeth.doubleN)rE   rF   rG   rY   r  r  r;   r;   r;   r<   r  A  s   
r  c                   @   s2   e Zd ZU eed< dZeed< dd Zdd ZdS )	XReprr   r   r   c                 C   s   | j  d| j S )Nz -> r[  rS   r;   r;   r<   __str__I  s    zXRepr.__str__c                 C   s   dS r_  r;   r7   ry  r;   r;   r<   __add__K  s    zXRepr.__add__N)rE   rF   rG   rY   r  r   r  r  r;   r;   r;   r<   r  F  s   
r  Labelr  c                   @   s   e Zd ZU eed< eed< dS )Point2Dr   r   Nr  r;   r;   r;   r<   r  P  s   
r  c                   @   s   e Zd ZU eed< dS )r   r  Nr  r;   r;   r;   r<   r   T  s   
r   totalc                   @   s   e Zd ZdS )LabelPoint2DNrI   r;   r;   r;   r<   r  W  r   r  c                   @   s   e Zd ZU eed< eed< dS )Options	log_levellog_pathNr  r;   r;   r;   r<   r  Y  s   
r  c                   @   s   e Zd ZU ded< ded< dS )HasForeignBaseClassr  
some_xreprzmod_generics_cache.Aother_aNr  r;   r;   r;   r<   r  ]  s   
r  )amc              	      s@   | 4 I d H }|W  d   I d H  S 1 I d H s20    Y  d S r?   r;   )r   r   r;   r;   r<   g_witha  s    r  c                   @   s:   e Zd Zejd dddZejejd dddZdS )ForRefExamplerS   c                 C   s   d S r?   r;   rS   r;   r;   r<   r  n  s    zForRefExample.funcc                 C   s   d S r?   r;   rS   r;   r;   r<   nestedr  s    zForRefExample.nestedN)rE   rF   rG   r  decr  r  r;   r;   r;   r<   r  m  s
   r  c                   @   s|   e Zd Zdd Zdd Zed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 )GetTypeHintTestsc                 C   s   |  t td W d    n1 s(0    Y  |  t td W d    n1 sZ0    Y  |  t td  W d    n1 s0    Y  d S )N{   r>  )rP   rQ   r  rS   r;   r;   r<   (test_get_type_hints_from_various_objectsy  s    &&z9GetTypeHintTests.test_get_type_hints_from_various_objectsc                 C   sJ   dt ttf ttd}| tt| | tti  | tti  d S )Nr   )r   rC   r   r   )r   rY   r{   rV   r  r  r  r  )r7   Zann_module_type_hintsr;   r;   r<   test_get_type_hints_modules  s    z,GetTypeHintTests.test_get_type_hints_modulesz	known bugc                 C   s*   t tj t tj d}| tt| d S )N)Z	default_aZ	default_b)r   r0   r\   r@  rV   r  )r7   Z	mgc_hintsr;   r;   r<   &test_get_type_hints_modules_forwardref  s    z7GetTypeHintTests.test_get_type_hints_modules_forwardrefc                 C   s<  |  ttjdttj i | ttjt |  ttjdt	d |  ttj
ttttj d |  ttjdti |  ttjdttj i |  ttjttd |  ttjdti |  tttt	d d |  ttttjtjd	 |  ttjttd |  ttjtjjtjjtjd
 d S )Nr   r  )Z123r   )jr  r   r   r[  r   )r  r  )r  r  Zsome_b)Zmy_inner_a1Zmy_inner_a2Z
my_outer_a)rV   r  r  r   r   rk   Zj_classr   Mr^   r-  r{   rs   rY   Zh_classr  r   r  r  r  r0   r\   r@  r  rS   r;   r;   r<   test_get_type_hints_classes  s>    

z,GetTypeHintTests.test_get_type_hints_classesc                 C   s&   G dd d}|  t|dti d S )Nc                   @   s   e Zd ZU dZeed< dS )zZGetTypeHintTests.test_get_type_hints_classes_no_implicit_optional.<locals>.WithNoneDefaultNfield)rE   rF   rG   r  rY   r  r;   r;   r;   r<   WithNoneDefault  s   
r  r  )rV   r  rY   )r7   r  r;   r;   r<   0test_get_type_hints_classes_no_implicit_optional  s    zAGetTypeHintTests.test_get_type_hints_classes_no_implicit_optionalc                 C   s   t G dd d}| |j | |jjj | ttjj	i  G dd dt
t }t G dd d|}| t|j	dti d S )Nc                   @   s   e Zd ZG dd dZdS )z>GetTypeHintTests.test_respect_no_type_check.<locals>.NoTpCheckc                   @   s   e Zd ZddddZdS )zBGetTypeHintTests.test_respect_no_type_check.<locals>.NoTpCheck.Innz
not a typer   c                 S   s   d S r?   r;   rb  r;   r;   r<   r    r   zKGetTypeHintTests.test_respect_no_type_check.<locals>.NoTpCheck.Inn.__init__NrY  r;   r;   r;   r<   Inn  s   r  N)rE   rF   rG   r  r;   r;   r;   r<   	NoTpCheck  s   r  c                   @   s   e Zd ZedddZdS )z:GetTypeHintTests.test_respect_no_type_check.<locals>.ABaser   c                 S   s   d S r?   r;   r   r;   r;   r<   r#    r   z?GetTypeHintTests.test_respect_no_type_check.<locals>.ABase.methNr  r;   r;   r;   r<   ABase  s   r  c                   @   s   e Zd ZdS )z8GetTypeHintTests.test_respect_no_type_check.<locals>.DerNrI   r;   r;   r;   r<   Der  s   r  r   )r!   r   __no_type_check__r  r  rV   r  r  ZNTCr#  r   r   rY   )r7   r  r  r  r;   r;   r<   test_respect_no_type_check  s    z+GetTypeHintTests.test_respect_no_type_checkc                 C   s|   |  tti  |  tti  |  tti  |  tti  |  ttji  |  tt ji  |  ttj	i  d S r?   )
rV   r  rY   r^   dirr   r   r  r{   joinrS   r;   r;   r<    test_get_type_hints_for_builtins  s    z1GetTypeHintTests.test_get_type_hints_for_builtinsc                 C   sP   dd }d|j d< | t|dti d ddd}| t|dtd i d S )Nc                 S   s   d S r?   r;   r[  r;   r;   r<   testf  r   z6GetTypeHintTests.test_previous_behavior.<locals>.testfrY   r   r   c                 S   s   d S r?   r;   r   r;   r;   r<   testg  r   z6GetTypeHintTests.test_previous_behavior.<locals>.testg)r  rV   r  rY   r^   )r7   r  r  r;   r;   r<   test_previous_behavior  s
    
z'GetTypeHintTests.test_previous_behaviorc                 C   sH   G dd d}G dd d}| }ddi|_ | t|t d|i d S )Nc                   @   s   e Zd ZdS )zKGetTypeHintTests.test_get_type_hints_for_object_with_annotations.<locals>.ANrI   r;   r;   r;   r<   r\     r   r\   c                   @   s   e Zd ZdS )zKGetTypeHintTests.test_get_type_hints_for_object_with_annotations.<locals>.BNrI   r;   r;   r;   r<   r@    r   r@  r   )r  rV   r  r   )r7   r\   r@  r  r;   r;   r<   /test_get_type_hints_for_object_with_annotations  s
    
z@GetTypeHintTests.test_get_type_hints_for_object_with_annotationsc              	   C   s   |  ttjtjdtjtj i |  ttt t	tt
t  t	d |  ttt tt t	t	tt
t  d |  ttdttt  i d S )Nvar)r   r   r  )r   r   r  r   r  )rV   r  r  ZCVr  r@   r   r@  r   rY   r   r  rj  r   r   rS   r;   r;   r<   test_get_type_hints_ClassVar  s    

z-GetTypeHintTests.test_get_type_hints_ClassVarc                 C   s0   dt i}| tt j| | tt j| d S )Nr7   )r  rV   r  r  r  )r7   Zexpectsr;   r;   r<   ,test_get_type_hints_wrapped_decoratored_func  s    z=GetTypeHintTests.test_get_type_hints_wrapped_decoratored_funcc                 C   sV  t d ddd}ttdf }| t|t t dt t i | t|t t dddt ttdf  i ttd dd	d}ttdf }| t|t t dtt i | t|t t dddtttdf  i t	tt
d
f df }|ddd}| t|t t d t	t
df  | t|t t ddd | ttt
d
f df }|ddd}| t|t t d tt
df  | t|t t ddd | tjdtt t
 df f tjttt
df f ddd}| t|t t tjdt t
 f tjtt
f d tjdt t
 f }|ddd}| t|t t ddd | d S )Nrp   r   c                 S   s   d S r?   r;   r   r;   r;   r<   r    r   z>GetTypeHintTests.test_get_type_hints_annotated.<locals>.foobar)r   
   r   Tinclude_extrasc                 S   s   d S r?   r;   r   r;   r;   r<   r    r   )r   r   .c                 S   s   d S r?   r;   r   r;   r;   r<   r!    r   z>GetTypeHintTests.test_get_type_hints_annotated.<locals>.barfooc                 S   s   d S r?   r;   r   r;   r;   r<   r!    r   r  Zmutabler[  c                 S   s   d S r?   r;   r[  r;   r;   r<   r"    s    z?GetTypeHintTests.test_get_type_hints_annotated.<locals>.barfoo2c                 S   s   d S r?   r;   r   r;   r;   r<   barfoo3  r   z?GetTypeHintTests.test_get_type_hints_annotated.<locals>.barfoo3)r   r.   rY   rV   r   r   r   r   r/   r   r   rw   r   r@   r   r   )r7   r  rp   ZBAr!  r"  ZBA2r#  r;   r;   r<   test_get_type_hints_annotated  s^    

$$ z.GetTypeHintTests.test_get_type_hints_annotatedc                    s   t tdf  G  fdddtt }| t|jt t |t |t d | t|jt t dd |t  |t d | t|jt t |t |t d d S )NConstc                       s0   e Zd ZdddddZ d ddddZdS )	zBGetTypeHintTests.test_get_type_hints_annotated_refs.<locals>.MySetzConst[MySet[T]]zMySet[T]ry  r   c                 S   s   d S r?   r;   r  r;   r;   r<   __ior__  s    zJGetTypeHintTests.test_get_type_hints_annotated_refs.<locals>.MySet.__ior__c                 S   s   d S r?   r;   r  r;   r;   r<   __iand__"  s    zKGetTypeHintTests.test_get_type_hints_annotated_refs.<locals>.MySet.__iand__N)rE   rF   rG   r'  r(  r;   r%  r;   r<   MySet  s   r*  r&  Tr!  )	r.   r   r   rV   r   r(  r   r   r'  )r7   r*  r;   r)  r<   "test_get_type_hints_annotated_refs  s    z3GetTypeHintTests.test_get_type_hints_annotated_refsN)rE   rF   rG   r  r  r   r	  r  r  r  r  r  r  r  r  r$  r+  r;   r;   r;   r<   r  x  s   	


5r  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
GetUtilitiesTestCasec                 C   sd  t d}G dd dt| }| t|t | | t|| | | ttd  | ttt t | ttttf t | ttd t | tt	t
t  t	 | ttt | tt| t | tt
t||f  t t | tt|df t | tt
t | ttt | tttjj | ttt t | ttd  d S )Nr   c                   @   s   e Zd ZdS )z/GetUtilitiesTestCase.test_get_origin.<locals>.CNrI   r;   r;   r;   r<   r   8  r   r   rO   +   r2  )r
   r   rw   r   rY   r   r   r{   r   r   r   r   r   r.   r   r   r  r>  r  r;   r;   r<   test_get_origin6  s$     z$GetUtilitiesTestCase.test_get_originc              	   C   s  t d}G dd dt| }| t|t tf | t|| |f | ttd | ttt tf | ttttf ttf | ttd d | tt	t
t  t
t f | tttt|tf f t ttttf f | ttjtt||f f tt  tttt tt f f | ttg |f t g tf | ttdtf dtf | ttttt|df gtf f ttt|df gtf f | tttdf tdf | ttd d | tt|dd	d
gf |dd	d
gf | tt
d | ttd | ttd | ttt tf | ttd | ttjjtgtf tgtf | ttjjdtf dtf | ttjjg tf g tf | ttjjtgtf tttgtf  d S )Nr   c                   @   s   e Zd ZdS )z-GetUtilitiesTestCase.test_get_args.<locals>.CNrI   r;   r;   r;   r<   r   L  r   r   r;   r-  .)r;   oner   Zthree)r
   r   rV   r    rY   r   r   r{   r   r   r   r   r@   r   r   r   r.   r   r  r>  r  r;   r;   r<   test_get_argsJ  sD    $ $($  z"GetUtilitiesTestCase.test_get_argsc                 C   s:   t t}| |dtt i t tj}| |dti d S )Nr  r  )r   r  rV   r   r{   ZMyClass)r7   r  r;   r;   r<   test_forward_ref_and_finalj  s    
z/GetUtilitiesTestCase.test_forward_ref_and_finalc                 C   s8   |  td tt W d    n1 s*0    Y  d S )Nz4typing.ClassVar\[int\] is not valid as type argument)assertRaisesRegexrQ   r   r  rS   r;   r;   r<   test_top_level_class_varr  s
    z-GetUtilitiesTestCase.test_top_level_class_varN)rE   rF   rG   r/  r1  r2  r4  r;   r;   r;   r<   r,  5  s    r,  c                   @   s  e Zd Zdd Zdd Zdd Zeeddd	 Zeedd
d Z	eeddd Z
eed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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$ee%j&dBkdCdDdE Z'ee%j&dBkdCdFdG Z(dHdI Z)dJdK Z*dLdM Z+dNdO Z,dPdQ Z-dRdS Z.dTdU Z/dVdW Z0dXdY Z1dZd[ Z2d\d] Z3d^d_ Z4d`da Z5dbdc Z6ddde Z7dfdg Z8dhdi Z9djS )kCollectionsAbcTestsc                 C   s    |  dtj | g tj d S rN   )rk   r@   Hashabler   rS   r;   r;   r<   test_hashable}  s    z!CollectionsAbcTests.test_hashablec                 C   sX   |  g tj |  g tj |  g tj | dtj | ttj | ttj d S rN   )rk   r@   r   r   r=   r   rS   r;   r;   r<   test_iterable  s    z!CollectionsAbcTests.test_iterablec                 C   s(   t g }| |tj | dtj d S rN   )r  rk   r@   Iteratorr   )r7   itr;   r;   r<   test_iterator  s    z!CollectionsAbcTests.test_iteratorz&Python 3.5 and multithreading requiredc                 C   sJ   i }t dt | |d }| }| |tj | |tj |d  d S )NzPasync def foo() -> typing.Awaitable[int]:
    return await AwaitableWrapper(42)
r   )r   r   rk   r@   	Awaitabler   sendr7   r  r   gr;   r;   r<   test_awaitable  s    z"CollectionsAbcTests.test_awaitablec                 C   s   i }t dt | |d }| }| |tj | t  t|tjt  W d    n1 s^0    Y  | 	|tj z|
d  W n ty   Y n0 d S )Nzasync def foo():
    return
r   )r   r   rk   r@   	CoroutinerP   rQ   rR   rY   r   r=  StopIterationr>  r;   r;   r<   test_coroutine  s    .z"CollectionsAbcTests.test_coroutinec                 C   s>   t d}t|}| |tj | |tj | dtj d S Nr   rO   )r  AsyncIteratorWrapperrk   r@   AsyncIterabler   r7   Zbase_itr:  r;   r;   r<   test_async_iterable  s
    z'CollectionsAbcTests.test_async_iterablec                 C   s0   t d}t|}| |tj | dtj d S rD  )r  rE  rk   r@   AsyncIteratorr   rG  r;   r;   r<   test_async_iterator  s    z'CollectionsAbcTests.test_async_iteratorc                 C   s    |  g tj | dtj d S rN   )rk   r@   Sizedr   rS   r;   r;   r<   
test_sized  s    zCollectionsAbcTests.test_sizedc                 C   s    |  g tj | dtj d S rN   )rk   r@   	Containerr   rS   r;   r;   r<   test_container  s    z"CollectionsAbcTests.test_containerc                 C   s@   |  t tj |  t tj | ttj | dtj d S rN   )rk   r   r@   
Collectionr  r=   r   r   rS   r;   r;   r<   test_collection  s    z#CollectionsAbcTests.test_collectionc                 C   s"   |  t tj | dtj d S rN   )rk   re  r@   r=  r   rS   r;   r;   r<   test_abstractset  s    z$CollectionsAbcTests.test_abstractsetc                 C   s$   |  t tj | t tj d S r?   )rk   re  r@   
MutableSetr   r  rS   r;   r;   r<   test_mutableset  s    z#CollectionsAbcTests.test_mutablesetc                 C   s    |  i tj | dtj d S rN   )rk   r@   r   r   rS   r;   r;   r<   test_mapping  s    z CollectionsAbcTests.test_mappingc                 C   s    |  i tj | dtj d S rN   )rk   r@   r   r   rS   r;   r;   r<   test_mutablemapping  s    z'CollectionsAbcTests.test_mutablemappingc                 C   s    |  g tj | dtj d S rN   )rk   r@   r+  r   rS   r;   r;   r<   test_sequence  s    z!CollectionsAbcTests.test_sequencec                 C   s    |  g tj | dtj d S r   )rk   r@   MutableSequencer   rS   r;   r;   r<   test_mutablesequence  s    z(CollectionsAbcTests.test_mutablesequencec                 C   s$   |  dtj |  tdtj d S r  )rk   r@   
ByteString	bytearrayrS   r;   r;   r<   test_bytestring  s    z#CollectionsAbcTests.test_bytestringc                 C   s   |  ttj d S r?   )r=   r   r@   r   rS   r;   r;   r<   	test_list  s    zCollectionsAbcTests.test_listc                 C   s:   |  tjtj G dd dtjt }| | tj d S )Nc                   @   s   e Zd ZdS )z/CollectionsAbcTests.test_deque.<locals>.MyDequeNrI   r;   r;   r;   r<   MyDeque  r   r]  )r=   r  dequer@   DequerY   rk   )r7   r]  r;   r;   r<   
test_deque  s    zCollectionsAbcTests.test_dequec                 C   s   |  tjtj d S r?   )r=   r  Counterr@   rS   r;   r;   r<   test_counter  s    z CollectionsAbcTests.test_counterc                 C   s    |  ttj | ttj d S r?   )r=   re  r@   Setr>   r  rS   r;   r;   r<   test_set  s    zCollectionsAbcTests.test_setc                 C   s    |  ttj | ttj d S r?   )r=   r  r@   r  r>   re  rS   r;   r;   r<   test_frozenset  s    z"CollectionsAbcTests.test_frozensetc                 C   s   |  ttj d S r?   )r=   r   r@   r   rS   r;   r;   r<   r    s    zCollectionsAbcTests.test_dictc                 C   s   t d}t d}| t||f ttf tttf  | t|tf t tttf  | tt|f t tttf  | t|t| f ttf tttt f  | t|tt f t tttt f  | t|t| f ttf tttt f  | t|tt f t tttt f  d S )NKr   )r
   rV   r   r{   rY   r   r   )r7   rf  r   r;   r;   r<   test_dict_subscribe  s    $  ,(,z'CollectionsAbcTests.test_dict_subscribec                 C   s   |  t t  W d    n1 s(0    Y  |  t tjt   W d    n1 s^0    Y  |  t tjt   W d    n1 s0    Y  d S r?   )rP   rQ   r@   r   r   rY   rS   r;   r;   r<   test_no_list_instantiation
  s    &*z.CollectionsAbcTests.test_no_list_instantiationc                 C   sR   G dd dt jt }| }| || | |t j | |t | t| d S )Nc                   @   s   e Zd ZdS )z6CollectionsAbcTests.test_list_subclass.<locals>.MyListNrI   r;   r;   r;   r<   MyList  s   ri  )r@   r   rY   rk   r+  r=   r   r>   )r7   ri  r   r;   r;   r<   test_list_subclass  s    z&CollectionsAbcTests.test_list_subclassc                 C   s   |  t t  W d    n1 s(0    Y  |  t  tjttf   W d    n1 sb0    Y  |  t  tjttf   W d    n1 s0    Y  d S r?   )rP   rQ   r@   r   r   r   r{   rY   rS   r;   r;   r<   test_no_dict_instantiation  s    &.z.CollectionsAbcTests.test_no_dict_instantiationc                 C   sV   G dd dt jttf }| }| || | |t j | |t | t| d S )Nc                   @   s   e Zd ZdS )z6CollectionsAbcTests.test_dict_subclass.<locals>.MyDictNrI   r;   r;   r;   r<   r1  (  s   r1  )	r@   r   r{   rY   rk   r   r=   r   r>   )r7   r1  rU  r;   r;   r<   test_dict_subclass&  s    z&CollectionsAbcTests.test_dict_subclassc                 C   sV   |  tt tj |  ttjttf  tj |  ttjtt	f  tj d S r?   )
rw   r^   r@   r5  r  defaultdictr   r   r{   rY   rS   r;   r;   r<   test_defaultdict_instantiation2  s    z2CollectionsAbcTests.test_defaultdict_instantiationc                 C   sL   G dd dt jttf }| }| || | |tj | tj| d S )Nc                   @   s   e Zd ZdS )z@CollectionsAbcTests.test_defaultdict_subclass.<locals>.MyDefDictNrI   r;   r;   r;   r<   	MyDefDict9  s   ro  )	r@   r5  r{   rY   rk   r=   r  rm  r>   )r7   ro  ddr;   r;   r<   test_defaultdict_subclass7  s
    z-CollectionsAbcTests.test_defaultdict_subclassc                 C   sV   |  tt tj |  ttjttf  tj |  ttjttf  tj d S r?   )	rw   r^   r@   OrderedDictr  r   r   r{   rY   rS   r;   r;   r<   test_ordereddict_instantiationB  s    z2CollectionsAbcTests.test_ordereddict_instantiationc                 C   sL   G dd dt jttf }| }| || | |tj | tj| d S )Nc                   @   s   e Zd ZdS )z@CollectionsAbcTests.test_ordereddict_subclass.<locals>.MyOrdDictNrI   r;   r;   r;   r<   	MyOrdDictI  s   rt  )r@   rr  r{   rY   rk   r=   r  r>   )r7   rt  Zodr;   r;   r<   test_ordereddict_subclassG  s
    z-CollectionsAbcTests.test_ordereddict_subclassr3  zChainMap was added in 3.3c                 C   s   |  tt tj |  ttjttf  tj |  ttjttf  tj G dd dtjttf }|  t|ttf  | d S )Nc                   @   s   e Zd ZdS )z;CollectionsAbcTests.test_chainmap_instantiation.<locals>.CMNrI   r;   r;   r;   r<   CMW  r   rv  )	rw   r^   r@   r6  r  r   r   r{   rY   )r7   rv  r;   r;   r<   test_chainmap_instantiationR  s
    z/CollectionsAbcTests.test_chainmap_instantiationc                 C   sL   G dd dt jttf }| }| || | |tj | tj| d S )Nc                   @   s   e Zd ZdS )z>CollectionsAbcTests.test_chainmap_subclass.<locals>.MyChainMapNrI   r;   r;   r;   r<   
MyChainMap]  s   rx  )r@   r6  r{   rY   rk   r=   r  r>   )r7   rx  cmr;   r;   r<   test_chainmap_subclassZ  s
    z*CollectionsAbcTests.test_chainmap_subclassc                 C   sz   |  tt tj |  ttjt  tj |  ttjt  tj G dd dtjt }|  t|t  | d S )Nc                   @   s   e Zd ZdS )z7CollectionsAbcTests.test_deque_instantiation.<locals>.DNrI   r;   r;   r;   r<   r-  j  r   r-  )rw   r^   r@   r_  r  r^  r   rY   r  r;   r;   r<   test_deque_instantiationf  s
    z,CollectionsAbcTests.test_deque_instantiationc                 C   sz   |  tt tj |  ttjt  tj |  ttjt  tj G dd dtjt }|  t|t  | d S )Nc                   @   s   e Zd ZdS )z9CollectionsAbcTests.test_counter_instantiation.<locals>.CNrI   r;   r;   r;   r<   r   q  r   r   )rw   r^   r@   ra  r  r   rY   r   r;   r;   r<   test_counter_instantiationm  s
    z.CollectionsAbcTests.test_counter_instantiationc                 C   sH   G dd dt jt }| }| || | |t j | |tj d S )Nc                   @   s   e Zd ZdS )zJCollectionsAbcTests.test_counter_subclass_instantiation.<locals>.MyCounterNrI   r;   r;   r;   r<   	MyCounterv  s   r}  )r@   ra  rY   rk   r  )r7   r}  rU  r;   r;   r<   #test_counter_subclass_instantiationt  s
    z7CollectionsAbcTests.test_counter_subclass_instantiationc                 C   s   |  t t  W d    n1 s(0    Y  |  t tjt   W d    n1 s^0    Y  |  t tjt   W d    n1 s0    Y  d S r?   )rP   rQ   r@   rc  r   rY   rS   r;   r;   r<   test_no_set_instantiation~  s    &*z-CollectionsAbcTests.test_no_set_instantiationc                 C   s,   G dd dt jt }| }| || d S )Nc                   @   s   e Zd ZdS )zBCollectionsAbcTests.test_set_subclass_instantiation.<locals>.MySetNrI   r;   r;   r;   r<   r*    s   r*  )r@   rc  rY   rk   )r7   r*  rU  r;   r;   r<   test_set_subclass_instantiation  s    z3CollectionsAbcTests.test_set_subclass_instantiationc                 C   s   |  t t  W d    n1 s(0    Y  |  t tjt   W d    n1 s^0    Y  |  t tjt   W d    n1 s0    Y  d S r?   )rP   rQ   r@   r  r   rY   rS   r;   r;   r<   test_no_frozenset_instantiation  s    &*z3CollectionsAbcTests.test_no_frozenset_instantiationc                 C   s,   G dd dt jt }| }| || d S )Nc                   @   s   e Zd ZdS )zNCollectionsAbcTests.test_frozenset_subclass_instantiation.<locals>.MyFrozenSetNrI   r;   r;   r;   r<   MyFrozenSet  s   r  )r@   r  rY   rk   )r7   r  rU  r;   r;   r<   %test_frozenset_subclass_instantiation  s    z9CollectionsAbcTests.test_frozenset_subclass_instantiationc                 C   s   |  t t  W d    n1 s&0    Y  |  t tt   W d    n1 sZ0    Y  |  t tt   W d    n1 s0    Y  d S r?   )rP   rQ   r   r   rY   rS   r;   r;   r<   test_no_tuple_instantiation  s    $(z/CollectionsAbcTests.test_no_tuple_instantiationc                 C   s$   dd }| }|  t|tj d S )Nc                   s   s
   dV  d S rN   r;   r;   r;   r;   r<   r     s    z/CollectionsAbcTests.test_generator.<locals>.foo)r=   r^   r@   	Generator)r7   r   r?  r;   r;   r<   test_generator  s    z"CollectionsAbcTests.test_generatorc                 C   s   |  t t  W d    n1 s(0    Y  |  t" tjtttf   W d    n1 sd0    Y  |  t" tjtttf   W d    n1 s0    Y  d S r?   )rP   rQ   r@   r  r   rY   rS   r;   r;   r<   test_no_generator_instantiation  s    &0z3CollectionsAbcTests.test_no_generator_instantiationc                 C   s2   i }t dt | |d  }| t|tj d S )Nzasync def f():
    yield 42
rC   )r   r   r=   r^   r@   AsyncGenerator)r7   r  r?  r;   r;   r<   test_async_generator  s    
z(CollectionsAbcTests.test_async_generatorc                 C   s   |  t t  W d    n1 s(0    Y  |  t  tjttf   W d    n1 sb0    Y  |  t  tjttf   W d    n1 s0    Y  d S r?   )rP   rQ   r@   r  r   rY   rS   r;   r;   r<   %test_no_async_generator_instantiation  s    &.z9CollectionsAbcTests.test_no_async_generator_instantiationc                 C   sV  G dd dt j}| t |  W d    n1 s80    Y  G dd d|}| t| d | | t j G dd dt jtt	f }| t| d | t|t
t
f  d | t|tt	f  d | t| | t| | |t j | |t j | |t j | |tt	f  t j | |tt	f  tjj | |tjj | |tjj | |tjj | t$ t|t
t
f t j W d    n1 s0    Y  | || G dd	 d	t j}| t| G d
d dt jtttf }dd }| |t j | |t j | |tjj | |tjj | t|| d S )Nc                   @   s   e Zd ZdS )z1CollectionsAbcTests.test_subclassing.<locals>.MMANrI   r;   r;   r;   r<   MMA  s   r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )z1CollectionsAbcTests.test_subclassing.<locals>.MMCc                 S   s   d S r?   r;   r  r;   r;   r<   r    s    z=CollectionsAbcTests.test_subclassing.<locals>.MMC.__getitem__c                 S   s   d S r?   r;   r  r;   r;   r<   r
    s    z=CollectionsAbcTests.test_subclassing.<locals>.MMC.__setitem__c                 S   s   d S r?   r;   r  r;   r;   r<   r    s    z=CollectionsAbcTests.test_subclassing.<locals>.MMC.__delitem__c                 S   s   t dS r   r  rS   r;   r;   r<   r    s    z:CollectionsAbcTests.test_subclassing.<locals>.MMC.__iter__c                 S   s   dS r_  r;   rS   r;   r;   r<   r    s    z9CollectionsAbcTests.test_subclassing.<locals>.MMC.__len__Nr  r;   r;   r;   r<   MMC  s
   r  r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )z1CollectionsAbcTests.test_subclassing.<locals>.MMBc                 S   s   d S r?   r;   r  r;   r;   r<   r    s    z=CollectionsAbcTests.test_subclassing.<locals>.MMB.__getitem__c                 S   s   d S r?   r;   r  r;   r;   r<   r
    s    z=CollectionsAbcTests.test_subclassing.<locals>.MMB.__setitem__c                 S   s   d S r?   r;   r  r;   r;   r<   r    s    z=CollectionsAbcTests.test_subclassing.<locals>.MMB.__delitem__c                 S   s   t dS r   r  rS   r;   r;   r<   r    s    z:CollectionsAbcTests.test_subclassing.<locals>.MMB.__iter__c                 S   s   dS r_  r;   rS   r;   r;   r<   r    s    z9CollectionsAbcTests.test_subclassing.<locals>.MMB.__len__Nr  r;   r;   r;   r<   MMB  s
   r  c                   @   s   e Zd ZdS )z/CollectionsAbcTests.test_subclassing.<locals>.INrI   r;   r;   r;   r<   I  r   r  c                   @   s   e Zd ZdS )z/CollectionsAbcTests.test_subclassing.<locals>.GNrI   r;   r;   r;   r<   rj     r   rj  c                   s   s
   dV  d S r_  r;   r;   r;   r;   r<   r?    r   z/CollectionsAbcTests.test_subclassing.<locals>.g)r@   r   rP   rQ   rV   r   rk   r   r   r   r{   r>   r   r=   r  r>  r5   r   r   r  rY   r^   )r7   r  r  r  r  rj  r?  r;   r;   r<   test_subclassing  s@    $4z$CollectionsAbcTests.test_subclassingc                 C   s   G dd dt jttf }i }tdt | |d }| |t j | |t j | |tjj | |tjj | 	t
|| | }| |t j | |t j | |tjj | |tjj | t
|| | || d S )Nc                   @   s   e Zd Zdd ZdddZdS )z?CollectionsAbcTests.test_subclassing_async_generator.<locals>.Gc                 S   s   d S r?   r;   )r7   r  r;   r;   r<   asend
  s    zECollectionsAbcTests.test_subclassing_async_generator.<locals>.G.asendNc                 S   s   d S r?   r;   )r7   typvaltbr;   r;   r<   athrow  s    zFCollectionsAbcTests.test_subclassing_async_generator.<locals>.G.athrow)NN)rE   rF   rG   r  r  r;   r;   r;   r<   rj  	  s   rj  zasync def g(): yield 0r?  )r@   r  rY   r   r   r=   rF  r  r>  r>   r^   rk   r   )r7   rj  r  r?  instancer;   r;   r<    test_subclassing_async_generator  s     z4CollectionsAbcTests.test_subclassing_async_generatorc                 C   sf   G dd dt j}G dd d|}G dd d}G dd d}| || | || | || d S )	Nc                   @   s   e Zd Zedd ZdS )z?CollectionsAbcTests.test_subclassing_subclasshook.<locals>.Basec                 S   s   |j dkrdS dS d S )Nr   TF)rE   rx  r;   r;   r<   rz  #  s    
zPCollectionsAbcTests.test_subclassing_subclasshook.<locals>.Base.__subclasshook__Nr{  r;   r;   r;   r<   r  "  s   r  c                   @   s   e Zd ZdS )z<CollectionsAbcTests.test_subclassing_subclasshook.<locals>.CNrI   r;   r;   r;   r<   r   *  r   r   c                   @   s   e Zd ZdS )z>CollectionsAbcTests.test_subclassing_subclasshook.<locals>.FooNrI   r;   r;   r;   r<   r   +  r   r   c                   @   s   e Zd ZdS )z>CollectionsAbcTests.test_subclassing_subclasshook.<locals>.BarNrI   r;   r;   r;   r<   r   ,  r   r   )r@   r   r=   r>   )r7   r  r   r   r   r;   r;   r<   test_subclassing_subclasshook   s    z1CollectionsAbcTests.test_subclassing_subclasshookc                 C   s   G dd dt j}G dd d|}G dd d}|| | || | || G dd d}|| | || | || G d	d
 d
}tjj| | |t j d S )Nc                   @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.ANrI   r;   r;   r;   r<   r\   3  r   r\   c                   @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.BNrI   r;   r;   r;   r<   r@  4  r   r@  c                   @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.CNrI   r;   r;   r;   r<   r   6  r   r   c                   @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.DNrI   r;   r;   r;   r<   r-  ;  r   r-  c                   @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.MNrI   r;   r;   r;   r<   r  @  r   r  )	r@   rM  rU  r=   r>   r  r>  r   r   )r7   r\   r@  r   r-  r  r;   r;   r<   test_subclassing_register1  s    

z-CollectionsAbcTests.test_subclassing_registerc                 C   s   G dd dt jj}| |tj | |tj G dd dt jj}| |tj | |tj G dd dt jj}| |tj G dd dt jjtjd	}G d
d d}|| | |tj d S )Nc                   @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.MNrI   r;   r;   r;   r<   r  F  r   r  c                   @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.SNrI   r;   r;   r;   r<   r  J  r   r  c                   @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.INrI   r;   r;   r;   r<   r  N  r   r  c                   @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.ANrI   r;   r;   r;   r<   r\   Q  r   r\   )	metaclassc                   @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.BNrI   r;   r;   r;   r<   r@  R  r   r@  )	r  r>  r   r=   r@   r   rW  ABCMetarU  )r7   r  r  r  r\   r@  r;   r;   r<   test_collections_as_baseD  s    
z,CollectionsAbcTests.test_collections_as_baseN):rE   rF   rG   r7  r8  r;  r   ASYNCIOr@  rC  rH  rJ  rL  rN  rP  rQ  rS  rT  rU  rV  rX  r[  r\  r`  rb  rd  re  r  rg  rh  rj  rk  rl  rn  rq  rs  ru  r  r  rw  rz  r{  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r;   r;   r;   r<   r5  {  sr   






Er5  c                   @   s&   e Zd Zdd Zeeddd ZdS )OtherABCTestsc                 C   s4   t jdd }| }| |tj | dtj d S )Nc                   s   s
   dV  d S rN   r;   r;   r;   r;   r<   managerZ  s    z2OtherABCTests.test_contextmanager.<locals>.managerrO   )
contextlibcontextmanagerrk   r@   r  r   )r7   r  ry  r;   r;   r<   test_contextmanagerY  s
    
z!OtherABCTests.test_contextmanagerzPython 3.5 requiredc                 C   s   G dd d}|  t tj | | tj tjdd }| }| |tj | tjt j	tf | 
t  tdtjt  W d    n1 s0    Y  | 
t tjttf  W d    n1 s0    Y  d S )Nc                   @   s   e Zd ZdS )z7OtherABCTests.test_async_contextmanager.<locals>.NotACMNrI   r;   r;   r;   r<   NotACMd  s   r  c                   s   s
   dV  d S rN   r;   r;   r;   r;   r<   r  h  s    z8OtherABCTests.test_async_contextmanager.<locals>.managerrO   )rk   ACMr@   r  r   r  r  rV   rY   ru   rP   rQ   rR   r{   )r7   r  r  ry  r;   r;   r<   test_async_contextmanagerb  s    
.z'OtherABCTests.test_async_contextmanagerN)rE   rF   rG   r  r   r  r  r;   r;   r;   r<   r  W  s   	r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )	TypeTestsc                 C   sN   G dd d}G dd d|}G dd d|}t | |ddd	}|| d S )
Nc                   @   s   e Zd ZdS )z'TypeTests.test_type_basic.<locals>.UserNrI   r;   r;   r;   r<   Usery  r   r  c                   @   s   e Zd ZdS )z,TypeTests.test_type_basic.<locals>.BasicUserNrI   r;   r;   r;   r<   	BasicUserz  r   r  c                   @   s   e Zd ZdS )z*TypeTests.test_type_basic.<locals>.ProUserNrI   r;   r;   r;   r<   ProUser{  r   r  
user_classr   c                 S   s   |  S r?   r;   r  r;   r;   r<   new_user}  s    z+TypeTests.test_type_basic.<locals>.new_userr#   )r7   r  r  r  r  r;   r;   r<   test_type_basicw  s
    zTypeTests.test_type_basicc                 C   sZ   G dd d}G dd d|}G dd d|}t d|d}t| |d	d
d}|| d S )Nc                   @   s   e Zd ZdS )z)TypeTests.test_type_typevar.<locals>.UserNrI   r;   r;   r;   r<   r    r   r  c                   @   s   e Zd ZdS )z.TypeTests.test_type_typevar.<locals>.BasicUserNrI   r;   r;   r;   r<   r    r   r  c                   @   s   e Zd ZdS )z,TypeTests.test_type_typevar.<locals>.ProUserNrI   r;   r;   r;   r<   r    r   r  r  r   r  c                 S   s   |  S r?   r;   r  r;   r;   r<   r    s    z-TypeTests.test_type_typevar.<locals>.new_user)r
   r$   )r7   r  r  r  r  r  r;   r;   r<   test_type_typevar  s    zTypeTests.test_type_typevarc                 C   s$   t tt  }|t t ddd}d S )Nr  c                 S   s   | d u rd S |  S d S r?   r;   r   r;   r;   r<   r     s    z)TypeTests.test_type_optional.<locals>.foo)r   r$   BaseException)r7   r\   r   r;   r;   r<   test_type_optional  s    zTypeTests.test_type_optionalN)rE   rF   rG   r  r  r  r;   r;   r;   r<   r  u  s   r  c                   @   s   e Zd Zdd Zdd ZdS )NewTypeTestsc                 C   sL   t dt}t dt}| |dt | |dt | |dd d d S )NUserIdUserNamer   Joer      )r%   rY   r{   rk   rV   )r7   r  r  r;   r;   r<   
test_basic  s
    

zNewTypeTests.test_basicc                 C   s   t dt}t dt}| t t|t W d    n1 s>0    Y  | t  G dd d|}W d    n1 sx0    Y  d S )Nr  r  c                   @   s   e Zd ZdS )z#NewTypeTests.test_errors.<locals>.DNrI   r;   r;   r;   r<   r-    s   r-  )r%   rY   r{   rP   rQ   r5   )r7   r  r  r-  r;   r;   r<   rZ     s    

(zNewTypeTests.test_errorsN)rE   rF   rG   r  rZ   r;   r;   r;   r<   r    s   r  c                   @   st   e Zd ZG dd de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 )NamedTupleTestsc                   @   s   e Zd ZU eed< eed< dS )zNamedTupleTests.NestedEmployeer  r  Nr  r;   r;   r;   r<   NestedEmployee  s   
r  c                 C   s   t ddtfdtfg}| |t |dd}|ddd}| || | |t | |jd | |jd | |jd | |jd | |j	d | |j
d | |jtdtfdtfg d S )	NEmpr  idr  rO   Jimr   r  r  )r&   r{   rY   r=   r   rk   rV   r  r  rE   _fieldsr  r  rr  )r7   r  Zjoejimr;   r;   r<   r     s    
zNamedTupleTests.test_basicsc                 C   s   t jd d dk r| t tdttd W d    n1 s@0    Y  | t  G dd dt}W d    n1 sz0    Y  d S )Nr   )r   r  Name)r0  ry  c                   @   s   e Zd ZdZdS )z9NamedTupleTests.test_namedtuple_pyversion.<locals>.NotYetr   N)rE   rF   rG   rJ  r;   r;   r;   r<   NotYet  s   r  )r  r  rP   rQ   r&   rY   r{   )r7   r  r;   r;   r<   test_namedtuple_pyversion  s
    ,z)NamedTupleTests.test_namedtuple_pyversionc                 C   sv   t dd}| |t  | |t | |jd | |jd | t jd | t jd | t jt	j
ttd d S )NZTimi(#  r  r  r  )r  rk   r   rV   r  r  rE   r  r  r  rr  r{   rY   )r7   Ztimr;   r;   r<   test_annotation_usage  s    
z%NamedTupleTests.test_annotation_usagec                 C   s   t d}| |t  | |t | |jd | |jd t dd}| |jd | t jd | t jd | t jt	t
td | t jt	dd | t  G dd	 d	t}W d    n1 s0    Y  d S )
NZJeller   ZSjoerdr   r  r  )r  c                   @   s"   e Zd ZU dZeed< eed< dS )zRNamedTupleTests.test_annotation_usage_with_default.<locals>.NonDefaultAfterDefaultr   r   r   N)rE   rF   rG   r   rY   r  r;   r;   r;   r<   NonDefaultAfterDefault  s   
r  )r  rk   r   rV   r  r  rE   r  r  r   r{   rY   _field_defaultsrP   rQ   r&   )r7   ZjelleZcooler_employeer  r;   r;   r<   "test_annotation_usage_with_default  s    

z2NamedTupleTests.test_annotation_usage_with_defaultc                 C   s   |  td d |  tdjtdd  |  ttdd |  tddtd d | t  G dd dt}W d    n1 s0    Y  | t  G d	d
 d
t}W d    n1 s0    Y  d S )Nr   r   rO   r   z42 -> 1r   c                   @   s   e Zd ZU eed< dd ZdS )zDNamedTupleTests.test_annotation_usage_with_methods.<locals>.XMethBadr   c                 S   s   dS )Nzno chance for thisr;   rS   r;   r;   r<   r    s    zLNamedTupleTests.test_annotation_usage_with_methods.<locals>.XMethBad._fieldsN)rE   rF   rG   rY   r  r  r;   r;   r;   r<   XMethBad  s   
r  c                   @   s   e Zd ZU eed< dd ZdS )zENamedTupleTests.test_annotation_usage_with_methods.<locals>.XMethBad2r   c                 S   s   dS )Nzno chance for this as wellr;   rS   r;   r;   r<   _source  s    zMNamedTupleTests.test_annotation_usage_with_methods.<locals>.XMethBad2._sourceN)rE   rF   rG   rY   r  r  r;   r;   r;   r<   	XMethBad2  s   
r  )	rV   r  r  r   r{   r  rP   r  r&   )r7   r  r  r;   r;   r<   "test_annotation_usage_with_methods  s    .z2NamedTupleTests.test_annotation_usage_with_methodsc                 C   sN   G dd d}|  t" G dd dt|}W d    n1 s@0    Y  d S )Nc                   @   s   e Zd ZdS )z4NamedTupleTests.test_multiple_inheritance.<locals>.ANrI   r;   r;   r;   r<   r\     s   r\   c                   @   s   e Zd ZU eed< dS )z4NamedTupleTests.test_multiple_inheritance.<locals>.Xr   Nr  r;   r;   r;   r<   rp     s   
rp   )rP   rQ   r&   )r7   r\   rp   r;   r;   r<   r\    s    z)NamedTupleTests.test_multiple_inheritancec                 C   s   t dttd}|dd}| |t | |jd | |jd | |jd | |j	t
ttd | t$ t ddtfgtd W d    n1 s0    Y  | t t ddd	d
 W d    n1 s0    Y  d S )NLocalEmployee)r  ZageZNick   r  r   r   r   r   r[  )r&   r{   rY   rk   r   rV   r  rE   r  r  r   rP   rQ   )r7   r  Znickr;   r;   r<   test_namedtuple_keyword_usage  s    
2z-NamedTupleTests.test_namedtuple_keyword_usagec                 C   s   t dttttd}| |jd | |jd |tdddtfgd}| |j	t | |j
d | |jd | |jdtfg d S )Nr'  )r8   r7   typenamefieldsrO   r   r   )r&   r^   r   r{   r   rV   rE   r  r   r8   r7   r  r  )r7   r'  r   r;   r;   r<   %test_namedtuple_special_keyword_names  s    z5NamedTupleTests.test_namedtuple_special_keyword_namesc              	   C   s   t d}G dd dt }||fD ]h}| j|dH | |jd | |ji  | |ji  | | | W d    q 1 s~0    Y  q d S )Nr'  c                   @   s   e Zd ZdS )z2NamedTupleTests.test_empty_namedtuple.<locals>.CNTNrI   r;   r;   r;   r<   CNT  s   r  )structr;   )r&   subTestrV   r  r  r  rk   )r7   r'  r  r  r;   r;   r<   test_empty_namedtuple  s    z%NamedTupleTests.test_empty_namedtuplec                 C   sZ  |  t t  W d    n1 s(0    Y  |  t t  W d    n1 sX0    Y  |  t" tddtfgd  W d    n1 s0    Y  |  t  tddtfg W d    n1 s0    Y  |  t tdttd W d    n1 s0    Y  |  t( tddtfdtfgd W d    n1 sL0    Y  d S )Nr  r  _name)r  r  r  r  )r  )rP   rQ   r&   r  r{   r   rY   rS   r;   r;   r<   test_namedtuple_errors(  s    &$0..z&NamedTupleTests.test_namedtuple_errorsc              	   C   s   t ddtfdtfgatt| jfD ]}| j|d |dd}ttj	d D ]2}t
||}t|}| || | || qLt|}| || | || t|}| || | || W d    q"1 s0    Y  q"d S )Nr  r  r  )r8   jane%   r   )r&   r{   rY   r  r  r  r  r  r  r  r  r  rV   rk   r   r   )r7   r8   r  r  r   jane2r;   r;   r<   test_copy_and_pickle6  s    

z$NamedTupleTests.test_copy_and_pickleN)rE   rF   rG   r&   r  r   r  r  r  r  r\  r  r  r  r  r  r;   r;   r;   r<   r    s   
r  c                   @   st   e Z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S )TypedDictTestsc                 C   s   t dttd}| |t | |tj | |tj	j
 |ddd}| t|t | |d d | |d d | |jd | |jt | |jtf | |jttd | |jd d S Nr  r  r  r   r  r  Tr'   r{   rY   r=   r   r@   r   r>   r  r>  r+  rw   r^   rV   rE   rF   r  r  	__total__r7   r  r  r;   r;   r<   test_basics_functional_syntaxL  s    z,TypedDictTests.test_basics_functional_syntaxc                 C   s   t dttd}| |t | |tj | |tj	j
 |ddd}| t|t | |d d | |d d | |jd | |jt | |jtf | |jttd | |jd d S r  r  r  r;   r;   r<   test_basics_keywords_syntax[  s    z*TypedDictTests.test_basics_keywords_syntaxc              
   C   s   t dttttttd}| |jd | |j	ttttttd |tddddt
fgdthd}| |d t | |d	 d | |d
 d | |d d | |d dt
fg | |d dth d S )NTD)r8   r7   r  	_typenamer  r  rO   r   5   r   r   r8   r7   r  r  r  r  )r'   r^   r   r{   rY   r   r   rV   rE   r  r   re  )r7   r  r   r;   r;   r<   $test_typeddict_special_keyword_namesj  s    z3TypedDictTests.test_typeddict_special_keyword_namesc                 C   s  |  t t  W d    n1 s(0    Y  |  t t  W d    n1 sX0    Y  |  t" tddtfgd  W d    n1 s0    Y  |  t tdttd W d    n1 s0    Y  |  t" tdttdd W d    n1 s
0    Y  d S )Nr  r  )r  r  r  r  )r  )rP   rQ   r'   r  r{   rY   rS   r;   r;   r<   test_typeddict_create_errorsv  s    &$0,z+TypedDictTests.test_typeddict_create_errorsc                 C   s~  t dttd}| t jd |ddd}| t ti | W d    n1 sT0    Y  | t t|| W d    n1 s0    Y  | t tt	| W d    n1 s0    Y  | t t ddd W d    n1 s0    Y  | t" t ddtfd	g W d    n1 s00    Y  | t$ t ddtfgtd
 W d    n1 sp0    Y  d S )Nr  r  r@   r  r   ZHir   r   )r   r   r  )
r'   r{   rY   rV   rF   rP   rQ   rR   r5   r   r  r;   r;   r<   test_typeddict_errors  s    (((*2z$TypedDictTests.test_typeddict_errorsc                 C   s   |  tjd |  tjt |  tjtttd |  tjtf |  tj	d | 
ttj tddd}|  |d d |  |d d tddd	d}|  |d
 d	 d S )Nr  rX  Tr   r   r[  r   r   hir  )rV   r  rE   rF   r  rY   r{   r  r   r  r>   r@   r+  r  )r7   Z
not_originry  r;   r;   r<   test_py36_class_syntax_usage  s    z+TypedDictTests.test_py36_class_syntax_usagec                 C   s   t dttdatddd}ttjd D ]d}t||}t|}| 	|| | 	|ddd tt|}t|}| 	|ddd| q*d S )NEmpDr  r  r  r   )
r'   r{   rY   r  r  r  r  r  r  rV   )r7   r  r  r   r  ZZZZEmpDnewr;   r;   r<   r?    s    

zTypedDictTests.test_picklec                 C   sF   t dttd}| tj| tjd |f  | tj| tj	|  d S )Nr  r  )
r'   r{   rY   rV   r@   r   r   rt   r   r   )r7   r  r;   r;   r<   r     s    zTypedDictTests.test_optionalc                 C   s   t ddtidd}| | i  | |ddddi | |jd | |jt  | |jdh | t i  | tddd	di | tjd | tjt  | tjd	d
h d S )Nr-  r   Fr  r   r   r   )r  r  r  )r'   rY   rV   r  __required_keys__r  __optional_keys__r  r  r;   r;   r<   
test_total  s    zTypedDictTests.test_totalc                 C   s   G dd dt dd}d S )Nc                   @   s   e Zd ZU eed< dS )z6TypedDictTests.test_optional_keys.<locals>.Point2Dor3Dr   Nr  r;   r;   r;   r<   Point2Dor3D  s   
r  Fr  )r  )r7   r  r;   r;   r<   test_optional_keys  s    z!TypedDictTests.test_optional_keysc                 C   s8   G dd dt }G dd d|dd}G dd d|}d S )	Nc                   @   s   e Zd ZU eed< dS )z8TypedDictTests.test_keys_inheritance.<locals>.BaseAnimalr  Nr  r;   r;   r;   r<   
BaseAnimal  s   
r  c                   @   s   e Zd ZU eed< eed< dS )z4TypedDictTests.test_keys_inheritance.<locals>.AnimalZvoicetailN)rE   rF   rG   r{   r  r   r;   r;   r;   r<   Animal  s   
r  Fr  c                   @   s   e Zd ZU eed< dS )z1TypedDictTests.test_keys_inheritance.<locals>.CatZ	fur_colorNr  r;   r;   r;   r<   Cat  s   
r  )r'   )r7   r  r  r  r;   r;   r<   test_keys_inheritance  s    z$TypedDictTests.test_keys_inheritancec                 C   s    |  tttjt td d S )Nr  )rV   r   r   r@   r   rY   rS   r;   r;   r<   test_get_type_hints  s    z"TypedDictTests.test_get_type_hintsc                 C   sr   G dd dt }|t }| |j| | |jd | |jtf |dd}| t|t | |ddi d S )Nc                   @   s   e Zd ZU eed< dS )z5TypedDictTests.test_non_generic_subscript.<locals>.TDr   N)rE   rF   rG   r   r  r;   r;   r;   r<   r    s   
r  r;   r   r   r   )	r'   rY   rV   rx   rv   ru   rw   r^   r   )r7   r  r\   r   r;   r;   r<   test_non_generic_subscript  s    
z)TypedDictTests.test_non_generic_subscriptN)rE   rF   rG   r  r  r  r  r  r  r?  r   r  r  r  r  r  r;   r;   r;   r<   r  K  s    r  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
IOTestsc                 C   s.   t tddd}|jd }| |jtf d S )Nr  c                 S   s   |   S r?   readliner   r;   r;   r<   r    s    zIOTests.test_io.<locals>.stuffr   )r)   r   r  rV   rv   r7   r  r   r;   r;   r<   test_io  s    
zIOTests.test_ioc                 C   s,   t tddd}|jd }| |jd d S )Nr  c                 S   s   |   S r?   r  r   r;   r;   r<   r  	  s    z"IOTests.test_textio.<locals>.stuffr   r;   )r*   r{   r  rV   rv   r  r;   r;   r<   test_textio  s    
zIOTests.test_textioc                 C   s,   t tddd}|jd }| |jd d S )Nr  c                 S   s   |   S r?   r  r   r;   r;   r<   r    s    z$IOTests.test_binaryio.<locals>.stuffr   r;   )r+   r|   r  rV   rv   r  r;   r;   r<   test_binaryio  s    
zIOTests.test_binaryioc                 C   sn   ddl m}m}m}m}m} | |tj | |tj | |tj | t	|t	g d | |d d S )Nr   )r)   r*   r+   r:  rE   r(   z	typing.io)
Z	typing.ior)   r*   r+   r:  rE   rw   r@   rV   re  )r7   r)   r*   r+   r:  rE   r;   r;   r<   test_io_submodule  s    zIOTests.test_io_submoduleN)rE   rF   rG   r  r  r  r  r;   r;   r;   r<   r    s   r  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )RETestsc                 C   s   t dt j}| |jt | t|t | |t |d}| |jt	 | t|t	 | |t	 tt
ttf   t	t
ttf   d S )Nz[a-z]+z12345abcde.....)rK  compiler  r=   r  r,   r^   rk   searchr-   r   r{   r|   )r7   patZmatr;   r;   r<   r   #  s    
zRETests.test_basicsc                 C   sP   |  tt tt  | tt tt  | tt tt  | tt t d S r?   )rV   r,   r{   rt   r|   r-   rS   r;   r;   r<   test_alias_equality2  s    zRETests.test_alias_equalityc                 C   s   t tttf  }| t |t  W d    n1 s80    Y  | t tdtt  W d    n1 sp0    Y  | t" ttt tt  W d    n1 s0    Y  d S rN   )	r-   r   r{   r|   rP   rQ   rR   r,   r5   )r7   mr;   r;   r<   rZ   8  s    &,zRETests.test_errorsc                 C   st   |  ttd |  ttt d |  ttt d |  ttd |  ttt d |  ttt d d S )Nztyping.Patternztyping.Pattern[str]ztyping.Pattern[bytes]ztyping.Matchztyping.Match[str]ztyping.Match[bytes])rV   rW   r,   r{   r|   r-   rS   r;   r;   r<   rX   C  s    zRETests.test_reprc                 C   s\   ddl m}m}m}m} | |tj | |tj | t|tddg | |d d S )Nr   )r-   r,   r:  rE   r-   r,   z	typing.re)	Z	typing.rer-   r,   r:  rE   rw   r@   rV   re  )r7   r-   r,   r:  rE   r;   r;   r<   test_re_submoduleK  s
    zRETests.test_re_submodulec                 C   sR   |  t"}G dd dtj}W d    n1 s20    Y  | t|jd d S )Nc                   @   s   e Zd ZdS )z'RETests.test_cannot_subclass.<locals>.ANrI   r;   r;   r;   r<   r\   U  s   r\   z.type 're.Match' is not an acceptable base type)rP   rQ   r@   r-   rV   r{   	exception)r7   exr\   r;   r;   r<   r`   R  s
    0zRETests.test_cannot_subclassN)	rE   rF   rG   r   r  rZ   rX   r  r`   r;   r;   r;   r<   r      s   r   c                   @   s   e Z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(S ))AnnotatedTestsc                 C   s6   |  td t  W d    n1 s(0    Y  d S )Nz%Type Annotated cannot be instantiatedr3  rQ   r.   rS   r;   r;   r<   test_new^  s
    zAnnotatedTests.test_newc                 C   s<   |  tttddf d |  tttt ddf d d S )Nr   r   ztyping.Annotated[int, 4, 5]z(typing.Annotated[typing.List[int], 4, 5])rV   rW   r.   rY   r   rS   r;   r;   r<   rX   e  s    zAnnotatedTests.test_reprc                 C   sJ   t t tdf df }| |t tddf  | |jd | |jt d S )Nr   r   r   )r.   rY   rV   __metadata__rx   r_   r;   r;   r<   r  o  s    zAnnotatedTests.test_flattenc                 C   s   t tt df }t tt df }| |t t tt df  | |t jd | |t jtt  | t |t  W d    n1 s0    Y  | t |tt	f  W d    n1 s0    Y  d S )Nmy decoration)r  )
r.   r   r   rY   rV   r  rx   rP   rQ   r   )r7   LLIr;   r;   r<   test_specializeu  s    &zAnnotatedTests.test_specializec                 C   s   |  tttddf ttddf hd | ttddf ttddf  | ttddf ttddf  | ttdf ttddf  |  ttddf ttddf ttddf httddf ttddf h d S Nr   r   r   rV   r   r.   rY   rt   r{   r   rS   r;   r;   r<   test_hash_eq  s    (  &zAnnotatedTests.test_hash_eqc                    s^   G  fddd t  df }|d} d}| || | |j|j | |j|j d S )Nc                       s$   e Zd ZdZdd Z fddZdS )z*AnnotatedTests.test_instantiate.<locals>.Cr   c                 S   s
   || _ d S r?   r   rb  r;   r;   r<   r    s    z3AnnotatedTests.test_instantiate.<locals>.C.__init__c                    s   t | stS |j| jkS r?   )rR   NotImplementedr   r  r  r;   r<   __eq__  s    
z1AnnotatedTests.test_instantiate.<locals>.C.__eq__N)rE   rF   rG   classvarr  r  r;   r  r;   r<   r     s   r   a decorationr   )r.   rV   r   r  )r7   r\   r   r   r;   r  r<   test_instantiate  s    zAnnotatedTests.test_instantiatec                 C   sN   t tjt df }| |g dddd | |t g dddd d S )Nr  )r   r   r   r   r   r   )r.   r@   ra  r   rV   rY   )r7   ZMyCountr;   r;   r<   test_instantiate_generic  s    z'AnnotatedTests.test_instantiate_genericc                 C   s>   t d }| t |d W d    n1 s00    Y  d S )N)rY   r   r  r   )r.   rP   rQ   r_   r;   r;   r<   test_cannot_instantiate_forward  s    z.AnnotatedTests.test_cannot_instantiate_forwardc                 C   sB   t tdf }| t |d W d    n1 s40    Y  d S )Nr  r   )r.   r   rP   rQ   r_   r;   r;   r<    test_cannot_instantiate_type_var  s    z/AnnotatedTests.test_cannot_instantiate_type_varc                 C   s<   |  t ttdf j W d    n1 s.0    Y  d S )N)r   r  )rP   r  r.   r   r   rS   r;   r;   r<   test_cannot_getattr_typevar  s    z*AnnotatedTests.test_cannot_getattr_typevarc                 C   s@   G dd d}t |df }| |jd d|_| |jd d S )Nc                   @   s   e Zd ZdZdS )z/AnnotatedTests.test_attr_passthrough.<locals>.Cr   N)rE   rF   rG   r  r;   r;   r;   r<   r     s   r   r  r   r   )r.   rV   r  r   )r7   r   r\   r;   r;   r<   test_attr_passthrough  s
    z$AnnotatedTests.test_attr_passthroughc                 C   sJ   G dd d}|  t|t d tt  |  t|t d tt  d S )Nc                   @   s>   e Zd ZU dZeee df ed< dZee	e df ed< dS )z7AnnotatedTests.test_special_form_containment.<locals>.Cr   r  r  r%  r  N)
rE   rF   rG   r  r.   r   rY   r  r  r   r;   r;   r;   r<   r     s   
r   r  r  )rV   r   r   r   rY   r   r   r;   r;   r<   test_special_form_containment  s    z,AnnotatedTests.test_special_form_containmentc                 C   s   |  tttddf ttddf hd | ttddf ttddf  | ttddf ttddf  | ttdf ttddf  |  ttddf ttddf ttddf httddf ttddf h d S r  r  rS   r;   r;   r<   r    s    (  &c                 C   s@   |  td  G dd dt}W d    n1 s20    Y  d S )NzCannot subclass .*Annotatedc                   @   s   e Zd ZdS )z.AnnotatedTests.test_cannot_subclass.<locals>.CNrI   r;   r;   r;   r<   r     s   r   r
  r   r;   r;   r<   r`     s    z#AnnotatedTests.test_cannot_subclassc                 C   s@   |  t" tdttdf  W d    n1 s20    Y  d S )Nr   positive)rP   rQ   rR   r.   rY   rS   r;   r;   r<   test_cannot_check_instance  s    z)AnnotatedTests.test_cannot_check_instancec                 C   s@   |  t" ttttdf  W d    n1 s20    Y  d S )Nr   )rP   rQ   r5   rY   r.   rS   r;   r;   r<   test_cannot_check_subclass  s    z)AnnotatedTests.test_cannot_check_subclassc                 C   s8   |  td tt  W d    n1 s*0    Y  d S )Nzat least two arguments)r3  rQ   r.   rY   rS   r;   r;   r<   test_too_few_type_args  s    z%AnnotatedTests.test_too_few_type_argsc           
   
   C   s6  t jt jttf t jt ttdf t jtgtf g}|D ]t}t	|df }t
tjd D ]T}| j||d2 t||}t|}| || W d    qV1 s0    Y  qVq8G dd dtt at	tt df }d|_d	|_t
tjd D ]D}t||}	t|	}| |jd | |jd	 | |jd qd S )
N.r   r   )protocolr^   c                   @   s   e Zd ZdZdS )_Annotated_test_Gr   NrO  r;   r;   r;   r<   r%    s   r%  zA decorationrO   r>  )r@   r   r   rY   r{   r   r   r   r|   r.   r  r  r  r  r  r  rV   r   r   r%  r   r   r   )
r7   r>  r   r   ZprotZpickledZrestoredrj  r  r   r;   r;   r<   r?    s*    
.
zAnnotatedTests.test_picklec                 C   s  d}d}t t|f }| |t t t|f  | |t t|f  t t||f  t tt |f }| |t t tt |f  | t |ttf  W d    n1 s0    Y  | ||t  t tt ||f  t tjt	t
f |f }| |ttf t tjttf |f  | t |t  W d    n1 s80    Y  t t|f }| t |d   W d    n1 sx0    Y  |t }| t |d   W d    n1 s0    Y  d S )Nr  zanother decoration)r.   r   rV   rY   r   rP   rQ   r@   r   r   r   r{   )r7   r  Zdec2r  r  r-  ZItr  r;   r;   r<   
test_subst  s(    "*"&((zAnnotatedTests.test_substc                 C   s0   t ttdf  }| |t t ttdf   d S )Nr   )r   r.   r   rV   rY   rq   r;   r;   r<   test_annotated_in_other_types  s    z,AnnotatedTests.test_annotated_in_other_typesN)rE   rF   rG   r  rX   r  r  r  r  r  r  r  r  r  r  r`   r!  r"  r#  r?  r&  r'  r;   r;   r;   r<   r	  \  s(   

	
r	  c                   @   s   e Zd Zdd Zdd ZdS )AllTestsc                 C   s   ddl m} | d| | d| | d| | d| | d| | d| | d	| | d
| | d| | d| | d| | d| | d| d S )Nr   )r:  r=  
ValuesViewr   r  r  r  iorK  osr  Textr  r  )r@   r:  r   r  rd  r;   r;   r<   test_all  s    zAllTests.test_allc                    s4   t tj  fddtt D }| |  d S )Nc                    sn   h | ]f\}}| v sf| d s|tjjvr|tjjvr|dvr|ds| |kst|ddtjkr|qS )_>   rK  r*  )r  Z_contraZ_corF   N)	rw  r@   r*  r:  rK  r  upperr8  rE   r  Z
actual_allr;   r<   	<setcomp>7  s   

z3AllTests.test_all_exported_names.<locals>.<setcomp>)re  r@   r:  varsr  ZassertSetEqual)r7   Zcomputed_allr;   r0  r<   test_all_exported_names5  s
    


z AllTests.test_all_exported_namesN)rE   rF   rG   r-  r3  r;   r;   r;   r<   r(    s   r(  __main__)r  r  r  rK  r  Zunittestr   r   r   r   r   r   r@   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r%   r&   r'   r)   r*   r+   r,   r-   r.   r/   r>  rL  r.  r  r0   r1   r2   rH   rJ   rK   rL   rM   rc   ri   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  ZASYNCIO_TESTSr   ImportErrorr  r  r  r  r  r  r  r\   r@  r  rj  r  r  r  r  r  r  r  r  r   r   r  r  r  rY   r  r  r=  rB  er  r  r  r,  r5  r  r  r  r  r  r  r   r	  r(  rE   r;   r;   r;   r<   <module>   s  *"Y *H^      '      9(1  u$
 >F   _'  3#< A0
