
+c`              7   @   st  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	 y d  d l
 j  Z Wn e k
 r d  d l Z Yn Xd d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 g/ Z d2 d3   Z Gd4 d5   d5 e  Z Gd6 d7   d7  Z Gd8 d9   d9 e  Z Gd: d;   d;  Z d< d=   Z d> d?   Z d@ dA   Z dB dC   Z dD dE   Z GdF dG   dG e  Z GdH d   d e dI e dJ dK Z GdL d	   d	 e dI e dJ dK Z e dM  Z e dN  Z e dO  Z e dP dQ dK Z e dR dQ dK Z  e dS dQ dK Z! e dT dU dK Z" e d) e# e$  Z% GdV dW   dW e  Z& GdX d
   d
 e dI e& dJ dK Z' GdY dZ   dZ e  Z( Gd[ d   d e dI e( dJ dK Z) Gd\ d]   d] e  Z* Gd^ d   d e dI e* dJ dK Z+ Gd_ d`   d` e  Z, Gda d   d e dI e, dJ dK Z- db dc   Z. dd de   Z/ df dg   Z0 Gdh di   di e e  j1  Z2 d Z3 Gdj d   d dI e2 Z3 dk d*   Z4 dl dm   Z5 d d dn d+  Z6 do d-   Z7 dp d.   Z8 dq dr   Z9 ds d/   Z: Gdt du   du e2  Z; Gdv dw   dw dI e; Z< e j= Z= e> e d  rGdx d   d e3 e dy e j? Z? n d Z? e> e d  rGdz d   d e3 e dy e j@ Z@ Gd{ d   d e@ e dy e jA ZA n d Z@ d ZA Gd| d   d e3 e dy e jB ZB Gd} d   d eB e dy e jC ZC Gd~ d!   d! e<  ZD Gd d    d  e<  ZE Gd d   d e<  ZF Gd d   d e<  ZG Gd d   d e< e  ZH Gd d"   d" e< e  ZI e> e d  rGd d   d eB e dy e jJ ZJ n Gd d   d e< e  ZJ e jK ZK Gd d   d e3 e dy e jL ZL Gd d   d eK eB e eL e dy e jM ZN Gd d   d eN e dy e jO ZO Gd d   d eK eB e eL e e3 e e! f dy e jP ZP Gd d   d eP e e f dy e jQ ZQ e> e d  rRGd d   d eK eJ e eL e dy e jR ZR n- Gd d   d eK eB e eL e dy e jR ZR Gd d   d eR e dy e jS ZS Gd d   d eR eT dy e jU ZU eU jV e eW d    Gd d%   d% eX eS e dy eX ZY Gd d&   d& eZ eO e dy eZ ZM Gd d   d e2  Z[ Gd d   d e\ eN e dI e[ dy e\ Z] Gd d   d eK eB e dy e j^ Z^ Gd d   d e^ e eN e dy e j_ Z_ Gd d   d e^ e+ e e! f eN e+ e e! f e3 e e! f dy e j` Z` Gd d   d e^ e! dy e ja Za e> e d  r`	Gd d   d e3 e dy e jb Zc e jd d  Gd d#   d# ee eQ e e f dy ee Zf Gd d$   d$ e jg eQ e e f dy e jg Zh e> e d(  r	e ji Zj n	 e	 jk Zj Gd d(   d( eC e e3 e e" e  f dy ej Zi e d dQ dK d e Zl Gd d   d e e3 el dy e Zm d d'   Zn d d,   Zo e$ Zp d Zq Gd d   d e3 e%  Zr Gd d   d er e#  Zs Gd d   d er e$  Zt Gd d   d  Zu ev d eu _v eu e jw eu jv <e d e% e e jx d   d d    Zy e d e% e e jz d d   d d    Z{ Gd d   d  Z ev d e _v e e jw e jv <d S)    N)abstractmethodabstractpropertyAnyCallableGenericOptionalTupleTypeTypeVarUnionAbstractSet	AwaitableAsyncIteratorAsyncIterable
ByteString	ContainerHashable	ItemsViewIterableIteratorKeysViewMappingMappingViewMutableMappingMutableSequence
MutableSetSequenceSized
ValuesView
ReversibleSupportsAbsSupportsFloatSupportsIntSupportsRoundDictDefaultDictListSet
NamedTuple	GeneratorAnyStrcastget_type_hintsNewTypeno_type_checkno_type_check_decoratoroverloadTextTYPE_CHECKINGc             C   s+   t  j d  d  d k r  |  j S|  j Sd  S)N      )r4   r4   )sysversion_info__qualname____name__)x r:   /usr/lib/python3.5/typing.py	_qualnameP   s    r<   c                   sd   e  Z d  Z d Z d Z d d   f d d  Z d d   Z d d	   Z d
 d   Z d d   Z	   S)
TypingMetaa  Metaclass for every type defined below.

    This overrides __new__() to require an extra keyword parameter
    '_root', which serves as a guard against naive subclassing of the
    typing classes.  Any legitimate class defined using a metaclass
    derived from TypingMeta (including internal subclasses created by
    e.g.  Union[X, Y]) must pass _root=True.

    This also defines a dummy constructor (all the work is done in
    __new__) and a nicer repr().
    F_rootc               sG   | s. t  d d j t t |   p' d   t   j |  | | |  S)NzCannot subclass %sz, z())	TypeErrorjoinmap
_type_reprsuper__new__)clsnamebases	namespacer>   )	__class__r:   r;   rD   g   s    "zTypingMeta.__new__c             O   s   d  S)Nr:   )selfargskwdsr:   r:   r;   __init__m   s    zTypingMeta.__init__c             C   s   |  S)a+  Override this in subclasses to interpret forward references.

        For example, Union['C'] is internally stored as
        Union[_ForwardRef('C')], which should evaluate to _Union[C],
        where C is an object found in globalns or localns (searching
        localns first, of course).
        r:   )rJ   globalnslocalnsr:   r:   r;   
_eval_typep   s    zTypingMeta._eval_typec             C   s   d  S)Nr:   )rJ   tvarsr:   r:   r;   _get_type_varsz   s    zTypingMeta._get_type_varsc             C   s   d |  j  t |   f S)Nz%s.%s)
__module__r<   )rJ   r:   r:   r;   __repr__}   s    zTypingMeta.__repr__)
r8   rS   r7   __doc___is_protocolrD   rM   rP   rR   rT   r:   r:   )rI   r;   r=   X   s   
r=   c               @   s(   e  Z d  Z d Z f  Z d d   Z d S)Finalz&Mix-in class to prevent instantiation.c             O   s   t  d |  j   d  S)NzCannot instantiate %r)r?   rI   )rJ   rK   rL   r:   r:   r;   rD      s    zFinal.__new__N)r8   rS   r7   rU   	__slots__rD   r:   r:   r:   r;   rW      s   rW   c                   sX   e  Z d  Z d Z   f d d   Z d d   Z d d   Z d d	   Z d
 d   Z   S)_ForwardRefz$Wrapper to hold a forward reference.c                s  t  | t  s" t d | f   y t | d d  } Wn% t k
 r_ t d | f   Yn Xt   j |  | f  i  d d } | | _ | | _ d | _	 d  | _
 t   } t j d  } x( | d  k	 r | j | k r | j } q W| d  k	 s t  | | _ | S)	Nz%ForwardRef must be a string -- got %rz<string>evalz*ForwardRef must be an expression -- got %rr>   TF   )
