B
    u9aZ             
   @   s  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	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 d dlmZmZmZ d d	l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! d dlm"Z" d dlm#Z# d dlm$Z$m%Z%m&Z& d dlm'Z'm(Z( d dl)Z)d dlZd dl*Z*d dl+m,Z, G dd deZ-G dd dZ.G dd de.Z/G dd de.Z0G dd de/e0Z1G dd de-Z2G d d! d!e-Z3G d"d# d#e-Z4G d$d% d%e-Z5G d&d' d'e-Z6G d(d) d)e-Z7ed*e8e9Z:ed+Z;G d,d- d-ee:e;f Z<G d.d/ d/e<e:e;f Z=G d0d1 d1e-Z>G d2d3 d3e-Z?G d4d5 d5e-Z@G d6d7 d7e-ZAG d8d9 d9e-ZBG d:d; d;e-ZCd<ZDyeEeD W n eFk
r   d=ZGY nX d>ZGd d?l+mHZHmIZImJZJ d d@lmKZK G dAdB dBZLG dCdD dDeLZMG dEdF dFeMZNG dGdH dHee ZOG dIdJ dJZPG dKdL dLe#ZQG dMdN dNe#ZRG dOdP dPe#ZSG dQdR dRe#ZTG dSdT dTe,jLZUeKeV dUdVdWZWyeWeX Yd W n$ eZk
r Z[ zW ddZ[[[X Y nX eZ\G dXdY dYe-Z]G dZd[ d[e-Z^G d\d] d]e-Z_G d^d_ d_e-Z`G d`da dae-ZaG dbdc dce-ZbG ddde dee-ZcG dfdg dge-ZdG dhdi die-Zeefdjkre  dS )k    N)TestCasemain
skipUnlessSkipTestskip)copydeepcopy)AnyNoReturn)TypeVarAnyStr)TKTVT)UnionOptional)TupleListMutableMapping)Callable)GenericClassVar)cast)get_type_hints)no_type_checkno_type_check_decorator)Type)NewType)
NamedTuple)IOTextIOBinaryIO)PatternMatch)mod_generics_cachec               @   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 k	r*|d| 7 }| |d S )Nz%r is not a subclass of %rz : %s)
issubclassfailureException)selfclsclass_or_tuplemsgmessage r-   !/usr/lib/python3.7/test_typing.pyassertIsSubclass!   s
    
zBaseTestCase.assertIsSubclassc             C   s8   t ||r4d||f }|d k	r*|d| 7 }| |d S )Nz%r is a subclass of %rz : %s)r&   r'   )r(   r)   r*   r+   r,   r-   r-   r.   assertNotIsSubclass(   s
    
z BaseTestCase.assertNotIsSubclassc             C   s   xt jD ]
}|  qW d S )N)typingZ	_cleanups)r(   fr-   r-   r.   clear_caches/   s    zBaseTestCase.clear_caches)N)N)__name__
__module____qualname__r/   r0   r3   r-   r-   r-   r.   r%      s   

r%   c               @   s   e Zd ZdS )EmployeeN)r4   r5   r6   r-   r-   r-   r.   r7   4   s   r7   c               @   s   e Zd ZdS )ManagerN)r4   r5   r6   r-   r-   r-   r.   r8   8   s   r8   c               @   s   e Zd ZdS )FounderN)r4   r5   r6   r-   r-   r-   r.   r9   <   s   r9   c               @   s   e Zd ZdS )ManagingFounderN)r4   r5   r6   r-   r-   r-   r.   r:   @   s   r:   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   s$   |  t tdt W d Q R X d S )N*   )assertRaises	TypeError
isinstancer	   )r(   r-   r-   r.   test_any_instance_type_errorF   s    z%AnyTests.test_any_instance_type_errorc          	   C   sD   |  t ttt W d Q R X |  t ttt W d Q R X d S )N)r=   r>   r&   r7   r	   )r(   r-   r-   r.   test_any_subclass_type_errorJ   s    z%AnyTests.test_any_subclass_type_errorc             C   s   |  ttd d S )Nz
typing.Any)assertEqualreprr	   )r(   r-   r-   r.   	test_reprP   s    zAnyTests.test_reprc          	   C   sB   |  t tdt W d Q R X |  t tt  W d Q R X d S )Nr<   )r=   r>   r&   r	   int)r(   r-   r-   r.   test_errorsS   s    zAnyTests.test_errorsc          	   C   sT   |  t G dd dt}W d Q R X |  t G dd dtt}W d Q R X d S )Nc               @   s   e Zd ZdS )z(AnyTests.test_cannot_subclass.<locals>.AN)r4   r5   r6   r-   r-   r-   r.   A[   s   rG   c               @   s   e Zd ZdS )z(AnyTests.test_cannot_subclass.<locals>.AN)r4   r5   r6   r-   r-   r-   r.   rG   ^   s   )r=   r>   r	   type)r(   rG   r-   r-   r.   test_cannot_subclassY   s    zAnyTests.test_cannot_subclassc          	   C   s@   |  t t  W d Q R X |  t tt  W d Q R X d S )N)r=   r>   r	   rH   )r(   r-   r-   r.   test_cannot_instantiatea   s    z AnyTests.test_cannot_instantiatec             C   s"   t jt  t jt  t jt  d S )N)r1   r#   r	   r"   r   )r(   r-   r-   r.   test_any_works_with_aliasg   s    

z"AnyTests.test_any_works_with_aliasN)
r4   r5   r6   r@   rA   rD   rF   rI   rJ   rK   r-   r-   r-   r.   r;   D   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 )NoReturnTestsc          	   C   s$   |  t tdt W d Q R X d S )Nr<   )r=   r>   r?   r
   )r(   r-   r-   r.   !test_noreturn_instance_type_errorp   s    z/NoReturnTests.test_noreturn_instance_type_errorc          	   C   sD   |  t ttt W d Q R X |  t ttt W d Q R X d S )N)r=   r>   r&   r7   r
   )r(   r-   r-   r.   !test_noreturn_subclass_type_errort   s    z/NoReturnTests.test_noreturn_subclass_type_errorc             C   s   |  ttd d S )Nztyping.NoReturn)rB   rC   r
   )r(   r-   r-   r.   rD   z   s    zNoReturnTests.test_reprc          	   C   s"   |  t tt  W d Q R X d S )N)r=   r>   r
   rE   )r(   r-   r-   r.   test_not_generic}   s    zNoReturnTests.test_not_genericc          	   C   sT   |  t G dd dt}W d Q R X |  t G dd dtt}W d Q R X d S )Nc               @   s   e Zd ZdS )z-NoReturnTests.test_cannot_subclass.<locals>.AN)r4   r5   r6   r-   r-   r-   r.   rG      s   rG   c               @   s   e Zd ZdS )z-NoReturnTests.test_cannot_subclass.<locals>.AN)r4   r5   r6   r-   r-   r-   r.   rG      s   )r=   r>   r
   rH   )r(   rG   r-   r-   r.   rI      s    z"NoReturnTests.test_cannot_subclassc          	   C   s@   |  t t  W d Q R X |  t tt  W d Q R X d S )N)r=   r>   r
   rH   )r(   r-   r-   r.   rJ      s    z%NoReturnTests.test_cannot_instantiateN)	r4   r5   r6   rM   rN   rD   rO   rI   rJ   r-   r-   r-   r.   rL   n   s   rL   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 )TypeVarTestsc             C   s$   t d}| || | |t  d S )Nr   )r   rB   assertIsInstance)r(   r   r-   r-   r.   test_basic_plain   s    zTypeVarTests.test_basic_plainc          	   C   s,   t d}| t td| W d Q R X d S )Nr   r<   )r   r=   r>   r?   )r(   r   r-   r-   r.    test_typevar_instance_type_error   s    z-TypeVarTests.test_typevar_instance_type_errorc          	   C   sL   t d}| t tt| W d Q R X | t t|t W d Q R X d S )Nr   )r   r=   r>   r&   rE   )r(   r   r-   r-   r.    test_typevar_subclass_type_error   s
    z-TypeVarTests.test_typevar_subclass_type_errorc          	   C   s(   |  t tdt}| W d Q R X d S )NX)r=   r>   r   rE   )r(   rU   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 )NrU   Y)	r   assertNotEqualrB   r   rE   __args____parameters__assertIs
