B
    u9a              >   @   s  d dl Z d dl mZmZ d dlZd dlZd dlZ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 dddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAg>ZddCdDZdEdF ZdGdH ZdIdJ ZdKdL ZdMdN Zg ZdOdP ZdQdR ZG dSdT dTZG dUdV dVZG dWdX dXeedBdYZeddZd[Zed>d\d[Zedd]d[Zedd^d[Zed	d_d[Z G d`d dedBdYZ!G dad deedBdYZ"d2d
d0d4d5d/d1dddb	Z#dcdd Z$G dedf dfedBdYZ%G dgdh dhe%dBdYZ&G did dZ'G djdk dkZ(G dldm dmZ)dnd9 Z*dodp Z+ej,ej-ej.ej/eeefZ0ddqd:Z1drd< Z2dsd= Z3dtdu Z4dvd? Z5G dwdx dxe6Z7G dydz dze'e7d{Z8e"d|Z9e"d}Z:e"d~Z;e"ddBdZ<e"ddBdZ=e"ddBdZ>e"ddBdZ?e"ddBe6dZ@e"d8eAeBZCdddZDeDej jEdZEeDej jFe<ZFeDej jGe<e?e=fZGeDej jHe<ZHeDej jIe<ZIeDej jJe<ZJeDej jKe<ZKeDej jLe<ZLeDej jMdZMeDej jNe<ZNeDej jOe<ZOe&ej jPddBdZPdeP_QeDej jRe<ZSeDej jTe9ZTeDej jUe:e>fZUeDej jVe:e;fZVeDej jWe<ZWeDej jXe9ZXeDej jYdZYe&eZdddBdZ[de[_QeDe\e9ddZ]eDej^e9Z_eDe`e9ddZReDeae<ddZbeDej jce<ZceDej jde:ZdeDej jee:e>fZeeDej jfe>ZfeDejge<ZheDejie<ZjeDeke:e;fddZleDejme:e;fZneDejoe:e;fZoeDejpe9ZpeDejqe:e;fZqeDej jre<e?e=fZreDej jse<e?fZseDe6e@ddZtdet_QG dd+ d+e8ZuG dd* d*e8ZvG dd) d)e8ZwG dd( d(e8ZxG dd' d'e8e< ZyG dd, d,e8e< Zzdd Z{dZ|dZ}G dd de6Z~G dd6 d6e~d{Zdd; ZeBZdZG dd de'eC ZG dd deeA ZG dd deeB ZG dd dZed e_ee
jej< eDe	jeCZeDe	jeCZG dd dZed e_ee
jej< dS )    N)abstractmethodabstractproperty)WrapperDescriptorTypeMethodWrapperTypeMethodDescriptorTypeAnyCallableClassVar
ForwardRefGenericOptionalTupleTypeTypeVarUnionAbstractSet
ByteString	ContainerContextManagerHashable	ItemsViewIterableIteratorKeysViewMappingMappingViewMutableMappingMutableSequence
MutableSetSequenceSized
ValuesView	AwaitableAsyncIteratorAsyncIterable	Coroutine
CollectionAsyncGeneratorAsyncContextManager
ReversibleSupportsAbsSupportsBytesSupportsComplexSupportsFloatSupportsIntSupportsRoundChainMapCounterDequeDictDefaultDictListOrderedDictSet	FrozenSet
NamedTuple	GeneratorAnyStrcastget_type_hintsNewTypeno_type_checkno_type_check_decoratorNoReturnoverloadTextTYPE_CHECKINGTc             C   s   t tf}|r|tf }| d kr&td S t| tr8t| S t| trZ| j|krZt	|  dt| t
rp| ttfks|| t tfkrt	d|  dt| tttfr| S t| st	| d| dd| S )Nz is not valid as type argumentzPlain z Got z.100.)r   	_Protocolr	   type
isinstancestrr
   _GenericAlias
__origin__	TypeError_SpecialFormr   rA   r   callable)argmsgis_argumentZinvalid_generic_forms rR   /usr/lib/python3.7/typing.py_type_checkq   s$    



rT   c             C   sR   t | tr,| jdkr| jS | j d| j S | dkr8dS t | tjrJ| jS t| S )NbuiltinsrE   .z...)rH   rG   
__module____qualname__typesFunctionType__name__repr)objrR   rR   rS   
_type_repr   s    

r]   c                s`   g  xR| D ]J}t |tr*| kr* | t |tr
|js
  fdd|jD  q
W t S )Nc                s   g | ]}| kr|qS rR   rR   ).0t)tvarsrR   rS   
<listcomp>   s    z&_collect_type_vars.<locals>.<listcomp>)rH   r   appendrJ   _specialextend__parameters__tuple)rX   r_   rR   )r`   rS   _collect_type_vars   s    