isinstancestrr?   compileSyntaxErrorrC   rD   __forward_arg____forward_code____forward_evaluated____forward_value__globalsr5   	_getframe	f_globalsf_backAssertionError__forward_frame__)rE   argcoderJ   Ztyping_globalsframe)rI   r:   r;   rD      s&    !						z_ForwardRef.__new__c             C   s   t  | t  s" t d | f   t  | t  sD t d | f   |  j s | d  k rr | d  k rr i  } } n' | d  k r | } n | d  k r | } t t |  j | |  d  |  _ d |  _ |  j S)Nz+ForwardRef localns must be a dict -- got %rz,ForwardRef globalns must be a dict -- got %rz*Forward references must evaluate to types.T)r\   dictr?   rb   _type_checkrZ   ra   rc   )rJ   rN   rO   r:   r:   r;   rP      s$    			z_ForwardRef._eval_typec             C   s   t  d   d  S)Nz4Forward references cannot be used with isinstance().)r?   )rJ   objr:   r:   r;   __instancecheck__   s    z_ForwardRef.__instancecheck__c             C   s^   |  j  sN |  j j } |  j j } y |  j | |  Wn t k
 rM d SYn Xt | |  j  S)NF)rb   ri   rf   f_localsrP   	NameError
issubclassrc   )rJ   rE   rN   rO   r:   r:   r;   __subclasscheck__   s    		z_ForwardRef.__subclasscheck__c             C   s   d |  j  f S)Nz_ForwardRef(%r))r`   )rJ   r:   r:   r;   rT      s    z_ForwardRef.__repr__)	r8   rS   r7   rU   rD   rP   rp   rt   rT   r:   r:   )rI   r;   rY      s   
rY   c               @   sd   e  Z d  Z d Z d Z d d   Z d d	   Z d
 d   Z d d   Z d d   Z	 d d   Z
 d S)
_TypeAliasa  Internal helper class for defining generic variants of concrete types.

    Note that this is not a type; let's call it a pseudo-type.  It can
    be used in instance and subclass checks, e.g. isinstance(m, Match)
    or issubclass(type(m), Match).  However, it cannot be itself the
    target of an issubclass() call; e.g. issubclass(Match, C) (for
    some arbitrary class C) raises TypeError rather than returning
    False.
    rF   type_var	impl_typetype_checkerc             O   sQ   t  |  d k rD t | d t  rD t | d t  rD t d   t j |   S)zConstructor.

        This only exists to give a better error message in case
        someone tries to subclass a type alias (not a good idea).
        r4   r   r[   z!A type alias cannot be subclassed)lenr\   r]   tupler?   objectrD   )rE   rK   rL   r:   r:   r;   rD      s
    z_TypeAlias.__new__c             C   s   t  | t  s! t t |    t  | t  sB t t |    t  | t  sc t t |    t  | t  s t t |    | |  _ | |  _ | |  _ | |  _	 d S)at  Initializer.

        Args:
            name: The name, e.g. 'Pattern'.
            type_var: The type parameter, e.g. AnyStr, or the
                specific type, e.g. str.
            impl_type: The implementation type.
            type_checker: Function that takes an impl_type instance.
                and returns a value that should be a type_var instance.
        N)
r\   r]   rh   reprtyper=   rF   rv   rw   rx   )rJ   rF   rv   rw   rx   r:   r:   r;   rM      s    !!!"			z_TypeAlias.__init__c             C   s   d |  j  t |  j  f S)Nz%s[%s])rF   rB   rv   )rJ   r:   r:   r;   rT      s    z_TypeAlias.__repr__c             C   s   t  | t  s! t t |    t  |  j t  sC t d |    |  j j r t | t	 |  j j  s t d | |  j f   |  j
 |  j | |  j |  j  S)Nz#%s cannot be further parameterized.z&%s is not a valid substitution for %s.)r\   r}   rh   r|   rv   r
   r?   __constraints__rs   r   rI   rF   rw   rx   )rJ   Z	parameterr:   r:   r;   __getitem__   s    !z_TypeAlias.__getitem__c             C   s   t  d   d  S)Nz.Type aliases cannot be used with isinstance().)r?   )rJ   ro   r:   r:   r;   rp     s    z_TypeAlias.__instancecheck__c             C   sX   | t  k r d St | t  rD | j |  j k oC t | j |  j  St | |  j  Sd  S)NT)r   r\   ru   rF   rs   rv   rw   )rJ   rE   r:   r:   r;   rt     s    z_TypeAlias.__subclasscheck__N)znameztype_varz	impl_typeztype_checker)r8   rS   r7   rU   rX   rD   rM   rT   r   rp   rt   r:   r:   r:   r;   ru      s   	ru   c             C   s1   x* |  D]" } t  | t  r | j |  q Wd  S)N)r\   r=   rR   )typesrQ   tr:   r:   r;   rR     s    rR   c             C   s   g  } t  |  |  t |  S)N)rR   rz   )r   rQ   r:   r:   r;   
_type_vars  s    r   c             C   s'   t  |  t  r |  j | |  S|  Sd  S)N)r\   r=   rP   )r   rN   rO   r:   r:   r;   rP      s    rP   c             C   so   |  d k r t  d  St |  t  r1 t |   }  t |  t  t f  rk t |   rk t | d |  f   |  S)av  Check that the argument is a type, and return it.

    As a special case, accept None and return type(None) instead.
    Also, _TypeAlias instances (e.g. Match, Pattern) are acceptable.

    The msg argument is a human-readable error message, e.g.

        "Union[arg, ...]: arg should be a type."

    We append the repr() of the actual value (truncated to 100 chars).
    Nz Got %.100r.)r}   r\   r]   rY   ru   callabler?   )rj   msgr:   r:   r;   rn   '  s    
#rn   c             C   s`   t  |  t  rR t  |  t  rR |  j d k r8 t |   Sd |  j t |   f Sn
 t |   Sd S)a)  Return the repr() of an object, special-casing types.

    If obj is a type, we return a shorter version than the default
    type.__repr__, based on the module and qualified name, which is
    typically enough to uniquely identify a type.  For everything
    else, we fall back on repr(obj).
    builtinsz%s.%sN)r\   r}   r=   rS   r<   r|   )ro   r:   r:   r;   rB   <  s
    