__origin__)r(   rU   rW   r-   r-   r.   test_union_unique   s    zTypeVarTests.test_union_uniquec             C   s(   t dtt}| t|tf t|  d S )NrG   )r   strbytesrX   r   )r(   rG   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)rB   rC   r   r   r   r   r   )r(   ra   rc   r-   r-   r.   rD      s    zTypeVarTests.test_reprc             C   s4   |  tdtd |  tdtttdtt d S )Nr   )rX   r   rE   r^   )r(   r-   r-   r.   test_no_redefinition   s    z!TypeVarTests.test_no_redefinitionc          	   C   s.   |  t G dd dtd}W d Q R X d S )Nc               @   s   e Zd ZdS )z1TypeVarTests.test_cannot_subclass_vars.<locals>.VN)r4   r5   r6   r-   r-   r-   r.   V   s   rf   r   )r=   r>   r   )r(   rf   r-   r-   r.   test_cannot_subclass_vars   s    z&TypeVarTests.test_cannot_subclass_varsc          	   C   s*   |  t G dd dt}W d Q R X d S )Nc               @   s   e Zd ZdS )z7TypeVarTests.test_cannot_subclass_var_itself.<locals>.VN)r4   r5   r6   r-   r-   r-   r.   rf      s   rf   )r=   r>   r   )r(   rf   r-   r-   r.   test_cannot_subclass_var_itself   s    z,TypeVarTests.test_cannot_subclass_var_itselfc          	   C   s$   |  t td  W d Q R X d S )NrG   )r=   r>   r   )r(   r-   r-   r.   test_cannot_instantiate_vars   s    z)TypeVarTests.test_cannot_instantiate_varsc          	   C   sL   |  t tddd W d Q R X |  t tdtttd W d Q R X d S )NrU   r<   )bound)r=   r>   r   r^   floatr7   )r(   r-   r-   r.   test_bound_errors   s    zTypeVarTests.test_bound_errorsc          	   C   s(   |  t tdddd W d Q R X d S )Nr   T)rb   rd   )r=   
ValueErrorr   )r(   r-   r-   r.   test_no_bivariant   s    zTypeVarTests.test_no_bivariantN)r4   r5   r6   rR   rS   rT   rV   r]   r`   rD   re   rg   rh   ri   rl   rn   r-   r-   r-   r.   rP      s   
rP   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 )N)r   rE   rk   rX   )r(   ur-   r-   r.   test_basics   s    zUnionTests.test_basicsc          	   C   s   |  t ttt W d Q R X |  t ttt W d Q R X |  t tttttf  W d Q R X |  t ttttf t W d Q R X d S )N)r=   r>   r&   rE   r   r^   )r(   r-   r-   r.   test_subclass_error   s    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 )N)r   r	   rB   rE   objectrX   )r(   rp   u1u2Z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 )N)r   rs   rB   rE   rX   )r(   rp   rt   ru   r-   r-   r.   test_union_object   s    zUnionTests.test_union_objectc             C   s(   t ttf }t ttf }| || d S )N)r   rE   rk   rB   )r(   rt   ru   r-   r-   r.   test_unordered  s    zUnionTests.test_unorderedc             C   s   t t }| |t d S )N)r   r7   r[   )r(   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 )N)r   r7   r8   rX   assertInrY   )r(   rp   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 )N)r   rE   rk   r7   rB   )r(   rp   vr-   r-   r.   test_union_union  s    zUnionTests.test_union_unionc             C   s   |  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 d S )Nztyping.Unionztyping.Union[%s.Employee, int]ztyping.Union[int, %s.Employee]r   z#typing.Union[typing.List[int], int])rB   rC   r   r7   rE   r4   r   r   )r(   rp   r   r-   r-   r.   rD     s    zUnionTests.test_reprc          	   C   s   |  t G dd dt}W d Q R X |  t G dd dtt}W d Q R X |  t G dd dtttf }W d Q R X d S )Nc               @   s   e Zd ZdS )z*UnionTests.test_cannot_subclass.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   C(  s   r   c               @   s   e Zd ZdS )z*UnionTests.test_cannot_subclass.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r   +  s   c               @   s   e Zd ZdS )z*UnionTests.test_cannot_subclass.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r   .  s   )r=   r>   r   rH   rE   r^   )r(   r   r-   r-   r.   rI   &  s    zUnionTests.test_cannot_subclassc          	   C   s   |  t t  W d Q R X |  t tt  W d Q R X tttf }|  t |  W d Q R X |  t t|  W d Q R X d S )N)r=   r>   r   rH   rE   rk   )r(   rp   r-   r-   r.   rJ   1  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 )N)assertFalser   r^   r1   IterablerE   r{   rY   )r(   r-   r-   r.   test_union_generalization<  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 )N)	rX   r   rs   r	   r   r   r1   Mappingr   )r(   r-   r-   r.   test_union_compare_otherB  s    z#UnionTests.test_union_compare_otherc             C   s$   t t }ttd f }| || d S )N)r   rE   r   rB   )r(   orp   r-   r-   r.   test_optionalK  s    zUnionTests.test_optionalc          	   C   s"   |  t td  W d Q R X d S )Nr-   )r=   r>   r   )r(   r-   r-   r.   
test_emptyP  s    zUnionTests.test_emptyc          	   C   s,   |  t tdtttf  W d Q R X d S )Nr<   )r=   r>   r?   r   rE   r^   )r(   r-   r-   r.   test_union_instance_type_errorT  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 )Nr-   )r   r-   r-   r.   r2   Z      z(UnionTests.test_no_eval_union.<locals>.fr   )r   rE   r^   r[   r   )r(   rp   r2   r-   r-   r.   test_no_eval_unionX  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 )Nr-   r-   r-   r-   r.   fun^  r   z0UnionTests.test_function_repr_union.<locals>.funztyping.Union[fun, int])rE   rB   rC   r   )r(   r   r-   r-   r.   test_function_repr_union]  s    z#UnionTests.test_function_repr_unionc             C   s   t ttf }| d S )N)r   r^   r"   )r(   rG   r-   r-   r.   test_union_str_patterna  s    z!UnionTests.test_union_str_patternc                sV   yddl m  W n tk
r,   tdY nX t tf   fdd}t|tf  d S )Nr   )ElementzcElementTree not foundc                 s    |  S )Nr-   )args)r   r-   r.   Elemo  s    z#UnionTests.test_etree.<locals>.Elem)Zxml.etree.cElementTreer   ImportErrorr   r   r^   )r(   r   r-   )r   r.   
test_etreef  s    zUnionTests.test_etreeN)r4   r5   r6   rq   rr   rv   rw   rx   rz   r|   r~   rD   rI   rJ   r   r   r   r   r   r   r   r   r   r-   r-   r-   r.   ro      s(   
		ro   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 Q R X |  t tttttf  W d Q R X 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>.TPN)r4   r5   r6   r-   r-   r-   r.   TP}  s    r   )r=   r>   r&   r   rE   r^   tuple
assertTrue)r(   r   r-   r-   r.   rq   w  s    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.)rB   r   rE   rX   )r(   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>.MyTupleN)r4   r5   r6   r-   r-   r-   r.   MyTuple  s   r   )r   r   r&   r   )r(   r   r-   r-   r.   test_tuple_subclass  s    zTupleTests.test_tuple_subclassc          	   C   s8   |  t tdtttf  W d Q R X | dt d S )N)r   r   )r=   r>   r?   r   rE   rQ   )r(   r-   r-   r.   test_tuple_instance_type_error  s    z)TupleTests.test_tuple_instance_type_errorc             C   sX   |  ttd |  ttd d |  ttttf d |  tttdf d d S )Nztyping.Tupler-   ztyping.Tuple[()]ztyping.Tuple[int, float].ztyping.Tuple[int, ...])rB   rC   r   rE   rk   )r(   r-   r-   r.   rD     s    zTupleTests.test_reprc          	   C   sH   |  t tdt W d Q R X |  t tdtt  W d Q R X d S )Nr<   )r=   r>   r&   r   rE   )r(   r-   r-   r.   rF     s    zTupleTests.test_errorsN)	r4   r5   r6   rq   r   r   r   rD   rF   r-   r-   r-   r.   r   u  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   sT   |  t( | ttdd ttgtf  W d Q R X | ttdd t d S )Nc             S   s   | S )Nr-   )r   r-   r-   r.   <lambda>  r   z2CallableTests.test_self_subclass.<locals>.<lambda>c             S   s   | S )Nr-   )r   r-   r-   r.   r     r   )r=   r>   r   r&   rH   r   rE   )r(   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   )rB   r   rE   lenrX   r^   )r(   r-   r-   r.   test_eq_hash  s     (  "zCallableTests.test_eq_hashc          	   C   s   |  t t  W d Q R X |  t tt  W d Q R X ttgtf }|  t |  W d Q R X |  t t|  W d Q R X d S )N)r=   r>   r   rH   rE   r^   )r(   cr-   r-   r.   rJ     s    z%CallableTests.test_cannot_instantiatec          	   C   s   |  t tdgtf  W d Q R X |  t tdtf  W d Q R X |  t tdgtf  W d Q R X |  t ttdgdf  W d Q R X |  t tt  W d Q R X d S )N.r-   r      )r=   r>   r   rE   )r(   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 )Nr-   r-   r-   r-   r.   r2     s    z5CallableTests.test_callable_instance_works.<locals>.f)rQ   r   assertNotIsInstance)r(   r2   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 Q R X |  t | |tg tf  W d Q R X |  t | d tg d f  W d Q R X |  t | d tg tf  W d Q R X d S )Nc               S   s   d S )Nr-   r-   r-   r-   r.   r2     s    z:CallableTests.test_callable_instance_type_error.<locals>.f)r=   r>   rQ   r   r	   r   )r(   r2   r-   r-   r.   !test_callable_instance_type_error  s    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 d S )Nztyping.Callable[[], bool]z"typing.Callable[[str, float], int].ztyping.Callable[..., str])r   boolrB   rC   r^   rk   rE   )r(   Zct0Zct2Zctvr-   r-   r.   rD     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 )Nr-   )r   r-   r-   r.   foo  s    z6CallableTests.test_callable_with_ellipsis.<locals>.foor   )r   r   rB   r   globalslocals)r(   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 )N.)r1   r   r   r^   )r(   r-   r-   r.   test_ellipsis_in_generic  s    z&CallableTests.test_ellipsis_in_genericN)r4   r5   r6   r   r   rJ   r   r   r   rD   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 )Nr-   )r(   r   r-   r-   r.   __getitem__  s    zSimpleMapping.__getitem__)r   valuec             C   s   d S )Nr-   )r(   r   r   r-   r-   r.   __setitem__  s    zSimpleMapping.__setitem__N)r   defaultr   c             C   s   d S )Nr-   )r(   r   r   r-   r-   r.   get  s    zSimpleMapping.get)N)r4   r5   r6   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 )N)store)r(   r-   r-   r.   __init__  s    zMySimpleMapping.__init__)r   c             C   s
   | j | S )N)r   )r(   r   r-   r-   r.   r     s    zMySimpleMapping.__getitem__c             C   s   || j |< d S )N)r   )r(   r   r   r-   r-   r.   r     s    zMySimpleMapping.__setitem__Nc             C   s$   y
| j | S  tk
r   |S X d S )N)r   KeyError)r(   r   r   r-   r-   r.   r     s    
zMySimpleMapping.get)N)r4   r5   r6   r   r^   r   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S )ProtocolTestsc             C   s    |  ttj | ttj d S )N)r/   rE   r1   SupportsIntr0   r^   )r(   r-   r-   r.   test_supports_int  s    zProtocolTests.test_supports_intc             C   s    |  ttj | ttj d S )N)r/   rk   r1   ZSupportsFloatr0   r^   )r(   r-   r-   r.   test_supports_float  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-   )r(   r-   r-   r.   __complex__  s    z:ProtocolTests.test_supports_complex.<locals>.C.__complex__N)r4   r5   r6   r   r-   r-   r-   r.   r     s   r   )r/   r1   SupportsComplexr0   r^   )r(   r   r-   r-   r.   test_supports_complex  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-   )r(   r-   r-   r.   	__bytes__&  s    z6ProtocolTests.test_supports_bytes.<locals>.B.__bytes__N)r4   r5   r6   r   r-   r-   r-   r.   B%  s   r   )r/   r1   SupportsBytesr0   r^   )r(   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 )N)r/   rk   r1   SupportsAbsrE   r0   r^   )r(   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 )N)r&   rk   r1   ZSupportsRoundr/   rE   r0   r^   )r(   r-   r-   r.   test_supports_round1  s    z!ProtocolTests.test_supports_roundc             C   s    |  ttj | ttj d S )N)r/   listr1   
Reversibler0   rE   )r(   r-   r-   r.   test_reversible7  s    zProtocolTests.test_reversiblec          	   C   sZ   |  t tdtj W d Q R X 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_protocol_instance_type_error.<locals>.C1)r   c             S   s   dS )Nr<   r-   )r(   r-   r-   r.   __int__?  s    zCProtocolTests.test_protocol_instance_type_error.<locals>.C1.__int__N)r4   r5   r6   rE   r   r-   r-   r-   r.   C1>  s   r   c               @   s   e Zd ZdS )z;ProtocolTests.test_protocol_instance_type_error.<locals>.C2N)r4   r5   r6   r-   r-   r-   r.   C2A  s   r   )r=   r>   r?   r1   r   r   rQ   )r(   r   r   r   r-   r-   r.   !test_protocol_instance_type_error;  s    z/ProtocolTests.test_protocol_instance_type_errorN)r4   r5   r6   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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   s   t ttf }| |jd | t |t  W d Q R X | t |ttf  W d Q R X t ttf }| |jtf |t  | t |ttf  W d Q R X t ttf }| t t	|t  W d Q R X | 
| t  d S )Nr-   )r   r^   r	   rB   rZ   r=   r>   r   rE   r&   rQ   )r(   rU   rW   ZSM1r-   r-   r.   rq   I  s    zGenericTests.test_basicsc          	   C   sv  t d}t d}| t t|   W d Q R X | t t| |  W d Q R X | t t| |  W d Q R X | t  G dd dt| t| }W d Q R X | t tg tt  W d Q R X | t tttt  W d Q R X | t G dd dt}W d Q R X | t  G dd dt| t| }W d Q R X | t  G d	d dt| t| }W d Q R X d S )
Nr   Sc               @   s   e Zd ZdS )z+GenericTests.test_generic_errors.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r   d  s    r   c               @   s   e Zd ZdS )z4GenericTests.test_generic_errors.<locals>.NewGenericN)r4   r5   r6   r-   r-   r-   r.   
NewGenericj  s    r   c               @   s   e Zd ZdS )z3GenericTests.test_generic_errors.<locals>.MyGenericN)r4   r5   r6   r-   r-   r-   r.   	MyGenericl  s    r   c               @   s   e Zd ZdS )z3GenericTests.test_generic_errors.<locals>.MyGenericN)r4   r5   r6   r-   r-   r-   r.   r   n  s    )	r   r=   r>   r   r?   r   rE   r&   r   )r(   r   r   r   r   r   r-   r-   r.   test_generic_errorsZ  s(    $$z GenericTests.test_generic_errorsc          	   C   sZ   t d}t d}| t t||f  W d Q R X | t t|||f  W d Q R X d S )Nr   r   )r   r=   r>   r   )r(   r   r   r-   r-   r.   	test_initp  s    zGenericTests.test_initc          	   C   s   G dd dt jt }G dd d|}| |jd | t |j W d Q R X 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 | d| _d S )Nr<   )super__init_subclass__attr)r)   kwargs)	__class__r-   r.   r   z  s    z<GenericTests.test_init_subclass.<locals>.X.__init_subclass__)r4   r5   r6   r   __classcell__r-   r-   )r   r.   rU   y  s   rU   c               @   s   e Zd ZdS )z*GenericTests.test_init_subclass.<locals>.YN)r4   r5   r6   r-   r-   r-   r.   rW   }  s   rW   r<   r   r   c               @   s   e Zd ZdS )z*GenericTests.test_init_subclass.<locals>.ZN)r4   r5   r6   r-   r-   r-   r.   Z  s   r   c               @   s   e Zd ZdS )z*GenericTests.test_init_subclass.<locals>.WN)r4   r5   r6   r-   r-   r-   r.   W  s   r   )r1   r   r   rB   r   r=   AttributeErrorrE   )r(   rU   rW   r   r   r-   r-   r.   test_init_subclassx  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'>)rB   rC   r   r4   r   )r(   r-   r-   r.   rD     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>.CN)r4   r5   r6   r-   r-   r-   r.   r     s   r   z.C[typing.Tuple[str, int]])	r   r   r   rB   rX   rE   r^   r   endswith)r(   r   r   r   rU   rW   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   UT)rb   r   ztyping.Listztyping.List[~T]ztyping.List[+U]ztyping.List[int])r   rB   rC   r   rE   )r(   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   rB   rC   r1   r   r   r   rE   )r(   r   r   r-   r-   r.   test_new_repr_complex  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>.CN)r4   r5   r6   r-   r-   r-   r.   r     s    r   )	r   rB   rC   r   r1   	_ProtocolDictr	   __mro__)r(   r   r   r-   r-   r.   test_new_repr_bare  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>.BN)r4   r5   r6   r-   r-   r-   r.   r     s   r   r<   r   c               @   s   e Zd ZdS )z!GenericTests.test_dict.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r     s   r   abcbar)r   r   r   rB   __dict__rE   r   )r(   r   r   br   r   r-   r-   r.   	test_dict  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defN)r4   r5   r6   r   r-   r-   r-   r.   r     s   r   r   Zchangednewc               @   s   e Zd ZdS )z<GenericTests.test_subscripted_generics_as_proxies.<locals>.DN)r4   r5   r6   r-   r-   r-   r.   D  s   r   zfrom derived zzfrom derived x)	r   r   rB   rE   r   r^   r   zr   )r(   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>.CN)r4   r5   r6   r-   r-   r-   r.   r     s    r   r   )
r   collectionsr   r   r   registerrE   rQ   _abc_registry_clear_abc_caches_clear)r(   r   r   r-   r-   r.   test_abc_registry_kept  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>.MyMappingN)r4   r5   r6   r-   r-   r-   r.   	MyMapping   s    r   )r   r^   r   r0   dict)r(   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 )Nr-   )r(   kr-   r-   r.   r     s    z3GenericTests.test_abc_bases.<locals>.MM.__getitem__c             S   s   d S )Nr-   )r(   r   r}   r-   r-   r.   r     s    z3GenericTests.test_abc_bases.<locals>.MM.__setitem__c             S   s   d S )Nr-   )r(   r   r-   r-   r.   __delitem__
  s    z3GenericTests.test_abc_bases.<locals>.MM.__delitem__c             S   s   t dS )Nr-   )iter)r(   r-   r-   r.   __iter__  s    z0GenericTests.test_abc_bases.<locals>.MM.__iter__c             S   s   dS )Nr   r-   )r(   r-   r-   r.   __len__  s    z/GenericTests.test_abc_bases.<locals>.MM.__len__N)r4   r5   r6   r   r   r   r  r  r-   r-   r-   r.   MM  s
   r  )r   r^   updaterQ   r   r   r   r   )r(   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>.MM1N)r4   r5   r6   r-   r-   r-   r.   MM1  s   r  c               @   s   e Zd ZdS )z-GenericTests.test_multiple_bases.<locals>.MM2N)r4   r5   r6   r-   r-   r-   r.   MM2  s   r  )r   r^   r   r   rB   	__bases__r   )r(   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>.CN)r4   r5   r6   r-   r-   r-   r.   r      s    r   )r   r1   r   r^   rB   __orig_bases__)r(   r   r   r-   r-   r.   test_orig_bases  s    zGenericTests.test_orig_basesc          	   C   sL  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 Q R X dd }G dd dt	t }|  ||t  |t  | ||t  |t  | ||t  t
 | t |dd	d
g|t  W d Q R X dd }G dd dt
t }|  |dd	d
g| | |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 )N)r?   ).0r   r}   )r   r   r-   r.   	<genexpr>+  s   zSGenericTests.test_naive_runtime_checks.<locals>.naive_dict_check.<locals>.<genexpr>)r   rZ   NotImplementedErrorrY   allitems)objtpr-   )r   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-   r.   naive_generic_check3  s    
zCGenericTests.test_naive_runtime_checks.<locals>.naive_generic_checkc               @   s   e Zd ZdS )z4GenericTests.test_naive_runtime_checks.<locals>.NodeN)r4   r5   r6   r-   r-   r-   r.   Node8  s    r  r      c                s   t  fdd| D S )Nc             3   s$   | ]}t | jd  jd  V  qdS )r   N)r?   r
  rY   )r  r   )r  r-   r.   r  A  s   zXGenericTests.test_naive_runtime_checks.<locals>.naive_list_base_check.<locals>.<genexpr>)r  )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>.CN)r4   r5   r6   r-   r-   r-   r.   r   C  s    r   r   r   )r   r1   r   r^   rE   r   r=   r  r   r   r   )r(   r  r  r  r  r   r-   r-   r.   test_naive_runtime_checks#  s     
"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   rf   c               @   s   e Zd ZdS )z.GenericTests.test_multi_subscr_base.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r   K  s    r   c               @   s   e Zd ZdS )z.GenericTests.test_multi_subscr_base.<locals>.DN)r4   r5   r6   r-   r-   r-   r.   r   L  s    r   r-   )
r   r   rB   rZ   rE   rY   r  r   r   r
  )r(   r   r   rf   r   r   r-   r-   r.   test_multi_subscr_baseG  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>.MetaN)r4   r5   r6   r-   r-   r-   r.   MetaZ  s    r  .)	r   rH   rB   r   r   rE   r   rY   Ellipsis)r(   r   r  r-   r-   r.   test_subscript_metaX  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>.AN)r4   r5   r6   r-   r-   r-   r.   rG   `  s   rG   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.AN)r4   r5   r6   r-   r-   r-   r.   rG   d  s   rG   N)r4   r5   r6   r   r   rG   r-   r-   r-   r.   r   c  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   rB   r$   rG   r^   r   rX   r   r	   rE   r   r   r1   	FrozenSetsysversion_infor   rC   r   )r(   rG   r   r-   r-   r.   test_generic_hashes_  s@    "&&z GenericTests.test_generic_hashesc          	   C   s  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 Q R X | t t||f |df  W d Q R X | 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 Q R X | 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 Q R X | t t
|g|f g tf  W d Q R X d S )
Nr   r   r-   .c               @   s   e Zd ZdS )z9GenericTests.test_extended_generic_rules_eq.<locals>.BaseN)r4   r5   r6   r-   r-   r-   r.   Base  s    r#  c               @   s   e Zd ZdS )z<GenericTests.test_extended_generic_rules_eq.<locals>.DerivedN)r4   r5   r6   r-   r-   r-   r.   Derived  s    r$  r   )r   rB   r   rE   r1   r   r=   r>   r   r^   r   r   r   )r(   r   r   r#  r$  r-   r-   r.   test_extended_generic_rules_eq  s*     ,,($( 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[..., Union[int, NoneType]]zCallable[[], List[int]])
r   rB   rC   r   r   r   replacerE   r   r   )r(   r   r-   r-   r.    test_extended_generic_rules_repr  s    ""z-GenericTests.test_extended_generic_rules_reprc             C   s   t t d  ddd}G dd d}| 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CC)r   c             S   s   d S )Nr-   )r   r-   r-   r.   foobar  r   z5GenericTests.test_generic_forward_ref.<locals>.foobarc               @   s   e Zd ZdS )z1GenericTests.test_generic_forward_ref.<locals>.CCN)r4   r5   r6   r-   r-   r-   r.   r)    s    r   r   .c             S   s   d S )Nr-   )r   r-   r-   r.   barfoo  r   z5GenericTests.test_generic_forward_ref.<locals>.barfooc             S   s   d S )Nr-   )r   r-   r-   r.   barfoo2  r   z6GenericTests.test_generic_forward_ref.<locals>.barfoo2)	r   rB   r   r   r   r   r   r[   r   )r(   r*  r)  r   ATr+  ZCTr,  r-   r-   r.   test_generic_forward_ref  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  W d Q R X | 
t |ttf  W d Q R X | 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 Q R X | 
t tt tdf tj W d Q R X d S )Nc               @   s   e Zd ZdS )z@GenericTests.test_extended_generic_rules_subclassing.<locals>.T1N)r4   r5   r6   r-   r-   r-   r.   T1  s    r/  c               @   s   e Zd ZdS )z@GenericTests.test_extended_generic_rules_subclassing.<locals>.T2N)r4   r5   r6   r-   r-   r-   r.   T2  s    r0  .c               @   s   e Zd ZdS )z@GenericTests.test_extended_generic_rules_subclassing.<locals>.C1N)r4   r5   r6   r-   r-   r-   r.   r     s    r   c               @   s   e Zd Zdd ZdS )z@GenericTests.test_extended_generic_rules_subclassing.<locals>.C2c             S   s   d S )Nr-   )r(   r-   r-   r.   __call__  s    zIGenericTests.test_extended_generic_rules_subclassing.<locals>.C2.__call__N)r4   r5   r6   r1  r-   r-   r-   r.   r     s   r   .zC1[int]r-   )r   r   r   r   rE   rB   rZ   r^   rY   r\   r=   r>   rC   splitrQ   r   r   r/   r   r&   r1   Sequencer   )r(   r/  r0  r   r   r-   r-   r.   'test_extended_generic_rules_subclassing  s.    z4GenericTests.test_extended_generic_rules_subclassingc          	   C   s   |  t tt  W d Q R X |  t tt  W d Q R X |  t tt  W d Q R X |  t ttt   W d Q R X d S )N)r=   r>   r   r   r   r   r   rE   )r(   r-   r-   r.   test_fail_with_bare_union  s    z&GenericTests.test_fail_with_bare_unionc          	   C   sl   t d}| t tt  W d Q R X | t tt|   W d Q R X | t ttj  W d Q R X d S )Nr   )r   r=   r>   r   r   r   r1   r   )r(   r   r-   r-   r.   test_fail_with_bare_generic  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>.MyTupN)r4   r5   r6   r-   r-   r-   r.   MyTup  s    r9  c               @   s   e Zd Zdd ZdS )z6GenericTests.test_type_erasure_special.<locals>.MyCallc             S   s   d S )Nr-   )r(   r-   r-   r.   r1    r   z?GenericTests.test_type_erasure_special.<locals>.MyCall.__call__N)r4   r5   r6   r1  r-   r-   r-   r.   MyCall  s   r:  .c               @   s   e Zd ZdS )z6GenericTests.test_type_erasure_special.<locals>.MyDictN)r4   r5   r6   r-   r-   r-   r.   MyDict  s    r;  c               @   s   e Zd ZdS )z5GenericTests.test_type_erasure_special.<locals>.MyDefN)r4   r5   r6   r-   r-   r-   r.   MyDef  s    r<  )r  r  c               @   s   e Zd ZdS )z7GenericTests.test_type_erasure_special.<locals>.MyChainN)r4   r5   r6   r-   r-   r-   r.   MyChain  s    r=  )r   r3   r   r[   rE   r   r  r   r1   r   DefaultDictr^   r   r!  ChainMap)r(   r   r9  r:  r;  r<  r=  r-   r-   r.   test_type_erasure_special  s$    z&GenericTests.test_type_erasure_specialc             C   s   dd t jD }x|D ]}| t|d | || t|dd rdt|jdkrd| |t j	tf t
|trx*|jD ] }| t|d | || qvW qW d S )Nc             s   s   | ]}t t|V  qd S )N)getattrr1   )r  elr-   r-   r.   r    s    z4GenericTests.test_all_repr_eq_any.<locals>.<genexpr>r&  rZ   r   )r1   __all__rX   rC   rB   rA  r   rZ   r	   rY   r?   rH   r   )r(   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|_x\ttjd D ]J}t	||}t
|}| |jd | |jd | |jddd	 qRW t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}xF|D ]>}x8ttjd D ]&}t	||}t
|}| || qW qW ttjtjtt tjtj tjtttf  g}	xJ|	D ]B}x:ttjd D ](}t	||}t
|}| || qpW q\W d S )Nr   c               @   s   e Zd ZdS )z#GenericTests.test_pickle.<locals>.BN)r4   r5   r6   r-   r-   r-   r.   r     s   r   c               @   s   e Zd ZdS )r   N)r4   r5   r6   r-   r-   r-   r.   r     s   r   r<   r   r   )r   r   .)r   r   rE   r   r   r   rangepickleHIGHEST_PROTOCOLdumpsloadsrB   r   r	   r   r   r   r   r^   r   r_   r1   r>  r  r   r   r   AbstractSet)
r(   r   r   r   protor   r   ZsamplessZmore_samplesr-   r-   r.   test_pickle  s6    

&



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}x2|tg D ]$}| |t| | |t| qW d S )Nr   c               @   s   e Zd ZdS )z1GenericTests.test_copy_and_deepcopy.<locals>.NodeN)r4   r5   r6   r-   r-   r-   r.   r  6  s    r  .)r   r   )r   r   r   rE   r   r   r	   r1   r   r   r^   r   r   r   rB   r   r   )r(   r   r  thingsry   r-   r-   r.   test_copy_and_deepcopy4  s    *$" z#GenericTests.test_copy_and_deepcopyc             C   s   t dat dtdat dttax^tttttj	t
tjttttgD ]<}| t|| | t|| | tt|| q@W t d}t dtd}t dtt}x2|||gD ]$}| t|| | t|| qW d S )Nr   TPB)rj   TPVTLTLBTLV)r   r   rE   rQ  r_   r^   rR  r   r1   r   r   r   r   r	   r   r   r[   r   r   rG  rJ  rI  )r(   rU   rS  rT  rU  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 )N)r   )r(   r   r-   r-   r.   r   W  s    z<GenericTests.test_copy_generic_instances.<locals>.C.__init__)r4   r5   r6   r   r-   )r   r-   r.   r   V  s   r   r<   r   )	r   r   rB   r   r   r   ZassertIsNotrE   r  )r(   r   r   Zcir-   )r   r.   test_copy_generic_instancesT  s&    z(GenericTests.test_copy_generic_instancesc          	   C   sz   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}x |D ]}| t| | qZW d S )Nr   .whatever)r   r	   r   rE   r   r   r   r   r1   r   r^   rer#   r_   r   rB   weakrefref)r(   r   rO  ry   r-   r-   r.   test_weakref_alll  s     
zGenericTests.test_weakref_allc          	   C   s   t d}G dd dt| }| }|t  }d|_d|_| t d|_W d Q R X | t d|_W d Q R X |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)r4   r5   r6   	__slots__r-   r-   r-   r.   r   v  s   r   r   )r   c             S   s   d S )Nr-   )r   r-   r-   r.   r     r   z2GenericTests.test_parameterized_slots.<locals>.foor   )r   r   rE   r]  r=   r   ZtomatorB   r   r   r   r   r   )r(   r   r   r   Zc_intr   r-   r-   r.   test_parameterized_slotst  s    
 z%GenericTests.test_parameterized_slotsc          	   C   st   t d}G dd dt| }| }|t  }d|_d|_| t d|_W d Q R X | t d|_W d Q R X d S )Nr   c               @   s   e Zd ZddiZdS )z5GenericTests.test_parameterized_slots_dict.<locals>.Dbananar<   N)r4   r5   r6   r^  r-   r-   r-   r.   r     s   r   Zyesno)r   r   rE   r`  r=   r   r*  )r(   r   r   dZd_intr-   r-   r.   test_parameterized_slots_dict  s    
z*GenericTests.test_parameterized_slots_dictc          	   C   s:   |  t& tttf }G dd dt| }W d Q R X d S )Nc               @   s   e Zd ZdS )z#GenericTests.test_errors.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r     s   r   )r=   r>   r   r   r	   r   )r(   r   r   r-   r-   r.   rF     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 )z#GenericTests.test_repr_2.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r     s   r   z#GenericTests.test_repr_2.<locals>.Cr2  r3  zC[int]c               @   s   e Zd ZdS )z#GenericTests.test_repr_2.<locals>.YN)r4   r5   r6   r-   r-   r-   r.   rW     s   rW   z#GenericTests.test_repr_2.<locals>.Y)	r   r   rB   r5   r4   r6   rE   rC   r4  )r(   r   rU   rW   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 )N)rB   r   r   rX   r   r   )r(   r-   r-   r.   	test_eq_1  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>.AN)r4   r5   r6   r-   r-   r-   r.   rG     s   rG   c               @   s   e Zd ZdS )z!GenericTests.test_eq_2.<locals>.BN)r4   r5   r6   r-   r-   r-   r.   r     s   r   )r   r   rB   rX   )r(   rG   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>.AN)r4   r5   r6   r-   r-   r-   r.   rG     s   rG   c               @   s   e Zd ZdS )z1GenericTests.test_multiple_inheritance.<locals>.BN)r4   r5   r6   r-   r-   r-   r.   r     s   r   c               @   s   e Zd ZdS )z1GenericTests.test_multiple_inheritance.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r     s   r   )r   r   r   r   rB   rZ   )r(   rG   r   r   r-   r-   r.   test_multiple_inheritance  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>.BN)r4   r5   r6   r-   r-   r-   r.   r     s    r   c               @   s   e Zd ZdS )z9GenericTests.test_multiple_inheritance_special.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r     s    r   )r   r   r   rE   rB   r   r   rs   )r(   r   r   r   r-   r-   r.   !test_multiple_inheritance_special  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 Q R X |  G d	d d|t }W d Q R X d S )
Nc               @   s   e Zd ZdS )zDGenericTests.test_init_subclass_super_called.<locals>.FinalExceptionN)r4   r5   r6   r-   r-   r-   r.   FinalException  s   ri  c                   s&   e Zd Zdd fddZ  ZS )z;GenericTests.test_init_subclass_super_called.<locals>.FinalN)r   c                s<   x(| j D ]}| k	rt| r|qW t jf | d S )N)r  r&   r   r   )r)   r   rD  )Finalri  r   r-   r.   r     s    zMGenericTests.test_init_subclass_super_called.<locals>.Final.__init_subclass__)r4   r5   r6   r   r   r-   )rj  ri  )r   r.   rj    s   rj  c               @   s   e Zd ZdS )z:GenericTests.test_init_subclass_super_called.<locals>.TestN)r4   r5   r6   r-   r-   r-   r.   Test  s   rk  c               @   s   e Zd ZdS )z>GenericTests.test_init_subclass_super_called.<locals>.SubclassN)r4   r5   r6   r-   r-   r-   r.   Subclass  s   rl  c               @   s   e Zd ZdS )z>GenericTests.test_init_subclass_super_called.<locals>.SubclassN)r4   r5   r6   r-   r-   r-   r.   rl    s   )	Exceptionr   r   r=   rE   )r(   rk  rl  r-   )rj  ri  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>.VisitorN)r   c             S   s
   || _ d S )N)r   )r(   r   r-   r-   r.   set  s    z-GenericTests.test_nested.<locals>.Visitor.setc             S   s   | j S )N)r   )r(   r-   r-   r.   r     s    z-GenericTests.test_nested.<locals>.Visitor.get)r   c             S   s   | j S )N)r   )r(   r-   r-   r.   visit  s    z/GenericTests.test_nested.<locals>.Visitor.visit)r4   r5   r6   r   r   ro  r   rp  r-   r-   r-   r.   Visitor  s   rq  c               @   s   e Zd ZedddZdS )z0GenericTests.test_nested.<locals>.IntListVisitor)r   c             S   s   | j | d S )N)r   append)r(   r   r-   r-   r.   rr    s    z7GenericTests.test_nested.<locals>.IntListVisitor.appendN)r4   r5   r6   rE   rr  r-   r-   r-   r.   IntListVisitor  s   rs  r   r<   )	r   r   r1   r   rE   ro  rr  rB   r   )r(   Grq  rf   rs  r   r-   r-   r.   test_nested  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>.NodeNzNode[T])labelleftrightc             S   s   || _ || _|| _d S )N)rv  rw  rx  )r(   rv  rw  rx  r-   r-   r.   r   	  s    z5GenericTests.test_type_erasure.<locals>.Node.__init__)NN)r4   r5   r6   r   r-   )r   r-   r.   r    s    r  )r   c                s~    | }  | } t  | }t|  t|  t|  |j|  |j|  |j|  d S )N)r	   r[   rH   rB   rv  )r   r   r   r   )r  r   r(   r-   r.   r     s    z+GenericTests.test_type_erasure.<locals>.foor<   )r   r   )r(   r   r-   )r  r   r(   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 Q R X | t |t  W d Q R X | t ||  W d Q R X d S )Nr   c               @   s   e Zd ZdS )z)GenericTests.test_implicit_any.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r      s   r   c               @   s   e Zd ZdS )z)GenericTests.test_implicit_any.<locals>.DN)r4   r5   r6   r-   r-   r-   r.   r   #  s   r   r-   )r   r   rB   rZ   r=   rm  rE   r	   )r(   r   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>.AN)r4   r5   r6   r-   r-   r-   r.   rG   1  s   rG   c                   s   e Zd Z fddZ  ZS )z*GenericTests.test_new_with_args.<locals>.Bc                s   t  | }||_|S )N)r   __new__arg)r)   r|  r  )r   r-   r.   r{  5  s    z2GenericTests.test_new_with_args.<locals>.B.__new__)r4   r5   r6   r{  r   r-   r-   )r   r.   r   4  s   r   c               @   s   e Zd ZdS )z*GenericTests.test_new_with_args.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r   <  s   r   r   )r   r   rB   r|  )r(   rG   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 )N)from_ar   r   )r(   r|  )r   r-   r.   r   E  s    z4GenericTests.test_new_with_args2.<locals>.A.__init__)r4   r5   r6   r   r   r-   r-   )r   r.   rG   D  s   rG   c                   s   e Zd Z fddZ  ZS )z+GenericTests.test_new_with_args2.<locals>.Cc                s   || _ t | d S )N)from_cr   r   )r(   r|  )r   r-   r.   r   L  s    z4GenericTests.test_new_with_args2.<locals>.C.__init__)r4   r5   r6   r   r   r-   r-   )r   r.   r   K  s   r   r   )r   r   rB   r~  r  )r(   rG   r   r   r-   r-   r.   test_new_with_args2B  s
    z GenericTests.test_new_with_args2c          	   C   s   G dd dt t }| t |d W d Q R X 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>.AN)r4   r5   r6   r-   r-   r-   r.   rG   W  s   rG   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)r)   r  )r   r-   r.   r{  ^  s    z0GenericTests.test_new_no_args.<locals>.B.__new__)r4   r5   r6   r{  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 )N)r|  )r(   r|  r-   r-   r.   r   f  s    z1GenericTests.test_new_no_args.<locals>.C.__init__c                s   t  | }d|_|S )Nr   )r   r{  r  )r)   r|  r  )r   r-   r.   r{  i  s    z0GenericTests.test_new_no_args.<locals>.C.__new__)r4   r5   r6   r   r{  r   r-   r-   )r   r.   r   e  s   r   r   r   )r   r   r=   r>   rB   r|  r  r  )r(   rG   r   r   r   r-   r-   r.   test_new_no_argsU  s    
zGenericTests.test_new_no_argsN)3r4   r5   r6   rq   r   r   r   rD   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r"  r%  r(  r.  r6  r7  r8  r@  rE  rN  rP  rV  rW  r\  r_  rc  rF   rd  re  rf  rg  rh  rn  ru  ry  rz  r}  r  r  r-   r-   r-   r.   r   G  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   sf   |  t td  W d Q R X |  t tttf  W d Q R X |  t tt t  W d Q R X d S )Nr   )r=   r>   r   rE   r^   )r(   r-   r-   r.   rq   w  s    zClassVarTests.test_basicsc             C   sH   |  ttd tt }|  t|d tt }|  t|dt  d S )Nztyping.ClassVarztyping.ClassVar[int]ztyping.ClassVar[%s.Employee])rB   rC   r   rE   r7   r4   )r(   Zcvr-   r-   r.   rD     s
    zClassVarTests.test_reprc          	   C   s\   |  t G dd dtt}W d Q R X |  t G dd dttt }W d Q R X d S )Nc               @   s   e Zd ZdS )z-ClassVarTests.test_cannot_subclass.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r     s   r   c               @   s   e Zd ZdS )z-ClassVarTests.test_cannot_subclass.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r     s   )r=   r>   rH   r   rE   )r(   r   r-   r-   r.   rI     s    z"ClassVarTests.test_cannot_subclassc          	   C   sh   |  t t  W d Q R X |  t tt  W d Q R X |  t tttt    W d Q R X d S )N)r=   r>   r   rH   r   rE   )r(   r-   r-   r.   test_cannot_init  s    zClassVarTests.test_cannot_initc          	   C   sH   |  t tdtt  W d Q R X |  t ttt W d Q R X d S )Nr   )r=   r>   r?   r   rE   r&   )r(   r-   r-   r.   test_no_isinstance  s    z ClassVarTests.test_no_isinstanceN)r4   r5   r6   rq   rD   rI   r  r  r-   r-   r-   r.   r  u  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 )Nr<   )rB   r   rE   rk   r[   rH   r	   r   r   r^   r   )r(   r-   r-   r.   rq     s    zCastTests.test_basicsc             C   s   t dd t dd d S )Nr<   Zhello)r   )r(   r-   r-   r.   rF     s    
zCastTests.test_errorsN)r4   r5   r6   rq   rF   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 )*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)rv  c             S   s   || _ d  | _| _d S )N)rv  rw  rx  )r(   rv  r-   r-   r.   r     s    z2ForwardRefTests.test_basics.<locals>.Node.__init__NzOptional[Node[T]]zNode[T])rw  rx  stuffc             S   s   || _ || _d S )N)rw  rx  )r(   rw  rx  r  blahr-   r-   r.   add_both  s    z2ForwardRefTests.test_basics.<locals>.Node.add_both)nodec             S   s   |  |d  d S )N)r  )r(   r  r-   r-   r.   add_left  s    z2ForwardRefTests.test_basics.<locals>.Node.add_leftc             S   s   |  d | d S )N)r  )r(   r  r-   r-   r.   	add_right  s    z3ForwardRefTests.test_basics.<locals>.Node.add_right)NNN)N)
r4   r5   r6   r   r   rE   r  r   r  r  r-   r-   r-   r.   r    s     r  rw  rx  r  r  r  )r   r   rE   r   r  r   r   rB   r   assertNotInr  r  )r(   r  ry   Z
both_hintsZ
left_hintsZright_hintsr-   r-   r.   rq     s    zForwardRefTests.test_basicsc          	   C   s.   t d}| t td| W d Q R X d S )NrE   r<   )r1   
ForwardRefr=   r>   r?   )r(   frr-   r-   r.   #test_forwardref_instance_type_error  s    
z3ForwardRefTests.test_forwardref_instance_type_errorc          	   C   s.   t d}| t tt| W d Q R X d S )NrE   )r1   r  r=   r>   r&   rE   )r(   r  r-   r-   r.   #test_forwardref_subclass_type_error  s    
z3ForwardRefTests.test_forwardref_subclass_type_errorc             C   s4   t d}| |t d | td tt  d S )NrE   )r1   r  rB   rX   r   rE   )r(   r  r-   r-   r.   test_forward_equality  s    
z%ForwardRefTests.test_forward_equalityc             C   s   |  ttd d d S )NrE   ztyping.List[ForwardRef('int')])rB   rC   r   )r(   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 )Nr-   )r   r-   r-   r.   r     s    z/ForwardRefTests.test_union_forward.<locals>.foor   )r   rB   r   r   r   r   )r(   r   r-   r-   r.   test_union_forward  s    z"ForwardRefTests.test_union_forwardc             C   s6   t d ddd}| t|t t dt t i d S )Nr   )r   c             S   s   d S )Nr-   )r   r-   r-   r.   r     s    z/ForwardRefTests.test_tuple_forward.<locals>.foor   )r   rB   r   r   r   r   )r(   r   r-   r-   r.   test_tuple_forward  s    z"ForwardRefTests.test_tuple_forwardc             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 )Nr-   )r   r-   r-   r.   r     s    z2ForwardRefTests.test_callable_forward.<locals>.foor   )r   rB   r   r   r   r   )r(   r   r-   r-   r.   test_callable_forward  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 )Nr-   )r   r-   r-   r.   r     s    z@ForwardRefTests.test_callable_with_ellipsis_forward.<locals>.foor   .)rB   r   r   r   r   r   )r(   r   r-   r-   r.   #test_callable_with_ellipsis_forward  s    z3ForwardRefTests.test_callable_with_ellipsis_forwardc          	   C   s"   |  t td  W d Q R X d S )Nz/T)r=   SyntaxErrorr   )r(   r-   r-   r.   test_syntax_error  s    z!ForwardRefTests.test_syntax_errorc          	   C   s0   dddd}|  t t| W d Q R X d S )NzNode[T)r   c             S   s   d S )Nr-   )r   r-   r-   r.   r     s    z6ForwardRefTests.test_delayed_syntax_error.<locals>.foo)r=   r  r   )r(   r   r-   r-   r.   test_delayed_syntax_error  s    z)ForwardRefTests.test_delayed_syntax_errorc          	   C   s4   t d ddd}| t t| W d Q R X d S )NZ42)r   c             S   s   d S )Nr-   )r   r-   r-   r.   r     s    z,ForwardRefTests.test_type_error.<locals>.foo)r   r=   r>   r   )r(   r   r-   r-   r.   test_type_error  s    zForwardRefTests.test_type_errorc          	   C   s4   dddd}|  t t|t  W d Q R X d S )NzNoode[T])r   c             S   s   d S )Nr-   )r   r-   r-   r.   r     s    z,ForwardRefTests.test_name_error.<locals>.foo)r=   	NameErrorr   r   )r(   r   r-   r-   r.   test_name_error  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 )Nr-   )r   r-   r-   r.   r   &  s    z/ForwardRefTests.test_no_type_check.<locals>.foo)r   r   rB   )r(   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   r   c             S   s   d S )Nr-   )r   r-   r-   r.   r   1  s    z7ForwardRefTests.test_no_type_check_class.<locals>.C.fooN)r4   r5   r6   r   r-   r-   r-   r.   r   /  s   r   )r   r   r   rB   )r(   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>.C)r   c             S   s   d S )Nr-   )r(   r   r-   r-   r.   meth;  r   z;ForwardRefTests.test_no_type_check_no_bases.<locals>.C.methN)r4   r5   r6   rE   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)r4   r5   r6   r   r-   )r   r-   r.   r   <  s   r   r   )r   rB   r   r  rE   )r(   r   r-   )r   r.   test_no_type_check_no_bases9  s    z+ForwardRefTests.test_no_type_check_no_basesc             C   sp   G dd d}G dd d}G dd d}G dd d}d	t jt i}x$||||gD ]}| t|| qTW d 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)r4   r5   r6   r   r1   r   rE   __annotations__r-   r-   r-   r.   r   C  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)r4   r5   r6   r   r   rE   r  r-   r-   r-   r.   r   E  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  ztyping.ClassVar[int]r   N)r4   r5   r6   r   r  r-   r-   r-   r.   EG  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>.Fr  zClassVar[int]r   N)r4   r5   r6   r   r  r-   r-   r-   r.   FI  s   
r  r   )r1   r   rE   rB   r   )r(   r   r   r  r  Zexpected_resultclazzr-   r-   r.   (test_no_type_check_forward_ref_as_stringB  s    z8ForwardRefTests.test_no_type_check_forward_ref_as_stringc          
   C   sP   G dd d}G dd d}x.||gD ]"}|  t t| W d Q R X q&W 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   N)r4   r5   r6   r   r  r-   r-   r-   r.   r  Q  s   
r  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  zClassVar[int]r   N)r4   r5   r6   r   r   r  r-   r-   r-   r.   r  S  s   
r  )r=   r>   r   )r(   r  r  r  r-   r-   r.   ,test_nested_classvar_fails_forward_ref_checkP  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 )Nr-   )funcr-   r-   r.   magic_decorator\  s    z@ForwardRefTests.test_meta_no_type_check.<locals>.magic_decoratorr  r  )r   r   c             S   s   d S )Nr-   )r   r-   r-   r.   r   b  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   r   c             S   s   d S )Nr-   )r   r-   r-   r.   r   h  s    z6ForwardRefTests.test_meta_no_type_check.<locals>.C.fooN)r4   r5   r6   r   r-   r-   r-   r.   r   f  s   r   r   )r   rB   r4   r   r   )r(   r  r   r   r  r  r  r-   r-   r.   test_meta_no_type_checkZ  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   )execr   r   rB   )r(   codensZhintsr-   r-   r.   test_default_globalss  s
    
z$ForwardRefTests.test_default_globalsN)r4   r5   r6   rq   r  r  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 )OverloadTestsc          	   C   s8   ddl m} | t |dd }|  W d Q R X d S )Nr   )overloadc               S   s   d S )Nr-   r-   r-   r-   r.   r    s    z/OverloadTests.test_overload_fails.<locals>.blah)r1   r  r=   RuntimeError)r(   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 )Nr-   r-   r-   r-   r.   r    s    z2OverloadTests.test_overload_succeeds.<locals>.blahc               S   s   d S )Nr-   r-   r-   r-   r.   r    s    )r1   r  )r(   r  r  r-   r-   r.   test_overload_succeeds  s    z$OverloadTests.test_overload_succeedsN)r4   r5   r6   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

    @asyncio.coroutine
    def __anext__(self) -> T_a:
        data = yield from 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)AsyncContextManagerc               @   s   e Zd ZU eed< dS )rG   yN)r4   r5   r6   rk   r  r-   r-   r-   r.   rG     s   
rG   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   )r4   r5   r6   r   r   r   r  rE   r-   r-   r-   r.   r     s   
r   c               @   s    e Zd ZU e Zed  ed< dS )CSubr   N)r4   r5   r6   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 )rt  lstN)r4   r5   r6   r  r   r   r   r  r-   r-   r-   r.   rt    s   
rt  c               @   s   e Zd ZU d ed< ded< dS )NoneAndForwardparentNmeaning)r4   r5   r6   r  r-   r-   r-   r.   r    s   
r  c               @   s   e Zd ZU eed< eed< dS )CoolEmployeenamecoolN)r4   r5   r6   r^   r  rE   r-   r-   r-   r.   r    s   
r  c               @   s"   e Zd ZU eed< dZeed< dS )CoolEmployeeWithDefaultr  r   r  N)r4   r5   r6   r^   r  r  rE   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   )r(   r-   r-   r.   double  s    zXMeth.doubleN)r4   r5   r6   rE   r  r  r-   r-   r-   r.   r    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   r  )r(   r-   r-   r.   __str__  s    zXRepr.__str__c             C   s   dS )Nr   r-   )r(   otherr-   r-   r.   __add__  s    zXRepr.__add__N)r4   r5   r6   rE   r  r  r  r  r-   r-   r-   r.   r    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_aN)r4   r5   r6   r  r-   r-   r-   r.   r    s   
r  )amc          
      s"   | 4 I d H }|S Q I d H R X d S )Nr-   )r  r   r-   r-   r.   g_with  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S )GetTypeHintTestsc          	   C   s^   |  t td W d Q R X |  t td W d Q R X |  t td  W d Q R X d S )N{   r   )r=   r>   gth)r(   r-   r-   r.   (test_get_type_hints_from_various_objects   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   r2   r   r  )r   rE   r^   rB   r  r  r  r  )r(   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   r$   rG   r   rB   r  )r(   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  r  Zsome_b)Zmy_inner_a1Zmy_inner_a2Z
my_outer_a)rB   r  r  r   r   rQ   Zj_classr   MrH   r   r^   rW   rE   Zh_classr   r   r  r  r  r$   rG   r   r{  )r(   r-   r-   r.   test_get_type_hints_classes  s,    

z,GetTypeHintTests.test_get_type_hints_classesc             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 type)r   c             S   s   d S )Nr-   )r(   r   r-   r-   r.   r   4  r   zKGetTypeHintTests.test_respect_no_type_check.<locals>.NoTpCheck.Inn.__init__N)r4   r5   r6   r   r-   r-   r-   r.   Inn3  s   r  N)r4   r5   r6   r  r-   r-   r-   r.   	NoTpCheck1  s   r  c               @   s   e Zd ZedddZdS )z:GetTypeHintTests.test_respect_no_type_check.<locals>.ABase)r   c             S   s   d S )Nr-   )r   r-   r-   r.   r  9  r   z?GetTypeHintTests.test_respect_no_type_check.<locals>.ABase.methN)r4   r5   r6   rE   r  r-   r-   r-   r.   ABase8  s   r  c               @   s   e Zd ZdS )z8GetTypeHintTests.test_respect_no_type_check.<locals>.DerN)r4   r5   r6   r-   r-   r-   r.   Der:  s   r  r   )r   r   Z__no_type_check__r  r   rB   r  r  ZNTCr  r   r   rE   )r(   r  r  r  r-   r-   r.   test_respect_no_type_check0  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 )N)
rB   r  rE   rH   dirr   rs   r  r^   join)r(   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 )Nr-   )r   r  r-   r-   r.   testfI  r   z6GetTypeHintTests.test_previous_behavior.<locals>.testfrE   r   )r   c             S   s   d S )Nr-   )r   r-   r-   r.   testgL  r   z6GetTypeHintTests.test_previous_behavior.<locals>.testg)r  rB   r  rE   rH   )r(   r  r  r-   r-   r.   test_previous_behaviorH  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>.AN)r4   r5   r6   r-   r-   r-   r.   rG   P  s    rG   c               @   s   e Zd ZdS )zKGetTypeHintTests.test_get_type_hints_for_object_with_annotations.<locals>.BN)r4   r5   r6   r-   r-   r-   r.   r   Q  s    r   r   )r  rB   r  r   )r(   rG   r   r   r-   r-   r.   /test_get_type_hints_for_object_with_annotationsO  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  )rB   r  r  ZCVr   r1   r   r   r   rE   r   r  rt  r   r   )r(   r-   r-   r.   test_get_type_hints_ClassVarV  s    
z-GetTypeHintTests.test_get_type_hints_ClassVarN)r4   r5   r6   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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#ee$j%d@kdAdBdC Z&ee$j%d@kdAdDdE Z'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 Z8dhS )iCollectionsAbcTestsc             C   s    |  dtj | g tj d S )Nr<   )rQ   r1   Hashabler   )r(   r-   r-   r.   test_hashablec  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 )Nr<   )rQ   r1   r   r   r/   r   )r(   r-   r-   r.   test_iterableg  s    z!CollectionsAbcTests.test_iterablec             C   s(   t g }| |tj | dtj d S )Nr<   )r   rQ   r1   Iteratorr   )r(   itr-   r-   r.   test_iteratorr  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   rQ   r1   	Awaitabler   send)r(   r  r   gr-   r-   r.   test_awaitablew  s    
z"CollectionsAbcTests.test_awaitablec          	   C   s   i }t dt | |d }| }| |tj | t t|tjt  W d Q R X | 	|tj y|
d  W n tk
r   Y nX d S )Nzasync def foo():
    return
r   )r  r   rQ   r1   	Coroutiner=   r>   r?   rE   r   r  StopIteration)r(   r  r   r  r-   r-   r.   test_coroutine  s    
z"CollectionsAbcTests.test_coroutinec             C   s>   t d}t|}| |tj | |tj | dtj d S )N
   r<   )rF  AsyncIteratorWrapperrQ   r1   AsyncIterabler   )r(   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 )Nr  r<   )rF  r  rQ   r1   AsyncIteratorr   )r(   r  r  r-   r-   r.   test_async_iterator  s    z'CollectionsAbcTests.test_async_iteratorc             C   s    |  g tj | dtj d S )Nr<   )rQ   r1   Sizedr   )r(   r-   r-   r.   
test_sized  s    zCollectionsAbcTests.test_sizedc             C   s    |  g tj | dtj d S )Nr<   )rQ   r1   	Containerr   )r(   r-   r-   r.   test_container  s    z"CollectionsAbcTests.test_containerc             C   sJ   t tdrF| t tj | t tj | ttj | dtj d S )N
Collectionr<   )	r  r1   rQ   r   r  	frozensetr/   r   r   )r(   r-   r-   r.   test_collection  s
    
z#CollectionsAbcTests.test_collectionc             C   s"   |  t tj | dtj d S )Nr<   )rQ   ro  r1   rK  r   )r(   r-   r-   r.   test_abstractset  s    z$CollectionsAbcTests.test_abstractsetc             C   s$   |  t tj | t tj d S )N)rQ   ro  r1   
MutableSetr   r  )r(   r-   r-   r.   test_mutableset  s    z#CollectionsAbcTests.test_mutablesetc             C   s    |  i tj | dtj d S )Nr<   )rQ   r1   r   r   )r(   r-   r-   r.   test_mapping  s    z CollectionsAbcTests.test_mappingc             C   s    |  i tj | dtj d S )Nr<   )rQ   r1   r   r   )r(   r-   r-   r.   test_mutablemapping  s    z'CollectionsAbcTests.test_mutablemappingc             C   s    |  g tj | dtj d S )Nr<   )rQ   r1   r5  r   )r(   r-   r-   r.   test_sequence  s    z!CollectionsAbcTests.test_sequencec             C   s    |  g tj | dtj d S )Nr-   )rQ   r1   MutableSequencer   )r(   r-   r-   r.   test_mutablesequence  s    z(CollectionsAbcTests.test_mutablesequencec             C   s$   |  dtj |  tdtj d S )Nr   )rQ   r1   
ByteString	bytearray)r(   r-   r-   r.   test_bytestring  s    z#CollectionsAbcTests.test_bytestringc             C   s   |  ttj d S )N)r/   r   r1   r   )r(   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>.MyDequeN)r4   r5   r6   r-   r-   r-   r.   MyDeque  s    r  )r/   r   dequer1   DequerE   rQ   )r(   r  r-   r-   r.   
test_deque  s    zCollectionsAbcTests.test_dequec             C   s   |  tjtj d S )N)r/   r   Counterr1   )r(   r-   r-   r.   test_counter  s    z CollectionsAbcTests.test_counterc             C   s    |  ttj | ttj d S )N)r/   ro  r1   Setr0   r  )r(   r-   r-   r.   test_set  s    zCollectionsAbcTests.test_setc             C   s    |  ttj | ttj d S )N)r/   r  r1   r  r0   ro  )r(   r-   r-   r.   test_frozenset  s    z"CollectionsAbcTests.test_frozensetc             C   s   |  ttj d S )N)r/   r   r1   r   )r(   r-   r-   r.   r     s    zCollectionsAbcTests.test_dictc          	   C   sf   |  t t  W d Q R X |  t tjt   W d Q R X |  t tjt   W d Q R X d S )N)r=   r>   r1   r   r   rE   )r(   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>.MyListN)r4   r5   r6   r-   r-   r-   r.   MyList  s   r  )r1   r   rE   rQ   r5  r/   r   r0   )r(   r  r   r-   r-   r.   test_list_subclass  s    z&CollectionsAbcTests.test_list_subclassc          	   C   sn   |  t t  W d Q R X |  t tjttf   W d Q R X |  t tjttf   W d Q R X d S )N)r=   r>   r1   r   r   r   r^   rE   )r(   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>.MyDictN)r4   r5   r6   r-   r-   r-   r.   r;    s   r;  )	r1   r   r^   rE   rQ   r   r/   r   r0   )r(   r;  rb  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 )N)
r[   rH   r1   r>  r   defaultdictr   r   r^   rE   )r(   r-   r-   r.   test_defaultdict_instantiation  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>.MyDefDictN)r4   r5   r6   r-   r-   r-   r.   	MyDefDict  s   r"  )	r1   r>  r^   rE   rQ   r/   r   r   r0   )r(   r"  ddr-   r-   r.   test_defaultdict_subclass  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 )N)	r[   rH   r1   OrderedDictr   r   r   r^   rE   )r(   r-   r-   r.   test_ordereddict_instantiation  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>.MyOrdDictN)r4   r5   r6   r-   r-   r-   r.   	MyOrdDict%  s   r'  )r1   r%  r^   rE   rQ   r/   r   r0   )r(   r'  Zodr-   r-   r.   test_ordereddict_subclass#  s
    z-CollectionsAbcTests.test_ordereddict_subclass)r  r  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>.CMN)r4   r5   r6   r-   r-   r-   r.   CM3  s    r)  )	r[   rH   r1   r?  r   r   r   r^   rE   )r(   r)  r-   r-   r.   test_chainmap_instantiation.  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>.MyChainMapN)r4   r5   r6   r-   r-   r-   r.   
MyChainMap9  s   r+  )r1   r?  r^   rE   rQ   r/   r   r0   )r(   r+  cmr-   r-   r.   test_chainmap_subclass6  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>.DN)r4   r5   r6   r-   r-   r-   r.   r   F  s    r   )r[   rH   r1   r  r   r  r   rE   )r(   r   r-   r-   r.   test_deque_instantiationB  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>.CN)r4   r5   r6   r-   r-   r-   r.   r   M  s    r   )r[   rH   r1   r  r   r   rE   )r(   r   r-   r-   r.   test_counter_instantiationI  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>.MyCounterN)r4   r5   r6   r-   r-   r-   r.   	MyCounterR  s   r0  )r1   r  rE   rQ   r   )r(   r0  rb  r-   r-   r.   #test_counter_subclass_instantiationP  s
    z7CollectionsAbcTests.test_counter_subclass_instantiationc          	   C   sf   |  t t  W d Q R X |  t tjt   W d Q R X |  t tjt   W d Q R X d S )N)r=   r>   r1   r  r   rE   )r(   r-   r-   r.   test_no_set_instantiationZ  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>.MySetN)r4   r5   r6   r-   r-   r-   r.   MySetd  s   r3  )r1   r  rE   rQ   )r(   r3  rb  r-   r-   r.   test_set_subclass_instantiationb  s    z3CollectionsAbcTests.test_set_subclass_instantiationc          	   C   sf   |  t t  W d Q R X |  t tjt   W d Q R X |  t tjt   W d Q R X d S )N)r=   r>   r1   r  r   rE   )r(   r-   r-   r.   test_no_frozenset_instantiationj  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>.MyFrozenSetN)r4   r5   r6   r-   r-   r-   r.   MyFrozenSett  s   r6  )r1   r  rE   rQ   )r(   r6  rb  r-   r-   r.   %test_frozenset_subclass_instantiationr  s    z9CollectionsAbcTests.test_frozenset_subclass_instantiationc          	   C   s`   |  t t  W d Q R X |  t tt   W d Q R X |  t tt   W d Q R X d S )N)r=   r>   r   r   rE   )r(   r-   r-   r.   test_no_tuple_instantiationz  s    z/CollectionsAbcTests.test_no_tuple_instantiationc             C   s$   dd }| }|  t|tj d S )Nc               s   s
   dV  d S )Nr<   r-   r-   r-   r-   r.   r     s    z/CollectionsAbcTests.test_generator.<locals>.foo)r/   rH   r1   	Generator)r(   r   r  r-   r-   r.   test_generator  s    z"CollectionsAbcTests.test_generatorc          	   C   sr   |  t t  W d Q R X |  t tjtttf   W d Q R X |  t tjtttf   W d Q R X d S )N)r=   r>   r1   r9  r   rE   )r(   r-   r-   r.   test_no_generator_instantiation  s    z3CollectionsAbcTests.test_no_generator_instantiationc             C   s2   i }t dt | |d  }| t|tj d S )Nzasync def f():
    yield 42
r2   )r  r   r/   rH   r1   AsyncGenerator)r(   r  r  r-   r-   r.   test_async_generator  s
    

z(CollectionsAbcTests.test_async_generatorc          	   C   sn   |  t t  W d Q R X |  t tjttf   W d Q R X |  t tjttf   W d Q R X d S )N)r=   r>   r1   r<  r   rE   )r(   r-   r-   r.   %test_no_async_generator_instantiation  s    z9CollectionsAbcTests.test_no_async_generator_instantiationc          	   C   s,  G dd dt j}| t |  W d Q R X 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 Q R X | || 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>.MMAN)r4   r5   r6   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 )Nr-   )r(   r   r-   r-   r.   r     s    z=CollectionsAbcTests.test_subclassing.<locals>.MMC.__getitem__c             S   s   d S )Nr-   )r(   r   r}   r-   r-   r.   r     s    z=CollectionsAbcTests.test_subclassing.<locals>.MMC.__setitem__c             S   s   d S )Nr-   )r(   r   r-   r-   r.   r     s    z=CollectionsAbcTests.test_subclassing.<locals>.MMC.__delitem__c             S   s   t dS )Nr-   )r   )r(   r-   r-   r.   r    s    z:CollectionsAbcTests.test_subclassing.<locals>.MMC.__iter__c             S   s   dS )Nr   r-   )r(   r-   r-   r.   r    s    z9CollectionsAbcTests.test_subclassing.<locals>.MMC.__len__N)r4   r5   r6   r   r   r   r  r  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 )Nr-   )r(   r   r-   r-   r.   r     s    z=CollectionsAbcTests.test_subclassing.<locals>.MMB.__getitem__c             S   s   d S )Nr-   )r(   r   r}   r-   r-   r.   r     s    z=CollectionsAbcTests.test_subclassing.<locals>.MMB.__setitem__c             S   s   d S )Nr-   )r(   r   r-   r-   r.   r     s    z=CollectionsAbcTests.test_subclassing.<locals>.MMB.__delitem__c             S   s   t dS )Nr-   )r   )r(   r-   r-   r.   r    s    z:CollectionsAbcTests.test_subclassing.<locals>.MMB.__iter__c             S   s   dS )Nr   r-   )r(   r-   r-   r.   r    s    z9CollectionsAbcTests.test_subclassing.<locals>.MMB.__len__N)r4   r5   r6   r   r   r   r  r  r-   r-   r-   r.   MMB  s
   rA  c               @   s   e Zd ZdS )z/CollectionsAbcTests.test_subclassing.<locals>.IN)r4   r5   r6   r-   r-   r-   r.   I  s    rB  c               @   s   e Zd ZdS )z/CollectionsAbcTests.test_subclassing.<locals>.GN)r4   r5   r6   r-   r-   r-   r.   rt    s    rt  c               s   s
   dV  d S )Nr   r-   r-   r-   r-   r.   r    r   z/CollectionsAbcTests.test_subclassing.<locals>.g)r1   r   r=   r>   rB   r   rQ   r   r   r   r^   r0   r   r/   r   r   r&   r   r   r9  rE   rH   )r(   r?  r@  rA  rB  rt  r  r-   r-   r.   test_subclassing  s@    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 )Nr-   )r(   r   r-   r-   r.   asend  s    zECollectionsAbcTests.test_subclassing_async_generator.<locals>.G.asendNc             S   s   d S )Nr-   )r(   typvaltbr-   r-   r.   athrow  s    zFCollectionsAbcTests.test_subclassing_async_generator.<locals>.G.athrow)NN)r4   r5   r6   rD  rH  r-   r-   r-   r.   rt    s   rt  zasync def g(): yield 0r  )r1   r<  rE   r  r   r/   r  r   r   r0   rH   rQ   r   )r(   rt  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 )NFooTF)r4   )r)   r  r-   r-   r.   __subclasshook__  s    