rg   c             C   s   t | ts| S t| j}x\t| jD ]N\}}t |trbx:t|D ]\}}||kr@|| ||< q@W q$t|||||< q$W | jtkrtt	| S | 
t	|S )N)rH   rJ   list__args__	enumerater   _subs_tvarsrK   r   rf   	copy_with)tpr`   ZsubsZnew_argsarO   iZtvarrR   rR   rS   rk      s    



rk   c          	   C   s^   | j st|  dt|}t| j }||krZtd||kr>dnd d|  d| d| d S )Nz is not a generic classzToo ZmanyZfewz parameters for z	; actual z, expected )re   rL   len)cls
parametersZalenZelenrR   rR   rS   _check_generic   s    
rs   c             C   s   g }xn| D ]f}t |tr0|jtkr0||j q
t |trft|dkrf|d tkrf||dd   q
|| q
W t	|}t|t|k rg }x(|D ] }||kr|| |
| qW |}t|S )Nr      )rH   rJ   rK   r   rd   ri   rf   rp   rb   setremove)rr   paramspZ
all_paramsZ
new_paramsr_   rR   rR   rS   _remove_dups_flatten   s     
"

ry   c                s4   t   t j t  fdd}|S )Nc                 s*   y
 | |S  t k
r   Y nX | |S )N)rL   )argskwds)cachedfuncrR   rS   inner   s
    
z_tp_cache.<locals>.inner)	functools	lru_cache	_cleanupsrb   cache_clearwraps)r}   r~   rR   )r|   r}   rS   	_tp_cache   s    r   c                sb   t | tr|  S t | tr^t fdd| jD }|| jkrH| S | |}| j|_|S | S )Nc             3   s   | ]}t | V  qd S )N)
_eval_type)r^   rn   )globalnslocalnsrR   rS   	<genexpr>	  s    z_eval_type.<locals>.<genexpr>)rH   r
   	_evaluaterJ   rf   ri   rl   rc   )r_   r   r   Zev_argsresrR   )r   r   rS   r     s    



r   c               @   s   e Zd ZdZdd ZdS )_Final)__weakref__c             O   s   d|krt dd S )N_rootz&Cannot subclass special typing classes)rL   )selfrz   r{   rR   rR   rS   __init_subclass__  s    z_Final.__init_subclass__N)rZ   rV   rW   	__slots__r   rR   rR   rR   rS   r     s   r   c               @   s   e Zd Zdd Zdd ZdS )
_Immutablec             C   s   | S )NrR   )r   rR   rR   rS   __copy__  s    z_Immutable.__copy__c             C   s   | S )NrR   )r   ZmemorR   rR   rS   __deepcopy__!  s    z_Immutable.__deepcopy__N)rZ   rV   rW   r   r   rR   rR   rR   rS   r     s   r   c                   sl   e Zd ZdZ f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edd Z  ZS )rM   )_name_docc                sB   t |dkr6t|d tr6t|d tr6td| t | S )N   r   rt   zCannot subclass )rp   rH   rI   rf   rL   super__new__)rq   rz   r{   )	__class__rR   rS   r   ,  s
    z_SpecialForm.__new__c             C   s   || _ || _d S )N)r   r   )r   namedocrR   rR   rS   __init__9  s    z_SpecialForm.__init__c             C   s   t |tstS | j|jkS )N)rH   rM   NotImplementedr   )r   otherrR   rR   rS   __eq__=  s    
z_SpecialForm.__eq__c             C   s   t | jfS )N)hashr   )r   rR   rR   rS   __hash__B  s    z_SpecialForm.__hash__c             C   s
   d| j  S )Nztyping.)r   )r   rR   rR   rS   __repr__E  s    z_SpecialForm.__repr__c             C   s   | j S )N)r   )r   rR   rR   rS   
__reduce__H  s    z_SpecialForm.__reduce__c             O   s   t d| d S )NzCannot instantiate )rL   )r   rz   r{   rR   rR   rS   __call__K  s    z_SpecialForm.__call__c             C   s   t |  dd S )Nz! cannot be used with isinstance())rL   )r   r\   rR   rR   rS   __instancecheck__N  s    z_SpecialForm.__instancecheck__c             C   s   t |  dd S )Nz! cannot be used with issubclass())rL   )r   rq   rR   rR   rS   __subclasscheck__Q  s    z_SpecialForm.__subclasscheck__c                s   | j dkr t|d}t| |fS | j dkr|dkr:tdt|tsJ|f}d t fdd|D }t|}t|d	kr|d
 S t| |S | j dkrt|d}t|t	d f S t|  dd S )Nr	   z"ClassVar accepts only single type.r   rR   z Cannot take a Union of no types.z)Union[arg, ...]: each arg must be a type.c             3   s   | ]}t | V  qd S )N)rT   )r^   rx   )rP   rR   rS   r   _  s    z+_SpecialForm.__getitem__.<locals>.<genexpr>rt   r   r   z#Optional[t] requires a single type.z is not subscriptable)
r   rT   rJ   rL   rH   rf   ry   rp   r   rG   )r   rr   itemrO   rR   )rP   rS   __getitem__T  s$    






z_SpecialForm.__getitem__)rZ   rV   rW   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__rR   rR   )r   rS   rM   %  s   rM   )r   a`  Special type indicating an unconstrained type.

    - Any is compatible with every type.
    - Any assumed to have all methods.
    - All values assumed to be instances of Any.

    Note that all the above statements are true from the point of view of
    static type checkers. At runtime, Any should not be used with instance
    or class checks.
    )r   a  Special type indicating functions that never return.
    Example::

      from typing import NoReturn

      def stop() -> NoReturn:
          raise Exception('no way')

    This type is invalid in other positions, e.g., ``List[NoReturn]``
    will fail in static type checkers.
    a3  Special type construct to mark class variables.

    An annotation wrapped in ClassVar indicates that a given
    attribute is intended to be used as a class variable and
    should not be set on instances of that class. Usage::

      class Starship:
          stats: ClassVar[Dict[str, int]] = {} # class variable
          damage: int = 10                     # instance variable

    ClassVar accepts only types and cannot be further subscribed.

    Note that ClassVar is not a class itself, and should not
    be used with isinstance() or issubclass().
    a'  Union type; Union[X, Y] means either X or Y.

    To define a union, use e.g. Union[int, str].  Details:
    - The arguments must be types and there must be at least one.
    - None as an argument is a special case and is replaced by
      type(None).
    - Unions of unions are flattened, e.g.::

        Union[Union[int, str], float] == Union[int, str, float]

    - Unions of a single argument vanish, e.g.::

        Union[int] == int  # The constructor actually returns int

    - Redundant arguments are skipped, e.g.::

        Union[int, str, int] == Union[int, str]

    - When comparing unions, the argument order is ignored, e.g.::

        Union[int, str] == Union[str, int]

    - You cannot subclass or instantiate a union.
    - You can use Optional[X] as a shorthand for Union[X, None].
    zEOptional type.

    Optional[X] is equivalent to Union[X, None].
    c               @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )r
   )__forward_arg____forward_code____forward_evaluated____forward_value____forward_is_argument__Tc             C   sn   t |tstd|yt|dd}W n" tk