rB   c                   sI   e  Z d  Z d Z d   f d d  Z d d   Z   f d d   Z   S)	AnyMetazMetaclass for Any.Fc                s%   t    j |  | | | d | } | S)Nr>   )rC   rD   )rE   rF   rG   rH   r>   rJ   )rI   r:   r;   rD   P  s    !zAnyMeta.__new__c             C   s   t  d   d  S)Nz%Any cannot be used with isinstance().)r?   )rJ   ro   r:   r:   r;   rp   T  s    zAnyMeta.__instancecheck__c                s#   t  | t  s t   j |  Sd S)NT)r\   r}   rC   rt   )rJ   rE   )rI   r:   r;   rt   W  s    zAnyMeta.__subclasscheck__)r8   rS   r7   rU   rD   rp   rt   r:   r:   )rI   r;   r   M  s   r   c               @   s   e  Z d  Z d Z f  Z d S)r   zSpecial type indicating an unconstrained type.

    - Any object is an instance of Any.
    - Any class is a subclass of Any.
    - As a special case, Any and object are subclasses of each other.
    N)r8   rS   r7   rU   rX   r:   r:   r:   r;   r   ]  s   	metaclassr>   Tc            	       sj   e  Z d  Z d Z d d d d d d   f d d  Z d	 d
   Z d d   Z d d   Z d d   Z   S)r
   a+  Type variable.

    Usage::

      T = TypeVar('T')  # Can be anything
      A = TypeVar('A', str, bytes)  # Must be str or bytes

    Type variables exist primarily for the benefit of static type
    checkers.  They serve as the parameters for generic types as well
    as for generic function definitions.  See class Generic for more
    information on generic types.  Generic functions work as follows:

      def repeat(x: T, n: int) -> Sequence[T]:
          '''Return a list containing n references to x.'''
          return [x]*n

      def longest(x: A, y: A) -> A:
          '''Return the longest of two strings.'''
          return x if len(x) >= len(y) else y

    The latter example's signature is essentially the overloading
    of (str, str) -> str and (bytes, bytes) -> bytes.  Also note
    that if the arguments are instances of some subclass of str,
    the return type is still plain str.

    At runtime, isinstance(x, T) will raise TypeError.  However,
    issubclass(C, T) is true for any class C, and issubclass(str, A)
    and issubclass(bytes, A) are true, and issubclass(int, A) is
    false.  (TODO: Why is this needed?  This may change.  See #136.)

    Type variables may be marked covariant or contravariant by passing
    covariant=True or contravariant=True.  See PEP 484 for more
    details.  By default type variables are invariant.

    Type variables can be introspected. e.g.:

      T.__name__ == 'T'
      T.__constraints__ == ()
      T.__covariant__ == False
      T.__contravariant__ = False
      A.__constraints__ == (str, bytes)
    boundN	covariantFcontravariantc               s   t    j |  | t f i  d d } | r< | r< t d   t |  | _ t |  | _ | rx | d  k	 rx t d   | r t |  d k r t d   d   t	   f d d	   | D  | _
 | r t | d
  | _ n	 d  | _ | S)Nr>   Tz+Bivariant type variables are not supported.z-Constraints cannot be combined with bound=...r[   z"A single constraint is not allowedz:TypeVar(name, constraint, ...): constraints must be types.c             3   s   |  ] } t  |    Vq d  S)N)rn   ).0r   )r   r:   r;   	<genexpr>  s    z"TypeVar.__new__.<locals>.<genexpr>zBound must be a type.)rC   rD   rW   
ValueErrorbool__covariant____contravariant__r?   ry   rz   r~   rn   	__bound__)rE   rF   r   r   r   ZconstraintsrJ   )rI   )r   r;   rD     s    $"	zTypeVar.__new__c             C   s   |  | k r | j  |   d  S)N)append)rJ   rQ   r:   r:   r;   rR     s    zTypeVar._get_type_varsc             C   s5   |  j  r d } n |  j r$ d } n d } | |  j S)N+-~)r   r   r8   )rJ   prefixr:   r:   r;   rT     s    				zTypeVar.__repr__c             C   s   t  d   d  S)Nz0Type variables cannot be used with isinstance().)r?   )rJ   instancer:   r:   r;   rp     s    zTypeVar.__instancecheck__c                sl     |  k r d S  t  k r  d S|  j d  k	 r? t   |  j  S|  j rh t   f d d   |  j D  Sd S)NTc             3   s   |  ] } t    |  Vq d  S)N)rs   )r   c)rE   r:   r;   r     s    z,TypeVar.__subclasscheck__.<locals>.<genexpr>)r   r   rs   r~   any)rJ   rE   r:   )rE   r;   rt     s    	 zTypeVar.__subclasscheck__)	r8   rS   r7   rU   rD   rR   rT   rp   rt   r:   r:   )rI   r;   r
   h  s   *		TKTVTT_cor   V_coVT_coT_contrar   c                   s   e  Z d  Z d Z d d   f d d  Z d d   Z d d	   Z   f d
 d   Z d d   Z d d   Z	 d d   Z
 d d   Z d d   Z   S)	UnionMetazMetaclass for Union.NFc                s2  | d  k r+ t    j |  | | | d | St | t  sF t d   g  } d } xF | D]> } t | t  r | j | j  qY | j t	 | |   qY Wt
 |    t    t |  k  rg  }	 x4 | D], }
 |
   k r |	 j |
    j |
  q W|	 }   st     t
 |    x | D]   t k r>t St  t  rPq(t  t  rbq(t  t  st   s(t  q(t  f d d      h D  r(  j   q(Wt    d k r  j   St    j |  | | i  d d } t   f d d   | D  | _ t | j  | _ | S)	Nr>   zExpected parameters=<tuple>z)Union[arg, ...]: each arg must be a type.c             3   s<   |  ]2 } t  | t  s t  | t  o3 t   |  Vq d  S)N)r\   r
   r}   rs   )r   Zt2)t1r:   r;   r     s   z$UnionMeta.__new__.<locals>.<genexpr>r[   Tc             3   s!   |  ] } |   k r | Vq d  S)Nr:   )r   r   )
all_paramsr:   r;   r     s    )rC   rD   r\   rz   r?   r   extend__union_params__r   rn   setry   removerh   r   r
   ru   r}   r   r   pop	frozenset__union_set_params__)rE   rF   rG   rH   
parametersr>   paramsr   pZ
new_paramsr   rJ   )rI   )r   r   r;   rD     sN    
!"zUnionMeta.__new__c                s^   t     f d d   |  j D  } | |  j k r8 |  S|  j |  j |  j i  | d d Sd  S)Nc             3   s!   |  ] } t  |     Vq d  S)N)rP   )r   r   )rN   rO   r:   r;   r     s   z'UnionMeta._eval_type.<locals>.<genexpr>r>   T)rz   r   rI   r8   	__bases__)rJ   rN   rO   r   r:   )rN   rO   r;   rP     s    zUnionMeta._eval_typec             C   s   |  j  r t |  j  |  d  S)N)r   rR   )rJ   rQ   r:   r:   r;   rR     s    	zUnionMeta._get_type_varsc                sC   t    j   } |  j r? | d d j d d   |  j D  7} | S)Nz[%s]z, c             s   s   |  ] } t  |  Vq d  S)N)rB   )r   r   r:   r:   r;   r     s   z%UnionMeta.__repr__.<locals>.<genexpr>)rC   rT   r   r@   )rJ   r)rI   r:   r;   rT     s
    	zUnionMeta.__repr__c             C   sv   |  j  d  k	 r t d   | f  k r3 t d   t | t  sK | f } |  j |  j |  j t |  j  | d d S)Nz<Cannot subscript an existing Union. Use Union[u, t] instead.z Cannot take a Union of no types.r>   T)	r   r?   r\   rz   rI   r8   r   rm   __dict__)rJ   r   r:   r:   r;   r     s    		zUnionMeta.__getitem__c             C   s#   t  | t  s t S|  j | j k S)N)r\   r   NotImplementedr   )rJ   otherr:   r:   r;   __eq__*  s    zUnionMeta.__eq__c             C   s   t  |  j  S)N)hashr   )rJ   r:   r:   r;   __hash__/  s    zUnionMeta.__hash__c             C   s   t  d   d  S)Nz(Unions cannot be used with isinstance().)r?   )rJ   ro   r:   r:   r;   rp   2  s    zUnionMeta.__instancecheck__c                s     t  k r d S j d  k r, t   t  St   t  rn   j d  k rN d St  f d d     j D  St   t  r    j k r d S  j r t t   j   Sd St	   f d d    j D  Sd  S)NTFc             3   s   |  ] } t  |    Vq d  S)N)rs   )r   r   )rJ   r:   r;   r   =  s    z.UnionMeta.__subclasscheck__.<locals>.<genexpr>c             3   s   |  ] } t    |  Vq d  S)N)rs   )r   r   )rE   r:   r;   r   E  s    )