zPCollectionsAbcTests.test_subclassing_subclasshook.<locals>.Base.__subclasshook__N)r4   r5   r6   classmethodrL  r-   r-   r-   r.   r#    s   r#  c               @   s   e Zd ZdS )z<CollectionsAbcTests.test_subclassing_subclasshook.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r   	  s    r   c               @   s   e Zd ZdS )z>CollectionsAbcTests.test_subclassing_subclasshook.<locals>.FooN)r4   r5   r6   r-   r-   r-   r.   rK  	  s    rK  c               @   s   e Zd ZdS )z>CollectionsAbcTests.test_subclassing_subclasshook.<locals>.BarN)r4   r5   r6   r-   r-   r-   r.   Bar	  s    rN  )r1   r   r/   r0   )r(   r#  r   rK  rN  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>.AN)r4   r5   r6   r-   r-   r-   r.   rG   	  s    rG   c               @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.BN)r4   r5   r6   r-   r-   r-   r.   r   	  s    r   c               @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.CN)r4   r5   r6   r-   r-   r-   r.   r   	  s    r   c               @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.DN)r4   r5   r6   r-   r-   r-   r.   r   	  s    r   c               @   s   e Zd ZdS )z8CollectionsAbcTests.test_subclassing_register.<locals>.MN)r4   r5   r6   r-   r-   r-   r.   r  	  s    r  )	r1   r  r   r/   r0   r   r   r   r   )r(   rG   r   r   r   r  r-   r-   r.   test_subclassing_register	  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>.MN)r4   r5   r6   r-   r-   r-   r.   r  "	  s    r  c               @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.SN)r4   r5   r6   r-   r-   r-   r.   r   &	  s    r   c               @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.IN)r4   r5   r6   r-   r-   r-   r.   rB  *	  s    rB  c               @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.AN)r4   r5   r6   r-   r-   r-   r.   rG   -	  s    rG   )	metaclassc               @   s   e Zd ZdS )z7CollectionsAbcTests.test_collections_as_base.<locals>.BN)r4   r5   r6   r-   r-   r-   r.   r   .	  s    r   )	r   r   r   r/   r1   r   r  ABCMetar   )r(   r  r   rB  rG   r   r-   r-   r.   test_collections_as_base 	  s    
z,CollectionsAbcTests.test_collections_as_baseN)9r4   r5   r6   r  r  r  r   ASYNCIOr  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/  r1  r2  r4  r5  r7  r8  r:  r;  r=  r>  rC  rJ  rO  rP  rS  r-   r-   r-   r.   r  a  sd   
Er  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 )Nr<   r-   r-   r-   r-   r.   manager6	  s    z2OtherABCTests.test_contextmanager.<locals>.managerr<   )
contextlibcontextmanagerrQ   r1   ContextManagerr   )r(   rV  r,  r-   r-   r.   test_contextmanager5	  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 Q R X | 
t tjttf  W d Q R X d S )Nc               @   s   e Zd ZdS )z7OtherABCTests.test_async_contextmanager.<locals>.NotACMN)r4   r5   r6   r-   r-   r-   r.   NotACM@	  s   r[  c               s   s
   dV  d S )Nr<   r-   r-   r-   r-   r.   rV  D	  s    z8OtherABCTests.test_async_contextmanager.<locals>.managerr<   )rQ   ACMr1   r  r   rW  rX  rB   rE   rY   r=   r>   r?   r^   )r(   r[  rV  r,  r-   r-   r.   test_async_contextmanager>	  s    z'OtherABCTests.test_async_contextmanagerN)r4   r5   r6   rZ  r   rT  r]  r-   r-   r-   r.   rU  3	  s   	rU  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>.UserN)r4   r5   r6   r-   r-   r-   r.   UserU	  s    r_  c               @   s   e Zd ZdS )z,TypeTests.test_type_basic.<locals>.BasicUserN)r4   r5   r6   r-   r-   r-   r.   	BasicUserV	  s    r`  c               @   s   e Zd ZdS )z*TypeTests.test_type_basic.<locals>.ProUserN)r4   r5   r6   r-   r-   r-   r.   ProUserW	  s    ra  )
user_classr   c             S   s   |  S )Nr-   )rb  r-   r-   r.   new_userY	  s    z+TypeTests.test_type_basic.<locals>.new_user)r   )r(   r_  r`  ra  rc  r-   r-   r.   test_type_basicS	  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>.UserN)r4   r5   r6   r-   r-   r-   r.   r_  `	  s    r_  c               @   s   e Zd ZdS )z.TypeTests.test_type_typevar.<locals>.BasicUserN)r4   r5   r6   r-   r-   r-   r.   r`  a	  s    r`  c               @   s   e Zd ZdS )z,TypeTests.test_type_typevar.<locals>.ProUserN)r4   r5   r6   r-   r-   r-   r.   ra  b	  s    ra  r   )rj   )rb  r   c             S   s   |  S )Nr-   )rb  r-   r-   r.   rc  f	  s    z-TypeTests.test_type_typevar.<locals>.new_user)r   r   )r(   r_  r`  ra  r   rc  r-   r-   r.   test_type_typevar^	  s    zTypeTests.test_type_typevarc             C   s$   t tt  }|t t ddd}d S )N)r   r   c             S   s   | d krd S |  S d S )Nr-   )r   r-   r-   r.   r   n	  s    z)TypeTests.test_type_optional.<locals>.foo)r   r   BaseException)r(   rG   r   r-   r-   r.   test_type_optionalk	  s    zTypeTests.test_type_optionalN)r4   r5   r6   rd  re  rg  r-   r-   r-   r.   r^  Q	  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UserName   Joer      )r   rE   r^   rQ   rB   )r(   ri  rj  r-   r-   r.   
test_basicz	  s
    

zNewTypeTests.test_basicc          	   C   s^   t dt}t dt}| t t|t W d Q R X | t G dd d|}W d Q R X d S )Nri  rj  c               @   s   e Zd ZdS )z#NewTypeTests.test_errors.<locals>.DN)r4   r5   r6   r-   r-   r-   r.   r   	  s   r   )r   rE   r^   r=   r>   r&   )r(   ri  rj  r   r-   r-   r.   rF   	  s    

zNewTypeTests.test_errorsN)r4   r5   r6   rn  rF   r-   r-   r-   r.   rh  x	  s   rh  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 )NamedTupleTestsc             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 | |j|j d S )	NEmpr  idrl  r<   ZJimr   )r  rq  )r   r^   rE   r/   r   rQ   rB   r  rq  r4   _fieldsr  r   r%  r[   _field_types)r(   rp  ZjoeZjimr-   r-   r.   rq   	  s    
zNamedTupleTests.test_basicsc          	   C   s`   t jd d dk r\| t tdttd W d Q R X | t G dd dt}W d Q R X d S )Nr   )r  rm  Name)Zoner  c               @   s   e Zd ZdZdS )z9NamedTupleTests.test_namedtuple_pyversion.<locals>.NotYetr   N)r4   r5   r6   rX  r-   r-   r-   r.   NotYet	  s   ru  )r   r!  r=   r>   r   rE   r^   )r(   ru  r-   r-   r.   test_namedtuple_pyversion	  s
    z)NamedTupleTests.test_namedtuple_pyversionc             C   s   t dd}| |t  | |t | |jd | |jd | t jd | t jd | t jt	j