rJ   td|Y nX || _|| _d| _d | _|| _	d S )Nz*Forward reference must be a string -- got z<string>evalz/Forward reference must be an expression -- got F)
rH   rI   rL   compileSyntaxErrorr   r   r   r   r   )r   rO   rQ   coderR   rR   rS   r     s    
zForwardRef.__init__c             C   sj   | j r||k	rd|d kr(|d kr(i  }}n|d kr6|}n|d krB|}tt| j||d| jd| _d| _ | jS )Nz*Forward references must evaluate to types.)rQ   T)r   rT   r   r   r   r   )r   r   r   rR   rR   rS   r     s    
zForwardRef._evaluatec             C   s&   t |tstS | j|jko$| j|jkS )N)rH   r
   r   r   r   )r   r   rR   rR   rS   r     s    
zForwardRef.__eq__c             C   s   t | j| jfS )N)r   r   r   )r   rR   rR   rS   r     s    zForwardRef.__hash__c             C   s   d| j dS )NzForwardRef())r   )r   rR   rR   rS   r     s    zForwardRef.__repr__N)T)	rZ   rV   rW   r   r   r   r   r   r   rR   rR   rR   rS   r
     s   
c               @   s2   e Zd ZdZddddddZdd Zd	d
 ZdS )r   )rZ   	__bound____constraints____covariant____contravariant__NF)bound	covariantcontravariantc               s   || _ |r|rtdt|| _t|| _|r>|d k	r>td|rVt|dkrVtdd t fdd|D | _|rt	|d| _
nd | _
tdjd	 }|d
kr|| _d S )Nz"Bivariant types are not supported.z-Constraints cannot be combined with bound=...rt   z"A single constraint is not allowedz:TypeVar(name, constraint, ...): constraints must be types.c             3   s   | ]}t | V  qd S )N)rT   )r^   r_   )rP   rR   rS   r   !  s    z#TypeVar.__init__.<locals>.<genexpr>zBound must be a type.rZ   typing)rZ   
ValueErrorboolr   r   rL   rp   rf   r   rT   r   sys	_getframe	f_globalsrV   )r   r   r   r   r   ZconstraintsZdef_modrR   )rP   rS   r     s"    

zTypeVar.__init__c             C   s&   | j rd}n| jrd}nd}|| j S )N+-~)r   r   rZ   )r   prefixrR   rR   rS   r   *  s    zTypeVar.__repr__c             C   s   | j S )N)rZ   )r   rR   rR   rS   r   3  s    zTypeVar.__reduce__)rZ   rV   rW   r   r   r   r   rR   rR   rR   rS   r     s
   ,	)	rh   rf   dictru   	frozensetdequedefaultdictrG   r7   c             C   s   |  do| dS )N__)
startswithendswith)attrrR   rR   rS   
_is_dunderN  s    r   c                   s   e Zd ZddddddZedd Zd	d
 Zdd Zdd Zdd Z	dd Z