r   r   r\   r   allr
   r~   rs   r   r   )rJ   rE   r:   )rE   rJ   r;   rt   5  s     	zUnionMeta.__subclasscheck__)r8   rS   r7   rU   rD   rP   rR   rT   r   r   r   rp   rt   r:   r:   )rI   r;   r     s   5	r   c               @   s"   e  Z d  Z d Z d Z d Z d S)r   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]

    - When two arguments have a subclass relationship, the least
      derived argument is kept, e.g.::

        class Employee: pass
        class Manager(Employee): pass
        Union[int, Employee, Manager] == Union[int, Employee]
        Union[Manager, int, Employee] == Union[int, Employee]
        Union[Employee, Manager] == Employee

    - Corollary: if Any is present it is the sole survivor, e.g.::

        Union[int, Any] == Any

    - Similar for object::

        Union[int, object] == object

    - To cut a tie: Union[object, Any] == Union[Any, object] == Any.

    - You cannot subclass or instantiate a union.

    - You cannot write Union[X][Y] (what would it mean?).

    - You can use Optional[X] as a shorthand for Union[X, None].
    N)r8   rS   r7   rU   r   r   r:   r:   r:   r;   r   H  s   2c                   s7   e  Z d  Z d Z d   f d d  Z d d   Z   S)OptionalMetazMetaclass for Optional.Fc                s   t    j |  | | | d | S)Nr>   )rC   rD   )rE   rF   rG   rH   r>   )rI   r:   r;   rD     s    zOptionalMeta.__new__c             C   s#   t  | d  } t | t d   f S)Nz#Optional[t] requires a single type.)rn   r   r}   )rJ   rj   r:   r:   r;   r     s    zOptionalMeta.__getitem__)r8   rS   r7   rU   rD   r   r:   r:   )rI   r;   r     s   r   c               @   s   e  Z d  Z d Z f  Z d S)r   zKOptional type.

    Optional[X] is equivalent to Union[X, type(None)].
    N)r8   rS   r7   rU   rX   r:   r:   r:   r;   r     s   c                   s   e  Z d  Z d Z d d d   f d d  Z d d   Z d d	   Z   f d
 d   Z d d   Z d d   Z	 d d   Z
 d d   Z   f d d   Z   S)	TupleMetazMetaclass for Tuple.NFc                s7   t    j |  | | | d | } | | _ | | _ | S)Nr>   )rC   rD   __tuple_params____tuple_use_ellipsis__)rE   rF   rG   rH   r   use_ellipsisr>   rJ   )rI   r:   r;   rD     s    !		zTupleMeta.__new__c             C   s   |  j  r t |  j  |  d  S)N)r   rR   )rJ   rQ   r:   r:   r;   rR     s    	zTupleMeta._get_type_varsc                st   |  j  } | d  k r |  St    f d d   | D  } | |  j  k rN |  S|  j |  j |  j i  | d d Sd  S)Nc             3   s!   |  ] } t  |     Vq d  S)N)rP   )r   r   )rN   rO   r:   r;   r     s    z'TupleMeta._eval_type.<locals>.<genexpr>r>   T)r   rz   rI   r8   r   )rJ   rN   rO   tpr   r:   )rN   rO   r;   rP     s    	"zTupleMeta._eval_typec                sx   t    j   } |  j d  k	 rt d d   |  j D } |  j rJ | j d  | s] | j d  | d d j |  7} | S)Nc             S   s   g  |  ] } t  |   q Sr:   )rB   )r   r   r:   r:   r;   
<listcomp>  s   	 z&TupleMeta.__repr__.<locals>.<listcomp>z...z()z[%s]z, )rC   rT   r   r   r   r@   )rJ   r   r   )rI   r:   r;   rT     s    	zTupleMeta.__repr__c          	      s   |  j  d  k	 r" t d |  f   t | t  s: | f } t |  d k r{ | d t k r{ | d  d  } d } d   n d } d   t   f d d	   | D  } |  j |  j |  j t	 |  j
  | d
 | d d S)NzCannot re-parameterize %rr3   r[   Tz Tuple[t, ...]: t must be a type.Fz*Tuple[t0, t1, ...]: each t must be a type.c             3   s   |  ] } t  |    Vq d  S)N)rn   )r   r   )r   r:   r;   r     s    z(TupleMeta.__getitem__.<locals>.<genexpr>r   r>   )r   r?   r\   rz   ry   EllipsisrI   r8   r   rm   r   )rJ   r   r   r:   )r   r;   r     s    	"	zTupleMeta.__getitem__c             C   s5   t  | t  s t S|  j | j k o4 |  j | j k S)N)r\   r   r   r   r   )rJ   r   r:   r:   r;   r     s    zTupleMeta.__eq__c             C   s   t  |  j  S)N)r   r   )rJ   r:   r:   r;   r     s    zTupleMeta.__hash__c             C   s   t  d   d  S)Nz(Tuples cannot be used with isinstance().)r?   )rJ   ro   r:   r:   r;   rp     s    zTupleMeta.__instancecheck__c                s   | t  k r d St | t  s/ t   j |  St | t  rB d St | t  sa t   j |  S|  j d  k rt d S| j d  k r d S| j	 |  j	 k r d St
 |  j  t
 | j  k o t d d   t | j |  j  D  S)NTFc             s   s$   |  ] \ } } t  | |  Vq d  S)N)rs   )r   r9   r   r:   r:   r;   r     s   z.TupleMeta.__subclasscheck__.<locals>.<genexpr>)r   r\   r}   rC   rt   rs   rz   r   r   r   ry   r   zip)rJ   rE   )rI   r:   r;   rt     s$    	zTupleMeta.__subclasscheck__)r8   rS   r7   rU   rD   rR   rP   rT   r   r   r   rp   rt   r:   r:   )rI   r;   r     s   r   c               @   s   e  Z d  Z d Z f  Z d S)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 Sequence[T].
    N)r8   rS   r7   rU   rX   r:   r:   r:   r;   r     s   c                   s   e  Z d  Z d Z d d d   f d d  Z d d   Z d d	   Z   f d
 d   Z d d   Z d d   Z	 d d   Z
 d d   Z   f d d   Z   S)CallableMetazMetaclass for Callable.FNc                s   | d  k r | d  k r nh | t  k	 rn t | t  sI t d | f   d   t   f d d   | D  } d   t |    } t   j |  | | | d | } | | _ | | _	 | S)Nz8Callable[args, result]: args must be a list. Got %.100r.z6Callable[[arg, ...], result]: each arg must be a type.c             3   s   |  ] } t  |    Vq d  S)N)rn   )r   rj   )r   r:   r;   r     s    z'CallableMeta.__new__.<locals>.<genexpr>z.Callable[args, result]: result must be a type.r>   )