ttd | t jt j d S )NZTimi(#  r  )r  r  )r  rQ   r   rB   r  r  r4   rr  r  r   r%  r^   rE   r[   rs  )r(   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 td W d Q R X d S )	NZJeller   ZSjoerdr   r  )r  r  )r  zE
class NonDefaultAfterDefault(NamedTuple):
    x: int = 3
    y: int
)r  rQ   r   rB   r  r  r4   rr  rs  r   r^   rE   _field_defaultsr=   r>   r  )r(   ZjelleZcooler_employeer-   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 td W d Q R X | t td W d Q R X d S )	Nr   r   r<   r   z42 -> 1r  zc
class XMethBad(NamedTuple):
    x: int
    def _fields(self):
        return 'no chance for this'
zl
class XMethBad2(NamedTuple):
    x: int
    def _source(self):
        return 'no chance for this as well'
)	rB   r  r  r   r^   r  r=   r   r  )r(   r-   r-   r.   "test_annotation_usage_with_methods	  s    z2NamedTupleTests.test_annotation_usage_with_methodsc          	   C   s   t dttd}|dd}| |t | |jd | |jd | |jd | |j	t
ttd | |j|j	 | t t ddtfgtd W d Q R X | t t ddd	d
 W d Q R X d S )NLocalEmployee)r  ZageZNick   rt  r   )r  r   r   )r   r  )r   r^   rE   rQ   r   rB   r  r4   rr  r  r   r[   rs  r=   r>   )r(   r{  Znickr-   r-   r.   test_namedtuple_keyword_usage	  s    
z-NamedTupleTests.test_namedtuple_keyword_usagec             C   s^   t ddtfdtfgatdd}x8ttjd D ]&}t||}t|}| 	|| q0W d S )Nrp  r  rq  jane%   r   )
r   r^   rE   rp  rF  rG  rH  rI  rJ  rB   )r(   r~  rL  r   Zjane2r-   r-   r.   rN  	  s    

zNamedTupleTests.test_pickleN)
r4   r5   r6   rq   rv  rw  ry  rz  r}  rN  r-   r-   r-   r.   ro  	  s   ro  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 )N)r   r   c             S   s   |   S )N)readline)r   r-   r-   r.   r  	  s    zIOTests.test_io.<locals>.stuffr   )r   r   r  rB   rZ   )r(   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 )N)r   r   c             S   s   |   S )N)r  )r   r-   r-   r.   r  
  s    z"IOTests.test_textio.<locals>.stuffr   r-   )r    r^   r  rB   rZ   )r(   r  r   r-   r-   r.   test_textio	  s    