dd Zdd Z fddZdd Zdd Zdd Z  ZS )rJ   TFN)instspecialr   c            C   sz   || _ || _|r*|d kr*|j}t||}|| _t|ts@|f}|| _tdd |D | _	t
|| _d | _|sv|j| _d S )Nc             s   s*   | ]"}|t krd n|tkrdn|V  qdS ).rR   N)_TypingEllipsis_TypingEmpty)r^   rn   rR   rR   rS   r   e  s   z)_GenericAlias.__init__.<locals>.<genexpr>)_instrc   rZ   _normalize_aliasgetr   rH   rf   rK   ri   rg   re   r   rV   )r   originrw   r   r   r   Z	orig_namerR   rR   rS   r   [  s    

z_GenericAlias.__init__c                s^   | j ttfkrtd|  t|ts,|f}d t fdd|D }t| | t| | j|S )Nz%Cannot subscript already-subscripted z*Parameters to generic types must be types.c             3   s   | ]}t | V  qd S )N)rT   )r^   rx   )rP   rR   rS   r   u  s    z,_GenericAlias.__getitem__.<locals>.<genexpr>)	rK   r   rF   rL   rH   rf   rs   rk   re   )r   rw   rR   )rP   rS   r   m  s    

z_GenericAlias.__getitem__c             C   s   t | j|| j| jdS )N)r   r   )rJ   rK   r   r   )r   rw   rR   rR   rS   rl   y  s    z_GenericAlias.copy_withc             C   s   | j dks&t| jdkrx| jd tkrx| j r8d| j  }n
t| j}| jshdddd | jD  d	}nd
}| | S | jrdS dddd | jd d D  dt| jd  d	S )Nr      r   ztyping.[z, c             S   s   g | ]}t |qS rR   )r]   )r^   rn   rR   rR   rS   ra     s    z*_GenericAlias.__repr__.<locals>.<listcomp>] ztyping.Callableztyping.Callable[[c             S   s   g | ]}t |qS rR   )r]   )r^   rn   rR   rR   rS   ra     s    z], )r   rp   ri   Ellipsisr]   rK   rc   join)r   r   rz   rR   rR   rS   r   }  s    

 z_GenericAlias.__repr__c             C   sR   t |tstS | j|jkrdS | jtkrF|jtkrFt| jt|jkS | j|jkS )NF)rH   rJ   r   rK   r   r   ri   )r   r   rR   rR   rS   r     s    
z_GenericAlias.__eq__c             C   s,   | j tkrttt| jfS t| j | jfS )N)rK   r   r   r   ri   )r   rR   rR   rS   r     s    
z_GenericAlias.__hash__c             O   sT   | j s$td| j d| j  d| j||}y
| |_W n tk
rN   Y nX |S )NzType z cannot be instantiated; use z
() instead)r   rL   r   lowerrK   Z__orig_class__AttributeError)r   rz   kwargsresultrR   rR   rS   r     s    
z_GenericAlias.__call__c             C   s   | j rZg }| j|kr || j || }tdd ||d d  D sR|t t|S | jtkr|| }x.||d d  D ]}t|tr|| k	rdS qW | jfS )Nc             s   s"   | ]}t |tpt|tV  qd S )N)rH   rJ   
issubclassr   )r^   brR   rR   rS   r     s   z0_GenericAlias.__mro_entries__.<locals>.<genexpr>rt   rR   )	r   rK   rb   indexanyr   rf   rH   rJ   )r   basesr   ro   r   rR   rR   rS   __mro_entries__  s    




z_GenericAlias.__mro_entries__c             C   s*   d| j krt|st| j|S t|d S )NrK   )__dict__r   getattrrK   r   )r   r   rR   rR   rS   __getattr__  s    z_GenericAlias.__getattr__c                s2   t |s|dkr t || nt| j|| d S )N)r   r   rc   )r   r   __setattr__setattrrK   )r   r   val)r   rR   rS   r     s    z_GenericAlias.__setattr__c             C   s   |  t|S )N)r   rG   )r   r\   rR   rR   rS   r     s    z_GenericAlias.__instancecheck__c             C   s<   | j r0t|tst|| jS |j r0t|j| jS tdd S )NzBSubscripted generics cannot be used with class and instance checks)rc   rH   rJ   r   rK   rL   )r   rq   rR   rR   rS   r     s    
z_GenericAlias.__subclasscheck__c             C   s   | j r| jS | jr t | j }n| j}|tkrht| jdkrJ| jd tksht| jd d | jd f}n*t	| j}t|dkrt
|d t	s|\}tj||ffS )Nr   r   r   rt   )rc   r   globalsrK   r   rp   ri   r   rh   rf   rH   operatorgetitem)r   r   rz   rR   rR   rS   r     s    
z_GenericAlias.__reduce__)rZ   rV   rW   r   r   r   rl   r   r   r   r   r   r   r   r   r   r   r   rR   rR   )r   rS   rJ   R  s   			rJ   c                   s(   e Zd Zdd Ze fddZ  ZS )_VariadicGenericAliasc             C   s   | j dks| js| |S t|tr0t|dkr8td|\}}|tkrRt|f}n$t|tsjtd| t||f}| |S )Nr   r   z6Callable must be used as Callable[[arg, ...], result].z1Callable[args, result]: args must be a list. Got )	r   rc   __getitem_inner__rH   rf   rp   rL   r   rh   )r   rw   rz   r   rR   rR   rS   r     s    