r   r\   listr?   rz   rn   rC   rD   __args__
__result__)rE   rF   rG   rH   r>   rK   resultrJ   )rI   )r   r;   rD     s    !		zCallableMeta.__new__c             C   s   |  j  r t |  j  |  d  S)N)r   rR   )rJ   rQ   r:   r:   r;   rR     s    	zCallableMeta._get_type_varsc          
      s   |  j  d  k r" |  j d  k r" |  S|  j  t k r= |  j  } n    f d d   |  j  D } t |  j     } | |  j  k r | |  j k r |  S|  j |  j |  j i  d | d | d d Sd  S)Nc                s"   g  |  ] } t  |      q Sr:   )rP   )r   r   )rN   rO   r:   r;   r     s   	 z+CallableMeta._eval_type.<locals>.<listcomp>rK   r   r>   T)r   r   r   rP   rI   r8   r   )rJ   rN   rO   rK   r   r:   )rN   rO   r;   rP     s    zCallableMeta._eval_typec                s   t    j   } |  j d  k	 s- |  j d  k	 r |  j t k rE d } n# d d j d d   |  j D  } | d | t |  j  f 7} | S)Nz...z[%s]z, c             s   s   |  ] } t  |  Vq d  S)N)rB   )r   r   r:   r:   r;   r   (  s   z(CallableMeta.__repr__.<locals>.<genexpr>z[%s, %s])rC   rT   r   r   r   r@   rB   )rJ   r   Zargs_r)rI   r:   r;   rT   "  s    	zCallableMeta.__repr__c          
   C   s   |  j  d  k	 s |  j d  k	 r* t d   t | t  sL t |  d k rX t d   | \ } } |  j |  j |  j t	 |  j
  d d d | d | S)Nz,This Callable type is already parameterized.r3   z6Callable must be used as Callable[[arg, ...], result].r>   TrK   r   )r   r   r?   r\   rz   ry   rI   r8   r   rm   r   )rJ   r   rK   r   r:   r:   r;   r   -  s    "	zCallableMeta.__getitem__c             C   s5   t  | t  s t S|  j | j k o4 |  j | j k S)N)r\   r   r   r   r   )rJ   r   r:   r:   r;   r   8  s    zCallableMeta.__eq__c             C   s   t  |  j  t  |  j  AS)N)r   r   r   )rJ   r:   r:   r;   r   >  s    zCallableMeta.__hash__c             C   s>   |  j  d  k r. |  j d  k r. t | t j  St d   d  S)Nz,Callable[] cannot be used with isinstance().)r   r   r\   collections_abcr   r?   )rJ   ro   r:   r:   r;   rp   A  s    zCallableMeta.__instancecheck__c                s[   | t  k r d St | t  s/ t   j |  S|  j d  k rQ |  j d  k rQ d S|  | k S)NT)r   r\   r   rC   rt   r   r   )rJ   rE   )rI   r:   r;   rt   J  s    zCallableMeta.__subclasscheck__)r8   rS   r7   rU   rD   rR   rP   rT   r   r   r   rp   rt   r:   r:   )rI   r;   r     s   	r   c               @   s   e  Z d  Z d Z f  Z d S)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; 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.
    N)r8   rS   r7   rU   rX   r:   r:   r:   r;   r   U  s   	c             C   s8   t  |  t  s t  x |  j d k	 r3 |  j }  q W|  S)z.Return the farthest origin of a generic class.N)r\   GenericMetarh   
__origin__)ar:   r:   r;   _gorgc  s    r   c             C   s:   t  |  t  r t  | t  s$ t  t |   t |  k S)a%  Return whether two generic classes are equivalent.

    The intention is to consider generic class X and any of its
    parameterized forms (X[T], X[int], etc.)  as equivalent.

    However, X is not equivalent to a subclass of X.

    The relation is reflexive, symmetric and transitive.
    )r\   r   rh   r   )r   br:   r:   r;   _geqvk  s    
$r   c             C   sf   t  } xY t |  j d d   D]> \ } } t | t  r  t |  t k r  |  j | d } q  W| S)zHelper for Generic.__new__.

    Returns the class after the last occurrence of Generic or
    Generic[...] in cls.__mro__.
    Nr[   )r{   	enumerate__mro__r\   r   r   r   )rE   Znext_in_mroir   r:   r:   r;   _next_in_mroz  s
    &!r   c                   s   e  Z d  Z d Z d d d d   f d d  Z d d   Z   f d d   Z d	 d
   Z d d   Z d d   Z	 d d   Z
   f d d   Z   S)r   zMetaclass for generic types.Nc                s  t    j |  | | | d d } | d  k	 rg | d  k	 s? t  t d d   | D  st |   nI| d  k s t |   | d  k s t |   | d  k s t |   t |  } d  }	 xe | D]] }
 |
 t k r t d   t |
 t  r |
 j	 t k r |	 d  k	 rt d   |
 j
 }	 q W|	 d  k r>| }	 nr t |  } t |	    |   k st d d j   f d	 d   | D  d j d
 d   |	 D  f   |	 } | | _
 | | _ | | _	 | | _ t |  | _ | S)Nr>   Tc             s   s   |  ] } t  | t  Vq d  S)N)r\   r
   )r   r   r:   r:   r;   r     s    z&GenericMeta.__new__.<locals>.<genexpr>z!Cannot inherit from plain Genericz0Cannot inherit from Generic[...] multiple types.z6Some type variables (%s) are not listed in Generic[%s]z, c             3   s'   |  ] } |   k r t  |  Vq d  S)N)r]   )r   r   )gvarsetr:   r;   r     s    c             s   s   |  ] } t  |  Vq d  S)N)r]   )r   gr:   r:   r;   r     s    )rC   rD   rh   r   r   r   r?   r\   r   r   __parameters__r   r@   r   	__extra__r   __next_in_mro__)rE   rF   rG   rH   rQ   rK   originextrarJ   ZgvarsbaseZtvarset)rI   )r   r;   rD     sD    !(		#				zGenericMeta.__new__c             C   s&   |  j  r" |  j r" t |  j |  d  S)N)r   r   rR   )rJ   rQ   r:   r:   r;   rR     s    zGenericMeta._get_type_varsc                s   |  j  d  k	 r! t |  j   } n t   j   } |  j r` | d d j d d   |  j D  7} |  j r | d d j d d   |  j D  7} | S)Nz[%s]z, c             s   s   |  ] } t  |  Vq d  S)N)rB   )r   r   r:   r:   r;   r     s    z'GenericMeta.__repr__.<locals>.<genexpr>z<%s>c             s   s   |  ] } t  |  Vq d  S)N)rB   )r   r   r:   r:   r;   r     s    )r   r|   rC   rT   r   r@   r   )rJ   r   )rI   r:   r;   rT     s    	!	!zGenericMeta.__repr__c             C   sd   t  | t  s t S|  j d  k	 rV |  j | j k oU |  j | j k oU |  j | j k S|  | k Sd  S)N)r\   r   r   r   r   r   )rJ   r   r:   r:   r;   r     s    zGenericMeta.__eq__c             C   s   t  |  j |  j f  S)N)r   r8   r   )rJ   r:   r:   r;   r     s    zGenericMeta.__hash__c                s  t  | t  s | f } | s4 t d t |     d   t   f d d   | D  } |  t k r t d d   | D  s t d   t t |   t |  k r t d   | } d  } n |  t k r | } d  } n |  j	 t t f k rt d t
 |     n |  j s+t d	 t
 |     t |  } t |  j  } | | k rt d
 | | k rjd n d t
 |   | | f   t |  } | } |  j |  j |  f |  j t |  j  d | d | d |  d |  j S)Nz)Parameter list to %s[...] cannot be emptyz*Parameters to generic types must be types.c             3   s   |  ] } t  |    Vq d  S)N)rn   )r   r   )r   r:   r;   r     s    z*GenericMeta.__getitem__.<locals>.<genexpr>c             s   s   |  ] } t  | t  Vq d  S)N)r\   r
   )r   r   r:   r:   r;   r     s    z5Parameters to Generic[...] must all be type variablesz-Parameters to Generic[...] must all be uniquez'Cannot subscript already-subscripted %sz%s is not a generic classz0Too %s parameters for %s; actual %s, expected %sZmanyZfewrQ   rK   r   r   )r\   rz   r?   r<   r   r   ry   r   	_Protocolr   r|   r   r   rI   r8   r   rm   r   r   )rJ   r   rQ   rK   ZalenZelenr:   )r   r;   r     sN    						.zGenericMeta.__getitem__c             C   s   |  j  | j  S)N)rt   rI   )rJ   r   r:   r:   r;   rp     s    zGenericMeta.__instancecheck__c                sj  | t  k r d St | t  r"|  j } | d  k	 r"| | j k r"t |  j  t | j  k sg t  t | j  t | j  k s t  x t |  j | j | j  D]s \ } } } t | t	  r| j
 r t | |  s