zIOTests.test_textioc             C   s,   t tddd}|jd }| |jd d S )N)r   r   c             S   s   |   S )N)r  )r   r-   r-   r.   r  	
  s    z$IOTests.test_binaryio.<locals>.stuffr   r-   )r!   r_   r  rB   rZ   )r(   r  r   r-   r-   r.   test_binaryio
  s    
zIOTests.test_binaryioc             C   sp   ddl m}m}m}m}m} | |tj | |tj | |tj | t	|t	dddg | |d d S )Nr   )r   r    r!   rC  r4   r   r    r!   z	typing.io)
Z	typing.ior   r    r!   rC  r4   r[   r1   rB   ro  )r(   r   r    r!   rC  r4   r-   r-   r.   test_io_submodule
  s    zIOTests.test_io_submoduleN)r4   r5   r6   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.....)rY  compilerB  r/   r   r"   rH   rQ   searchr#   r   r^   r_   )r(   ZpatZmatr-   r-   r.   rq   
  s    
zRETests.test_basicsc             C   sP   |  tt tt  | tt tt  | tt tt  | tt t d S )N)rB   r"   r^   rX   r_   r#   )r(   r-   r-   r.   test_alias_equality*
  s    zRETests.test_alias_equalityc          	   C   s~   t tttf  }| t |t  W d Q R X | t tdtt  W d Q R X | t ttt tt  W d Q R X d S )Nr<   )	r#   r   r^   r_   r=   r>   r?   r"   r&   )r(   mr-   r-   r.   rF   0
  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])rB   rC   r"   r^   r_   r#   )r(   r-   r-   r.   rD   ;
  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"   rC  r4   r#   r"   z	typing.re)	Z	typing.rer#   r"   rC  r4   r[   r1   rB   ro  )r(   r#   r"   rC  r4   r-   r-   r.   test_re_submoduleC
  s
    zRETests.test_re_submodulec          	   C   s>   |  t}G dd dtj}W d Q R X | t|jd d S )Nc               @   s   e Zd ZdS )z'RETests.test_cannot_subclass.<locals>.AN)r4   r5   r6   r-   r-   r-   r.   rG   M
  s   rG   z.type 're.Match' is not an acceptable base type)r=   r>   r1   r#   rB   r^   Z	exception)r(   ZexrG   r-   r-   r.   rI   J
  s    zRETests.test_cannot_subclassN)	r4   r5   r6   rq   r  rF   rD   r  rI   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| ttdrR| d| | d	| | d