z!_VariadicGenericAlias.__getitem__c                s
  | j tkr| jr|dkr$| tfS t|ts4|f}t|dkrl|d dkrld t|d  }| |tfS d t fdd	|D }| |S | j t	j
jkr| jr|\}}d
 t| }|tkr| t|fS d t fdd	|D }||f }| |S t |S )NrR   r   rt   .z Tuple[t, ...]: t must be a type.r   z*Tuple[t0, t1, ...]: each t must be a type.c             3   s   | ]}t | V  qd S )N)rT   )r^   rx   )rP   rR   rS   r     s    z:_VariadicGenericAlias.__getitem_inner__.<locals>.<genexpr>z.Callable[args, result]: result must be a type.z6Callable[[arg, ...], result]: each arg must be a type.c             3   s   | ]}t | V  qd S )N)rT   )r^   rO   )rP   rR   rS   r     s    )rK   rf   rc   rl   r   rH   rp   rT   r   collectionsabcr   r   r   r   )r   rw   rx   rz   r   )r   )rP   rS   r     s.    




z'_VariadicGenericAlias.__getitem_inner__)rZ   rV   rW   r   r   r   r   rR   rR   )r   rS   r     s   r   c                   s8   e Zd ZdZ fddZedd Z fddZ  ZS )r   rR   c                sP   | t krtdt jtjkr8| jtjk	r8t | }nt j| f||}|S )NzHType Generic cannot be instantiated; it can be used only as a base class)r   rL   r   r   objectr   )rq   rz   r{   r\   )r   rR   rS   r   )  s    zGeneric.__new__c                s   t |ts|f}|s.| tk	r.td| j dd t fdd|D }| tkrtdd |D sjtdtt|t|krtdn| t	krn
t
| | t| |S )	NzParameter list to z[...] cannot be emptyz*Parameters to generic types must be types.c             3   s   | ]}t | V  qd S )N)rT   )r^   rx   )rP   rR   rS   r   ;  s    z,Generic.__class_getitem__.<locals>.<genexpr>c             s   s   | ]}t |tV  qd S )N)rH   r   )r^   rx   rR   rR   rS   r   >  s    z5Parameters to Generic[...] must all be type variablesz-Parameters to Generic[...] must all be unique)rH   rf   r   rL   rW   r   allrp   ru   rF   rs   rJ   )rq   rw   rR   )rP   rS   __class_getitem__3  s$    

zGeneric.__class_getitem__c       
         s  t  j|| g }d| jkr(t| jk}nt| jko:| jdk}|rHtdd| jkr
t| j}d }x8| jD ].}t	|t
rj|jtkrj|d k	rtd|j}qjW |d kr|}n`t|}t| | ksd fdd|D }ddd |D }	td	| d
|	 d|}t|| _d S )N__orig_bases__rF   z!Cannot inherit from plain Genericz0Cannot inherit from Generic[...] multiple types.z, c             3   s   | ]}| krt |V  qd S )N)rI   )r^   r_   )gvarsetrR   rS   r   j  s    z,Generic.__init_subclass__.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)rI   )r^   grR   rR   rS   r   k  s    zSome type variables (z) are not listed in Generic[r   )r   r   r   r   r   	__bases__rZ   rL   rg   rH   rJ   rK   re   ru   r   rf   )
rq   rz   r   r`   errorZgvarsbaseZtvarsetZs_varsZs_args)r   )r   rS   r   L  s6    





zGeneric.__init_subclass__)	rZ   rV   rW   r   r   r   r   r   r   rR   rR   )r   rS   r     s   
c               @   s   e Zd ZdS )r   N)rZ   rV   rW   rR   rR   rR   rS   r   r  s   r   c               @   s   e Zd ZdS )r   N)rZ   rV   rW   rR   rR   rR   rS   r   y  s   r   c             C   s   |S )NrR   )typr   rR   rR   rS   r<   }  s    c       
      C   s   y
| j }W n tk
r   i S X |j}|j}|d | }| jp@d}| j}|rTt|ni }|t| }x&t||d  |D ]\}}	|	||< qxW |S )NrR   )	__code__r   co_argcountco_varnames__defaults____kwdefaults__r   rp   zip)
r}   r   Z	pos_countZ	arg_namesdefaultsZ
kwdefaultsr   Z
pos_offsetr   valuerR   rR   rS   _get_defaults  s    

r  c       
      C   s  t | dd ri S t| tri }xt| jD ]~}|d krFtj|j j}n|}|j	di }xN|
 D ]B\}}|d krztd }t|trt|dd}t|||}|||< qbW q*W |S |d krt| tjr| j}nt | di }|d kr|}n|d kr|}t | dd }|d kr&t| tri S td| t| }	t|}xp|
 D ]d\}}|d krZtd }t|trnt|}t|||}||	kr|	| d krt| }|||< q@W |S )N__no_type_check____annotations__F)rQ   __globals__z1{!r} is not a module, class, method, or function.)r   rH   rG   reversed__mro__r   modulesrV   r   r   itemsrI   r
   r   rX   