Pq| j r t | |  s
Pq| | k rPq | | k r Pq Wd St   j |  r8d S|  j d  k sVt | t  rZd St | |  j  S)NTF)r   r\   r   r   ry   r   r   rh   r   r
   r   rs   r   rC   rt   r   )rJ   rE   r   Zp_selfZp_clsZp_origin)rI   r:   r;   rt     s6    	$$		zGenericMeta.__subclasscheck__)r8   rS   r7   rU   rD   rR   rT   r   r   r   rp   rt   r:   r:   )rI   r;   r     s   3
.r   c               @   s(   e  Z d  Z d Z f  Z d d   Z d S)r   aI  Abstract base class for generic types.

    A generic type is typically declared by inheriting from an
    instantiation of this class with one or more type variables.
    For example, a generic mapping type might be defined as::

      class Mapping(Generic[KT, VT]):
          def __getitem__(self, key: KT) -> VT:
              ...
          # Etc.

    This class can then be used as follows::

      def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
          try:
              return mapping[key]
          except KeyError:
              return default
    c             O   sU   |  j  d  k r |  j j |   St |   } |  j j |  } | j | |   | Sd  S)N)r   r   rD   r   rM   )rE   rK   rL   r   ro   r:   r:   r;   rD   W  s    zGeneric.__new__N)r8   rS   r7   rU   rX   rD   r:   r:   r:   r;   r   @  s   c             C   s   | S)zCast a value to a type.

    This returns the value unchanged.  To the type checker this
    signals that the return value has the designated type, but at
    runtime we intentionally don't check anything (we want this
    to be as fast as possible).
    r:   )typvalr:   r:   r;   r+   a  s    c       
      C   s   |  j  } | j } | j } | d |  } |  j p7 f  } |  j } | rU t |  n i  } | t |  } xC t | | d  |  D]( \ } }	 | | k s t  |	 | | <q W| S)z:Internal helper to extract the default arguments, by name.N)	__code__co_argcountco_varnames__defaults____kwdefaults__rm   ry   r   rh   )
funcrk   Z	pos_countZ	arg_namesdefaultsZ
kwdefaultsZresZ
pos_offsetrF   valuer:   r:   r;   _get_defaultsl  s    				&r   c             C   s   t  |  d d  r i  S| d k rI t  |  d i   } | d k r[ | } n | d k r[ | } t |   } t |  j  } xw | j   D]i \ } } t | t  r t |  } t | | |  } | | k r | | d k r t	 | } | | | <q W| S)a>  Return type hints for a function or method object.

    This is often the same as obj.__annotations__, but it handles
    forward references encoded as string literals, and if necessary
    adds Optional[t] if a default value equal to None is set.

    BEWARE -- the behavior of globalns and localns is counterintuitive
    (unless you are familiar with how eval() and exec() work).  The
    search order is locals first, then globals.

    - If no dict arguments are passed, an attempt is made to use the
      globals from obj, and these are also used as the locals.  If the
      object does not appear to have globals, an exception is raised.

    - If one dict argument is passed, it is used for both globals and
      locals.

    - If two dict arguments are passed, they specify globals and
      locals, respectively.
    __no_type_check__N__globals__)
getattrr   rm   __annotations__itemsr\   r]   rY   rP   r   )ro   rN   rO   r   ZhintsrF   r   r:   r:   r;   r,   |  s$    	
c             C   sT   t  |  t  rG x> |  j j   D]! } t  | t j  r d | _ q Wn	 d |  _ |  S)a0  Decorator to indicate that annotations are not type hints.

    The argument must be a class or function; if it is a class, it
    applies recursively to all methods defined in that class (but not
    to methods defined in its superclasses or subclasses).

    This mutates the function(s) in place.
    T)r\   r}   r   valuesr   FunctionTyper   )rj   ro   r:   r:   r;   r.     s    		c                s%   t  j      f d d    } | S)zDecorator to give another decorator the @no_type_check effect.

    This wraps the decorator with something that wraps the decorated
    function in @no_type_check.
    c                 s     |  |   } t  |  } | S)N)r.   )rK   rL   r   )	decoratorr:   r;   wrapped_decorator  s    z2no_type_check_decorator.<locals>.wrapped_decorator)	functoolswraps)r   r   r:   )r   r;   r/     s    !c              O   s   t  d   d S)z*Helper for @overload to raise when called.zYou 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.N)NotImplementedError)rK   rL   r:   r:   r;   _overload_dummy  s    r   c             C   s   t  S)a
  Decorator for overloaded functions/methods.

    In a stub file, place two or more stub definitions for the same
    function in a row, each decorated with @overload.  For example:

      @overload
      def utf8(value: None) -> None: ...
      @overload
      def utf8(value: bytes) -> bytes: ...
      @overload
      def utf8(value: str) -> bytes: ...

    In a non-stub file (i.e. a regular .py file), do the same but
    follow it with an implementation.  The implementation should *not*
    be decorated with @overload.  For example:

      @overload
      def utf8(value: None) -> None: ...
      @overload
      def utf8(value: bytes) -> bytes: ...
      @overload
      def utf8(value: str) -> bytes: ...
      def utf8(value):
          # implementation goes here
    )r   )r   r:   r:   r;   r0     s    c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	_ProtocolMetaz~Internal metaclass for _Protocol.

    This exists so _Protocol classes can be generic without deriving
    from Generic.
    c             C   s   t  d   d  S)Nz+Protocols cannot be used with isinstance().)r?   )rJ   ro   r:   r:   r;   rp     s    z_ProtocolMeta.__instancecheck__c                sd   |  j  s t S|  t k r d S|  j   } x4 | D],   t   f d d   | j D  s0 d Sq0 Wd S)NTc             3   s   |  ] }   | j  k Vq d  S)N)r   )r   d)attrr:   r;   r     s    z2_ProtocolMeta.__subclasscheck__.<locals>.<genexpr>F)rV   r   r   _get_protocol_attrsr   r   )rJ   rE   attrsr:   )r   r;   rt     s    	"z_ProtocolMeta.__subclasscheck__c             C   sd  g  } x? |  j  D]4 } t | d d  r | j d k r | j |  q Wt   } x| D]} x | j j   D] } x |  j  D]5 } | | k	 r~ | | j k r~ t | d d  r~ Pq~ W| j d  rn | d k rn | d k rn | d k rn | d k rn | d k rn | d	 k rn | d
 k rn | d k rn | d k rn | d k rn | d k rn | j |  qn WqX W| S)NrV   Fr   _abc___abstractmethods__r   r   rX   r   r   r   r   r   rS   )	r   r   r8   r   r   r   keys