| | d| | d| | d| | d| | d| d S )Nr   )rC  rK  
ValuesViewr   r  AbstractContextManagerrY  iorY  osr   ZTextr   r   )r1   rC  r{   r  rW  r  )r(   r   r-   r-   r.   test_allW
  s    
zAllTests.test_allc                s>   dd l tj  fddt D }| |  d S )Nr   c                sn   h | ]f\}}| ksf| d s|jjkr|jjkr|dkr|ds| |kst|ddjkr|qS )_>   rY  r  )r  Z_contraZ_cor5   N)
startswithr  rC  rY  r   upperrA  r4   )r  r   r}   )
actual_allr1   r-   r.   	<setcomp>p
  s   

z3AllTests.test_all_exported_names.<locals>.<setcomp>)r1   ro  rC  varsr  ZassertSetEqual)r(   Zcomputed_allr-   )r  r1   r.   test_all_exported_namesl
  s
    
z AllTests.test_all_exported_namesN)r4   r5   r6   r  r  r-   r-   r-   r.   r  T
  s   r  __main__)grW  r   rG  rY  r   Zunittestr   r   r   r   r   r   r   r1   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   rZ  Ztestr$   r%   r7   r8   r9   r:   r;   rL   rP   ro   r   r   r^   r_   r   r   r   r   r   r   r  r  r  r  ZASYNCIO_TESTSr  r   rT  r  r  r  r  rG   r   r  rt  r  r  r  r  r  r  rE   r  r\  r  r  er  r  r  rU  r^  rh  ro  r  r  r  r4   r-   r-   r-   r.   <module>   s   *"R )N9      4( Q=
b   U'j#<1