ModuleType_allowed_typesrL   formatr  r   r   )
r\   r   r   Zhintsr   Zbase_globalsannr   r  r  rR   rR   rS   r=     sV    



c             C   s   t | tr|| j }x0| j D ]"\}}|| j| f kr || q W x4| D ](}t |tj	rfd|_
t |trPt| qPW y
d| _
W n tk
r   Y nX | S )NT)rH   rG   r   copyr  r   popvaluesrX   rY   r  r?   rL   )rO   Z	arg_attrsr   r   r\   rR   rR   rS   r?     s    	



c                s   t   fdd}|S )Nc                 s    | |}t |}|S )N)r?   )rz   r{   r}   )	decoratorrR   rS   wrapped_decorator  s    
z2no_type_check_decorator.<locals>.wrapped_decorator)r   r   )r  r  rR   )r  rS   r@     s    c              O   s   t dd S )NzYou should not call an overloaded function. A series of @overload-decorated functions outside a stub module should always be followed by an implementation that is not @overload-ed.)NotImplementedError)rz   r{   rR   rR   rS   _overload_dummy  s    r  c             C   s   t S )N)r  )r}   rR   rR   rS   rB   &  s    c                   s,   e Zd Z fddZdd Zdd Z  ZS )_ProtocolMetac                s"   t | jkrt |S tdd S )Nz+Protocols cannot be used with isinstance().)rF   r   r   r   rL   )r   r\   )r   rR   rS   r   J  s    
z_ProtocolMeta.__instancecheck__c                sL   | j s
tS | tkrdS |  }x(|D ]  t fdd|jD s$dS q$W dS )NTc             3   s   | ]} |j kV  qd S )N)r   )r^   d)r   rR   rS   r   \  s    z2_ProtocolMeta.__subclasscheck__.<locals>.<genexpr>F)_is_protocolr   rF   _get_protocol_attrsr   r  )r   rq   attrsrR   )r   rS   r   O  s    
z_ProtocolMeta.__subclasscheck__c             C   s&  g }x.| j D ]$}t|ddr|jdkr|| qW t } x|D ]}x|j D ]}x| j D ]$}||k	r^||jkr^t|dds^P q^W |dsR|dkrR|dkrR|dkrR|dkrR|dkrR|d	krR|d
krR|dkrR|dkrR|dkrR|dkrR|dkrR|dkrR|dkrR|dkrR|dkrR|| qRW qBW |S )Nr  FrF   Z_abc___abstractmethods__r  r   Z_gorgr   ri   r   r  Z__next_in_mro__re   rK   r   Z	__extra__Z__tree_hash__rV   )	r  r   rZ   rb   ru   r   keysr   add)r   Zprotocol_basescr  r   r   rR   rR   rS   r  `  s<    
z!_ProtocolMeta._get_protocol_attrs)rZ   rV   rW   r   r   r  r   rR   rR   )r   rS   r  C  s   r  c                   s$   e Zd ZdZdZ fddZ  ZS )rF   rR   Tc                s   t  |S )N)r   r   )rq   rw   )r   rR   rS   r     s    z_Protocol.__class_getitem__)rZ   rV   rW   r   r  r   r   rR   rR   )r   rS   rF     s   rF   )	metaclassTKTVTT_co)r   V_coVT_coT_contra)r   CT_co)r   r   c             C   s   t | |d|dS )NT)r   r   )rJ   )r   rw   r   rR   rR   rS   _alias  s    r+  rR   )r   a  Callable type; Callable[[int], str] is a function of (int) -> str.

    The subscription syntax must always be used with exactly two
    values: the argument list and the return type.  The argument list
    must be a list of types or ellipsis; the return type must be a single type.

    There is no syntax to indicate optional or keyword arguments,
    such function types are rarely used as callback types.
    F)r   r   a@  Tuple type; Tuple[X, Y] is the cross-product type of X and Y.

    Example: Tuple[T1, T2] is a tuple of two elements corresponding
    to type variables T1 and T2.  Tuple[int, float, str] is a tuple
    of an int, a float and a string.

    To specify a variable-length tuple of homogeneous type, use Tuple[T, ...].
    )r   a  A special construct usable to annotate class objects.

    For example, suppose we have the following classes::

      class User: ...  # Abstract base for User classes
      class BasicUser(User): ...
      class ProUser(User): ...
      class TeamUser(User): ...

    And a function that takes a class argument that's a subclass of
    User and returns an instance of the corresponding class::

      U = TypeVar('U', bound=User)
      def new_user(user_class: Type[U]) -> U:
          user = user_class()
          # (Here we could write the user object to a database)
          return user

      joe = new_user(BasicUser)

    At this point the type checker knows that joe has type BasicUser.
    c               @   s"   e Zd ZdZeedddZdS )r.   rR   )returnc             C   s   d S )NrR   )r   rR   rR   rS   __int__  s    zSupportsInt.__int__N)rZ   rV   rW   r   r   intr-  rR   rR   rR   rS   r.     s   c               @   s"   e Zd ZdZeedddZdS )r-   rR   )r,  c             C   s   d S )NrR   )r   rR   rR   rS   	__float__
  s    zSupportsFloat.__float__N)rZ   rV   rW   r   r   floatr/  rR   rR   rR   rS   r-     s   c               @   s"   e Zd ZdZeedddZdS )r,   rR   )r,  c             C   s   d S )NrR   )r   rR   rR   rS   __complex__  s    zSupportsComplex.__complex__N)rZ   rV   rW   r   r   complexr1  rR   rR   rR   rS   r,     s   c               @   s"   e Zd ZdZeedddZdS )r+   rR   )r,  c             C   s   d S )NrR   )r   rR   rR   rS   	__bytes__  s    zSupportsBytes.__bytes__N)rZ   rV   rW   r   r   bytesr3  rR   rR   rR   rS   r+     s   c               @   s"   e Zd ZdZeedddZdS )r*   rR   )r,  c             C   s   d S )NrR   )r   rR   rR   rS   __abs__"  s    zSupportsAbs.__abs__N)rZ   rV   rW   r   r   r&  r5  rR   rR   rR   rS   r*     s   c               @   s&   e Zd ZdZedeedddZdS )r/   rR   r   )ndigitsr,  c             C   s   d S )NrR   )r   r6  rR   rR   rS   	__round__*  s    zSupportsRound.__round__N)r   )rZ   rV   rW   r   r   r.  r&  r7  rR   rR   rR   rS   r/   '  s   c          	      sv   d  fdd|D }t | dd |D }t | |_|_ytdjdd|_	W n t
tfk
rp   Y nX |S )NzDNamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a typec                s   g | ]\}}|t | fqS rR   )rT   )r^   nr_   )rP   rR   rS   ra   1  s    z!_make_nmtuple.<locals>.<listcomp>c             S   s   g | ]\}}|qS rR   rR   )r^   r8  r_   rR   rR   rS   ra   2  s    r   rZ   __main__)r   
namedtupler6   r  _field_typesr   r   r   r   rV   r   r   )r   rX   nm_tplrR   )rP   rS   _make_nmtuple/  s    r=  )r   r   r   __getnewargs___fields_field_defaultsr;  _make_replace_asdictZ_source)rV   rZ   rW   r  c                   s   e Zd Z fddZ  ZS )NamedTupleMetac                s   | ddrt | |||S | di }t|| }g }i }xP|D ]H}||krn|| }	||	 |	||< qF|rFtdj|d|	 dqFW t
||j_t||j_||_xD|D ]<}
|
tkrtd|
 q|
tkr|
|jkrt||
||
  qW |S )Nr   Fr  zXNon-default namedtuple field {field_name} cannot follow default field(s) {default_names}z, )
field_nameZdefault_namesz&Cannot overwrite NamedTuple attribute )r   r   r   r=  r  rb   rL   r  r   r  r   r6   r  rf   r  r@  _prohibitedr   rc   r?  r   )rq   typenamer   nsrX   r<  r  Zdefaults_dictrE  Zdefault_valuekey)r   rR   rS   r   G  s0    



zNamedTupleMeta.__new__)rZ   rV   rW   r   r   rR   rR   )r   rS   rD  E  s   rD  c               @   s   e Zd ZdZdddZdS )r9   TNc             K   s(   |d kr|  }n|rtdt||S )NzIEither list of fields or keywords can be provided to NamedTuple, not both)r  rL   r=  )r   rG  Zfieldsr   rR   rR   rS   r     s
    
zNamedTuple.__new__)N)rZ   rV   rW   r   r   rR   rR   rR   rS   r9   d  s   c             C   s   dd }| |_ ||_|S )Nc             S   s   | S )NrR   )xrR   rR   rS   new_type  s    zNewType.<locals>.new_type)rZ   Z__supertype__)r   rm   rK  rR   rR   rS   r>     s    c               @   s  e Zd ZdZeedddZeedddZedddd	Z	ee
dd
dZeedddZeddddZee
dddZed6eedddZee
dddZed7eedddZed8eee dddZed9eeedd d!Zee
dd"d#Zeedd$d%Zed:eed&d'd(Zee
dd)d*Zeeed+d,d-Zeee dd.d/d0Zed1dd2d3Zeddd4d5ZdS );IOrR   )r,  c             C   s   d S )NrR   )r   rR   rR   rS   mode  s    zIO.modec             C   s   d S )NrR   )r   rR   rR   rS   r     s    zIO.nameNc             C   s   d S )NrR   )r   rR   rR   rS   close  s    zIO.closec             C   s   d S )NrR   )r   rR   rR   rS   closed  s    z	IO.closedc             C   s   d S )NrR   )r   rR   rR   rS   fileno  s    z	IO.filenoc             C   s   d S )NrR   )r   rR   rR   rS   flush  s    zIO.flushc             C   s   d S )NrR   )r   rR   rR   rS   isatty  s    z	IO.isattyr   )r8  r,  c             C   s   d S )NrR   )r   r8  rR   rR   rS   read  s    zIO.readc             C   s   d S )NrR   )r   rR   rR   rS   readable  s    zIO.readable)limitr,  c             C   s   d S )NrR   )r   rU  rR   rR   rS   readline  s    zIO.readline)hintr,  c             C   s   d S )NrR   )r   rW  rR   rR   rS   	readlines  s    zIO.readlinesr   )offsetwhencer,  c             C   s   d S )NrR   )r   rY  rZ  rR   rR   rS   seek  s    zIO.seekc             C   s   d S )NrR   )r   rR   rR   rS   seekable  s    zIO.seekablec             C   s   d S )NrR   )r   rR   rR   rS   tell  s    zIO.tell)sizer,  c             C   s   d S )NrR   )r   r^  rR   rR   rS   truncate  s    zIO.truncatec             C   s   d S )NrR   )r   rR   rR   rS   writable  s    zIO.writable)sr,  c             C   s   d S )NrR   )r   ra  rR   rR   rS   write  s    zIO.write)linesr,  c             C   s   d S )NrR   )r   rc  rR   rR   rS   
writelines  s    zIO.writelinesz
IO[AnyStr]c             C   s   d S )NrR   )r   rR   rR   rS   	__enter__  s    zIO.__enter__c             C   s   d S )NrR   )r   rG   r  	tracebackrR   rR   rS   __exit__  s    zIO.__exit__)r   )r   )r   )r   )N)rZ   rV   rW   r   r   rI   rM  r   r   rN  r   rO  r.  rP  rQ  rR  r;   rS  rT  rV  r5   rX  r[  r\  r]  r_  r`  rb  rd  re  rg  rR   rR   rR   rS   rL    sR   rL  c               @   s>   e Zd ZdZeeeef edddZ	ed dddZ
dS )	BinaryIOrR   )ra  r,  c             C   s   d S )NrR   )r   ra  rR   rR   rS   rb    s    zBinaryIO.write)r,  c             C   s   d S )NrR   )r   rR   rR   rS   re    s    zBinaryIO.__enter__N)rZ   rV   rW   r   r   r   r4  	bytearrayr.  rb  re  rR   rR   rR   rS   rh    s
   rh  c               @   s   e Zd ZdZeedddZeedddZee	e dddZ