startswithadd)rJ   Zprotocol_basesr   r   r   r   r:   r:   r;   r     s2    !	z!_ProtocolMeta._get_protocol_attrsN)r8   rS   r7   rU   rp   rt   r   r:   r:   r:   r;   r     s   r   c               @   s"   e  Z d  Z d Z f  Z d Z d S)r   zInternal base class for protocol classes.

    This implements a simple-minded structural isinstance check
    (similar but more general than the one-offs in collections.abc
    such as Hashable).
    TN)r8   rS   r7   rU   rX   rV   r:   r:   r:   r;   r   *  s   r   c               @   s   e  Z d  Z f  Z d S)r   N)r8   rS   r7   rX   r:   r:   r:   r;   r   >  s   r   c               @   s   e  Z d  Z f  Z d S)r   N)r8   rS   r7   rX   r:   r:   r:   r;   r   F  s   c               @   s   e  Z d  Z f  Z d S)r   N)r8   rS   r7   rX   r:   r:   r:   r;   r   I  s   c               @   s   e  Z d  Z f  Z d S)r   N)r8   rS   r7   rX   r:   r:   r:   r;   r   R  s   c               @   s   e  Z d  Z f  Z d S)r   N)r8   rS   r7   rX   r:   r:   r:   r;   r   V  s   c               @   s1   e  Z d  Z f  Z e e d d d     Z d S)r"   )returnc             C   s   d  S)Nr:   )rJ   r:   r:   r;   __int__]  s    zSupportsInt.__int__N)r8   rS   r7   rX   r   intr   r:   r:   r:   r;   r"   Z  s   c               @   s1   e  Z d  Z f  Z e e d d d     Z d S)r!   )r   c             C   s   d  S)Nr:   )rJ   r:   r:   r;   	__float__e  s    zSupportsFloat.__float__N)r8   rS   r7   rX   r   floatr   r:   r:   r:   r;   r!   b  s   c               @   s1   e  Z d  Z f  Z e e d d d     Z d S)SupportsComplex)r   c             C   s   d  S)Nr:   )rJ   r:   r:   r;   __complex__m  s    zSupportsComplex.__complex__N)r8   rS   r7   rX   r   complexr  r:   r:   r:   r;   r  j  s   r  c               @   s1   e  Z d  Z f  Z e e d d d     Z d S)SupportsBytes)r   c             C   s   d  S)Nr:   )rJ   r:   r:   r;   	__bytes__u  s    zSupportsBytes.__bytes__N)r8   rS   r7   rX   r   bytesr  r:   r:   r:   r;   r  r  s   r  c               @   s1   e  Z d  Z f  Z e e d d d     Z d S)r    )r   c             C   s   d  S)Nr:   )rJ   r:   r:   r;   __abs__}  s    zSupportsAbs.__abs__N)r8   rS   r7   rX   r   r   r  r:   r:   r:   r;   r    z  s   c               @   s7   e  Z d  Z f  Z e d e e d d d    Z d S)r#   r   )ndigitsr   c             C   s   d  S)Nr:   )rJ   r  r:   r:   r;   	__round__  s    zSupportsRound.__round__N)r8   rS   r7   rX   r   r   r   r	  r:   r:   r:   r;   r#     s   c               @   s   e  Z d  Z f  Z d S)r   N)r8   rS   r7   rX   r:   r:   r:   r;   r     s   c               @   s1   e  Z d  Z f  Z e d d d d     Z d S)r   zIterator[T_co])r   c             C   s   d  S)Nr:   )rJ   r:   r:   r;   __reversed__  s    zReversible.__reversed__N)r8   rS   r7   rX   r   r
  r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z f  Z d S)r   N)r8   rS   r7   rX   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s       c               @   s   e  Z d  Z d d   Z d S)r&   c             O   s.   t  |  t  r t d   t j |  | |  S)Nz4Type List cannot be instantiated; use list() instead)r   r&   r?   r   rD   )rE   rK   rL   r:   r:   r;   rD     s    zList.__new__N)r8   rS   r7   rD   r:   r:   r:   r;   r&     s   c               @   s   e  Z d  Z d d   Z d S)r'   c             O   s.   t  |  t  r t d   t j |  | |  S)Nz2Type Set cannot be instantiated; use set() instead)r   r'   r?   r   rD   )rE   rK   rL   r:   r:   r;   rD     s    zSet.__new__N)r8   rS   r7   rD   r:   r:   r:   r;   r'     s   c                   s(   e  Z d  Z d Z   f d d   Z   S)_FrozenSetMetazThis metaclass ensures set is not a subclass of FrozenSet.

    Without this metaclass, set would be considered a subclass of
    FrozenSet, because FrozenSet.__extra__ is collections.abc.Set, and
    set is a subclass of that.
    c                s#   t  | t  r d St   j |  S)NF)rs   r'   rC   rt   )rJ   rE   )rI   r:   r;   rt     s    z _FrozenSetMeta.__subclasscheck__)r8   rS   r7   rU   rt   r:   r:   )rI   r;   r    s   r  c               @   s"   e  Z d  Z f  Z d d   Z d S)	FrozenSetc             O   s.   t  |  t  r t d   t j |  | |  S)Nz>Type FrozenSet cannot be instantiated; use frozenset() instead)r   r  r?   r   rD   )rE   rK   rL   r:   r:   r;   rD     s    zFrozenSet.__new__N)r8   rS   r7   rX   rD   r:   r:   r:   r;   r    s   r  c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   c               @   s   e  Z d  Z d S)r   N)r8   rS   r7   r:   r:   r:   r;   r     s   AbstractContextManagerc               @   s   e  Z d  Z f  Z d S)ContextManagerN)r8   rS   r7   rX   r:   r:   r:   r;   r    s   r  c               @   s   e  Z d  Z d d   Z d S)r$   c             O   s.   t  |  t  r t d   t j |  | |  S)Nz4Type Dict cannot be instantiated; use dict() instead)r   r$   r?   rm   rD   )rE   rK   rL   r:   r:   r;   rD     s    zDict.__new__N)r8   rS   r7   rD   r:   r:   r:   r;   r$     s   c               @   s   e  Z d  Z d d   Z d S)r%   c             O   s1   t  |  t  r t d   t j j |  | |  S)NzNType DefaultDict cannot be instantiated; use collections.defaultdict() instead)r   r%   r?   collectionsdefaultdictrD   )rE   rK   rL   r:   r:   r;   rD     s    zDefaultDict.__new__N)r8   rS   r7   rD   r:   r:   r:   r;   r%     s   c                   s(   e  Z d  Z f  Z   f d d   Z   S)r)   c                s1   t  |  t  r t d   t   j |  | |  S)Nz@Type Generator cannot be instantiated; create a subclass instead)r   r)   r?   rC   rD   )rE   rK   rL   )rI   r:   r;   rD   *  s    zGenerator.__new__)r8   rS   r7   rX   rD   r:   r:   )rI   r;   r)   &  s   CTr   c               @   s   e  Z d  Z d Z d S)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.
    N)r8   rS   r7   rU   r:   r:   r:   r;   r	   6  s   c             C   s   d d   | D } t  j |  d d   | D  } t |  | _ y% t j d  j j d d  | _ Wn t	 t
 f k
 r Yn X| S)a  Typed version of namedtuple.

    Usage::

        Employee = typing.NamedTuple('Employee', [('name', str), 'id', int)])

    This is equivalent to::

        Employee = collections.namedtuple('Employee', ['name', 'id'])

    The resulting class has one extra attribute: _field_types,
    giving a dict mapping field names to types.  (The field names
    are in the _fields attribute, which is part of the namedtuple
    API.)
    c             S   s"   g  |  ] \ } } | | f  q Sr:   r:   )r   nr   r:   r:   r;   r   _  s   	 zNamedTuple.<locals>.<listcomp>c             S   s   g  |  ] \ } } |  q Sr:   r:   )r   r  r   r:   r:   r;   r   `  s   	 r[   r8   __main__)r  