eedd	d
ZeedddZed dddZdS )TextIOrR   )r,  c             C   s   d S )NrR   )r   rR   rR   rS   buffer  s    zTextIO.bufferc             C   s   d S )NrR   )r   rR   rR   rS   encoding#  s    zTextIO.encodingc             C   s   d S )NrR   )r   rR   rR   rS   errors'  s    zTextIO.errorsc             C   s   d S )NrR   )r   rR   rR   rS   line_buffering+  s    zTextIO.line_bufferingc             C   s   d S )NrR   )r   rR   rR   rS   newlines/  s    zTextIO.newlinesc             C   s   d S )NrR   )r   rR   rR   rS   re  3  s    zTextIO.__enter__N)rZ   rV   rW   r   r   rh  rk  rI   rl  r   rm  r   rn  r   ro  r   re  rR   rR   rR   rS   rj    s   rj  c               @   s"   e Zd ZdddgZeZeZeZdS )iorL  rj  rh  N)rZ   rV   rW   __all__rL  rj  rh  rR   rR   rR   rS   rp  8  s   
rp  z.ioc               @   s   e Zd ZddgZeZeZdS )rePatternMatchN)rZ   rV   rW   rq  rs  rt  rR   rR   rR   rS   rr  G  s   rr  z.re)T)NN)T)r   r   r   r   Zcollections.abc
contextlibr   r   rr  Z	stdlib_rer   rX   r   r   r   rq  rT   r]   rg   rk   rs   ry   r   r   r   r   r   rM   r   rA   r	   r   r   r
   r   r   r   rJ   r   r   r   r   r<   r  rY   BuiltinFunctionType
MethodTyper  r  r=   r?   r@   r  rB   rG   r  rF   r#  r$  r%  r&  r'  r(  r)  r*  r4  rI   r;   r+  r   r"   r%   r$   r#   r   r   r)   r    r   r&   r   __doc__r7   r   r   r   r   r   r   r   rf   r   rh   r5   r   r2   ru   r   r8   r   r   r   r!   AbstractContextManagerr   AbstractAsyncContextManagerr(   r   r3   r   r4   r6   r1   r0   r:   r'   r   r.   r-   r,   r+   r*   r/   r=  rF  rc   rD  r9   r>   rC   rD   rL  rh  rj  rp  rZ   r  rs  rt  rR   rR   rR   rS   <module>   s  
!	
E
0^ /_

R	D

	%`	