namedtuplerm   Z_field_typesr5   re   rf   getrS   AttributeErrorr   )typenameZfieldsrE   r:   r:   r;   r(   O  s    %c             C   s"   d d   } |  | _  | | _ | S)a%  NewType creates simple unique types with almost zero
    runtime overhead. NewType(name, tp) is considered a subtype of tp
    by static type checkers. At runtime, NewType(name, tp) returns
    a dummy function that simply returns its argument. Usage::

        UserId = NewType('UserId', int)

        def name_by_id(user_id: UserId) -> str:
            ...

        UserId('user')          # Fails type check

        name_by_id(42)          # Fails type check
        name_by_id(UserId(42))  # OK

        num = UserId(5) + 1     # type: int
    c             S   s   |  S)Nr:   )r9   r:   r:   r;   new_type}  s    zNewType.<locals>.new_type)r8   Z__supertype__)rF   r   r  r:   r:   r;   r-   j  s    		Fc               @   sg  e  Z d  Z d Z f  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	 d6 e e d d d    Z e	 e d d d     Z e	 d7 e e d d d    Z e	 d8 e e e d d d    Z e	 d e 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	 d1 d d2 d3     Z e	 d d d4 d5     Z d S)9IOa  Generic base class for TextIO and BinaryIO.

    This is an abstract, generic version of the return of open().

    NOTE: This does not distinguish between the different possible
    classes (text vs. binary, read vs. write vs. read/write,
    append-only, unbuffered).  The TextIO and BinaryIO subclasses
    below capture the distinctions between text vs. binary, which is
    pervasive in the interface; however we currently do not offer a
    way to track the other distinctions in the type system.
    )r   c             C   s   d  S)Nr:   )rJ   r:   r:   r;   mode  s    zIO.modec             C   s   d  S)Nr:   )rJ   r:   r:   r;   rF     s    zIO.nameNc             C   s   d  S)Nr:   )rJ   r:   r:   r;   close  s    zIO.closec             C   s   d  S)Nr:   )rJ   r:   r:   r;   closed  s    z	IO.closedc             C   s   d  S)Nr:   )rJ   r:   r:   r;   fileno  s    z	IO.filenoc             C   s   d  S)Nr:   )rJ   r:   r:   r;   flush  s    zIO.flushc             C   s   d  S)Nr:   )rJ   r:   r:   r;   isatty  s    z	IO.isattyr[   )r  r   c             C   s   d  S)Nr:   )rJ   r  r:   r:   r;   read  s    zIO.readc             C   s   d  S)Nr:   )rJ   r:   r:   r;   readable  s    zIO.readable)limitr   c             C   s   d  S)Nr:   )rJ   r#  r:   r:   r;   readline  s    zIO.readline)hintr   c             C   s   d  S)Nr:   )rJ   r%  r:   r:   r;   	readlines  s    zIO.readlinesr   )offsetwhencer   c             C   s   d  S)Nr:   )rJ   r'  r(  r:   r:   r;   seek  s    zIO.seekc             C   s   d  S)Nr:   )rJ   r:   r:   r;   seekable  s    zIO.seekablec             C   s   d  S)Nr:   )rJ   r:   r:   r;   tell  s    zIO.tell)sizer   c             C   s   d  S)Nr:   )rJ   r,  r:   r:   r;   truncate  s    zIO.truncatec             C   s   d  S)Nr:   )rJ   r:   r:   r;   writable  s    zIO.writable)sr   c             C   s   d  S)Nr:   )rJ   r/  r:   r:   r;   write  s    zIO.write)linesr   c             C   s   d  S)Nr:   )rJ   r1  r:   r:   r;   
writelines  s    zIO.writelinesz
IO[AnyStr]c             C   s   d  S)Nr:   )rJ   r:   r:   r;   	__enter__  s    zIO.__enter__c             C   s   d  S)Nr:   )rJ   r}   r   	tracebackr:   r:   r;   __exit__  s    zIO.__exit__r   r   r   ) r8   rS   r7   rU   rX   r   r]   r  rF   r   r  r   r  r   r  r  r   r*   r!  r"  r$  r&   r&  r)  r*  r+  r-  r.  r0  r2  r3  r5  r:   r:   r:   r;   r    sT   "!r  c               @   s_   e  Z d  Z d Z f  Z e e e e f e	 d d d     Z
 e d  d d d     Z d S)	BinaryIOz5Typed version of the return of open() in binary mode.)r/  r   c             C   s   d  S)Nr:   )rJ   r/  r:   r:   r;   r0    s    zBinaryIO.write)r   c             C   s   d  S)Nr:   )rJ   r:   r:   r;   r3    s    zBinaryIO.__enter__N)r8   rS   r7   rU   rX   r   r   r  	bytearrayr   r0  r3  r:   r:   r:   r;   r6    s   %r6  c               @   s   e  Z d  Z d Z f  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 e e d d d     Z e d  d d d     Z d S)TextIOz3Typed version of the return of open() in text mode.)r   c             C   s   d  S)Nr:   )rJ   r:   r:   r;   buffer   s    zTextIO.bufferc             C   s   d  S)Nr:   )rJ   r:   r:   r;   encoding  s    zTextIO.encodingc             C   s   d  S)Nr:   )rJ   r:   r:   r;   errors  s    zTextIO.errorsc             C   s   d  S)Nr:   )rJ   r:   r:   r;   line_buffering  s    zTextIO.line_bufferingc             C   s   d  S)Nr:   )rJ   r:   r:   r;   newlines  s    zTextIO.newlinesc             C   s   d  S)Nr:   )rJ   r:   r:   r;   r3    s    zTextIO.__enter__N)r8   rS   r7   rU   rX   r   r6  r9  r]   r:  r;  r   r<  r   r=  r   r3  r:   r:   r:   r;   r8    s   r8  c               @   s7   e  Z d  Z d Z d d d g Z e Z e Z e Z d S)ioz)Wrapper namespace for IO generic classes.r  r8  r6  N)r8   rS   r7   rU   __all__r  r8  r6  r:   r:   r:   r;   r>    s
   r>  z.ioPattern c             C   s   |  j  S)N)pattern)r   r:   r:   r;   <lambda>&  s    rC  Matchc             C   s
   |  j  j S)N)rerB  )mr:   r:   r;   rC  (  s    c               @   s.   e  Z d  Z d Z d d g Z e Z e Z d S)rE  z&Wrapper namespace for re type aliases.r@  rD  N)r8   rS   r7   rU   r?  r@  rD  r:   r:   r:   r;   rE  +  s   rE  z.re)|abcr   r   r  
contextlibr   rE  Z	stdlib_rer5   r   collections.abcr   ImportErrorr?  r<   r}   r=   rW   rY   ru   rR   r   rP   rn   rB   r   r   r
   r   r   r   r   r   r   r   r  r]   r*   r   r   r   r   r   r   r   r   r   r   r   ABCMetar   r   r+   r   r,   r.   r/   r   r0   r   r   r   hasattrr   r   r   r   r   r"   r!   r  r  r    r#   r   r   r   r'   r   r   r   r   r   r   r   r   register
memoryviewr   r&   r   r  r   r  r   r   r   r   r  r  r   rm   r$   r  r%   r)   Z_G_baseGeneratorTyper  r	   r(   r-   r1   r2   r  r6  r8  r>  r8   modulesr^   r@  matchrD  r:   r:   r:   r;   <module>   sl  	)	=M""^u"9"	X"["!)	=	&###&	#!#.)!!###	#	 	
&##)#		'	#`