AlkantarClanX12

Your IP : 18.191.97.229


Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/__pycache__/typing.cpython-35.pyc



��Yf9�D@sKddlZddlmZmZddlZddlZddlZddlZddlZddl	Z	yddl
jZWnek
r�ddlZYnXej
dd�ddfkr�ddlZy ddl	mZmZmZWnBek
r-eej�Zee�j�Zeej�ZYnXddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:g4Zd;d<�Zd=d>�ZGd?d@�d@e�ZGdAdB�dBdCedDdE�ZGdFdG�dGedDdE�ZGdHdI�dIedDdE�ZGdJdK�dKedDdE�ZdLdM�Z dNdO�Z!dPdQ�Z"dRdS�Z#dTdU�Z$GdVdW�dWedDdE�Z%e%dDdE�Z&GdXdY�dYedDdE�Z'e'dDdE�Z(GdZd�dedDdE�Z)e)d[�Z*e)d\�Z+e)d]�Z,e)d^d_dE�Z-e)d`d_dE�Z.e)dad_dE�Z/e)dbdcdE�Z0e)d2e1e�Z2ddde�Z3dddfdg�Z4dhdi�Z5djdk�Z6gZ7dldm�Z8Gdndo�doedDdE�Z9e9dDdE�Z:Gdpdq�dqedDdE�Z;e;dDdE�Z<drds�Z=dtdu�Z>dvdw�Z?dxdy�Z@dzd{�ZAGd|d�deejB�ZCdZDd}d~�ZEGdd
�d
dCeC�ZDGd�d��d��ZFGd�d��d��ZGGd�d��d�eC�ZHGd�d�deId�eIdCeH�ZJGd�d��d�eC�ZKGd�d�dd�ejLdCeK�ZLGd�d��d�edDdE�ZMeMdDdE�ZNd�d3�ZOd�d��ZPe	jQe	jRe	jSe	jTeeefZUddd�d4�ZVd�d6�ZWd�d7�ZXd�d��ZYd�d8�ZZGd�d��d�eC�Z[Gd�d��d�dCe[�Z\ej]Z]e^ed��rwGd�d��d�eDe-d�ej_�Z_ej`d��e^ed��r�Gd�d��d�e_e.eDe-e0e.fd�eja�Zaej`d��e^ed��r5Gd�d��d�eDe-d�ejb�ZbGd�d��d�ebe-d�ejc�Zcej`d��ej`d��Gd�d�deDe-d�ejd�ZdGd�d�dede-d�eje�ZeGd�d'�d'e\�ZfGd�d&�d&e\�ZgGd�d%�d%e\�ZhGd�d$�d$e\�ZiGd�d#�d#e\e-�ZjGd�d(�d(e\e-�Zke^ed"�r<Gd�d"�d"ede-d�ejl�ZlnGd�d"�d"e\e-�ZlejmZmGd�d�deDe-d�ejn�Zne^ed��r�Gd�d��d�emede-ene-d�ejo�Zoej`d��e^ed��r	Gd�d�deoe-d�ejp�Zqn-Gd�d�demede-ene-d�ejp�ZqGd�d�deqe*d�ejr�Zre^ed��r�	Gd�d�deoe+eDe+e/fd�ejs�Zsn:Gd�d�demede+ene+eDe+e/fd�ejs�ZsGd�d�dese+e,fd�ejt�Zte^ed"�rp
e^ed��r@
Gd�d�dele-eoe-d�eju�Zun-Gd�d�demele-ene-d�eju�Zun-Gd�d�demede-ene-d�eju�ZuGd�d�deue*d�ejv�ZvGd�d�deuewd�ejx�ZxGd�d-�d-eyeve*d�ey�ZzGd�d*�d*ej{eve*d�ej{�Z|Gd�d.�d.e}ere*d�e}�ZpGd�d/�d/e~eqe-d�e~�ZGd�d�demede-d�ej��Z�Gd�d�de�e+eqe+d�ej��Z�Gd�d�de�eJe+e/feqeJe+e/feDe+e/fd�ej��Z�Gd�d!�d!e�e/d�ej��Z�e^ed��rhGd�d�deDe-d�ej��Z�nGd�d�deDe-�Z�e^ed��r�Gd�d��d�eDe-d�ej��Z�ej`d��n)ej
dd�dd�fkr�e�d��Gd�d+�d+e�ete+e,fd�e��Z�Gd�d,�d,ej�ete+e,fd�ej��Z�Gd�d)�d)ej�e�e*ewfd�ej��Z�e^ed��r�
ej`d��Gd�d��d�ej�ete+e,fd�ej��Z�e^ed1�r�
ej�Z�n	e	j�Z�Gd�d1�d1eee-eDe-e0e.fd�e��Z�e^ed��r_Gd�d��d�ece-eDe-e0fd�ej��Z�ej`d��e)d�d_dEd�e�Z�Gd�d
�d
eDe�d�e�Z�d�d��Z�ej
dd�ddfkZ�d�d�d�d�d�d�d�d�d�d�d�fZ�d�d�d�d�fZ�Gd�d��d�e�Z�Gd�d0�d0dCe��Z�d�d5�Z�eZ�d�Z�Gd�d��d�eDe2�Z�Gd�d��d�e�e1�Z�Gd�d��d�e�e�Z�Gd�d��d��Z�e�d�e�_�e�ej�e�j�<ed�e2eej�d���d�d���Z�ed�e2eej�d�d���d�d���Z�Gd�d��d��Ze�d�e_�eej�ej�<dS)��N)�abstractmethod�abstractproperty���)�WrapperDescriptorType�MethodWrapperType�MethodDescriptorType�Any�Callable�ClassVar�Generic�Optional�Tuple�Type�TypeVar�Union�AbstractSet�GenericMeta�
ByteString�	Container�ContextManager�Hashable�	ItemsView�Iterable�Iterator�KeysView�Mapping�MappingView�MutableMapping�MutableSequence�
MutableSet�Sequence�Sized�
ValuesView�
Reversible�SupportsAbs�
SupportsBytes�SupportsComplex�
SupportsFloat�SupportsInt�
SupportsRound�Counter�Deque�Dict�DefaultDict�List�Set�	FrozenSet�
NamedTuple�	Generator�AnyStr�cast�get_type_hints�NewType�
no_type_check�no_type_check_decorator�overload�Text�
TYPE_CHECKINGcCs+tjdd�dkr |jS|jSdS)Nrr)rr)�sys�version_info�__qualname__�__name__)�x�rC�+/opt/alt/python35/lib64/python3.5/typing.py�	_qualnamegsrEcCs5d}|jd�r1||kr1|dd�}|S)N�
_TypeAlias�_ForwardRef�_TypingBase�_FinalTypingBase�_�)rFrGrHrI)�
startswith)ZnmZ	whitelistrCrCrD�
_trim_nameosrMcsdeZdZdZdZdd�fdd�Zdd�Zdd	�Zd
d�Zdd
�Z	�S)�
TypingMetaa�Metaclass for most types defined in typing module
    (not a part of public API).

    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 must pass _root=True.

    This also defines a dummy constructor (all the work for most typing
    constructs is done in __new__) and a nicer repr().
    F�_rootcsG|s.tddjtt|��p'd��t�j||||�S)NzCannot subclass %sz, z())�	TypeError�join�map�
_type_repr�super�__new__)�cls�name�bases�	namespacerO)�	__class__rCrDrU�s"zTypingMeta.__new__cOsdS)NrC)�self�args�kwdsrCrCrD�__init__�szTypingMeta.__init__cCs|S)a'Override this in subclasses to interpret forward references.

        For example, List['C'] is internally stored as
        List[_ForwardRef('C')], which should evaluate to List[C],
        where C is an object found in globalns or localns (searching
        localns first, of course).
        rC)r[�globalns�localnsrCrCrD�
_eval_type�szTypingMeta._eval_typecCsdS)NrC)r[�tvarsrCrCrD�_get_type_vars�szTypingMeta._get_type_varscCs#tt|��}d|j|fS)Nz%s.%s)rMrE�
__module__)r[�qnamerCrCrD�__repr__�szTypingMeta.__repr__)
rArdr@�__doc__�_is_protocolrUr^rarcrfrCrC)rZrDrNvs
rNcsjeZdZdZdZdd�Z�fdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
�S)rHz0Internal indicator of special typing constructs.�__weakref__cOsdS)NrC)r[r\r]rCrCrDr^�sz_TypingBase.__init__csXt|�dkrHt|dt�rHt|dt�rHtd|��t�j|�S)z�Constructor.

        This only exists to give a better error message in case
        someone tries to subclass a special typing object (not a good idea).
        rrrKzCannot subclass %r)�len�
isinstance�str�tuplerPrTrU)rVr\r])rZrCrDrU�s
z_TypingBase.__new__cCs|S)NrC)r[r_r`rCrCrDra�sz_TypingBase._eval_typecCsdS)NrC)r[rbrCrCrDrc�sz_TypingBase._get_type_varscCs/t|�}tt|��}d|j|fS)Nz%s.%s)�typerMrErd)r[rVrerCrCrDrf�sz_TypingBase.__repr__cOstdt|���dS)NzCannot instantiate %r)rPrn)r[r\r]rCrCrD�__call__�sz_TypingBase.__call__)ri)rArdr@rg�	__slots__r^rUrarcrfrorCrC)rZrDrH�srH�	metaclassrOTcs@eZdZdZfZdd�fdd�Zdd�Z�S)rIz�Internal mix-in class to prevent instantiation.

    Prevents instantiation unless _root=True is given in class call.
    It is used to create pseudo-singleton instances Any, Union, Optional, etc.
    rOFcs<t�j|||�}|dkr(|Std|��dS)NTzCannot instantiate %r)rTrUrP)rVrOr\r]r[)rZrCrDrU�sz_FinalTypingBase.__new__cCstt|�j�S)N)rMrnrA)r[rCrCrD�
__reduce__�sz_FinalTypingBase.__reduce__)rArdr@rgrprUrrrCrC)rZrDrI�srIcsveZdZdZdZ�fdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Z�S)rGz-Internal wrapper to hold a forward reference.�__forward_arg__�__forward_code__�__forward_evaluated__�__forward_value__cs�t�j|�t|t�s2td|f��yt|dd�}Wn%tk
rotd|f��YnX||_||_d|_	d|_
dS)Nz,Forward reference must be a string -- got %rz<string>�evalz1Forward reference must be an expression -- got %rF)rTr^rkrlrP�compile�SyntaxErrorrsrtrurv)r[�arg�code)rZrCrDr^�s
			z_ForwardRef.__init__cCs�|js||k	r�|dkr;|dkr;i}}n'|dkrP|}n|dkrb|}tt|j||�d�|_d|_|jS)Nz*Forward references must evaluate to types.T)ru�_type_checkrwrtrv)r[r_r`rCrCrDra�s
		z_ForwardRef._eval_typecCs5t|t�stS|j|jko4|j|jkS)N)rkrG�NotImplementedrsrv)r[�otherrCrCrD�__eq__�sz_ForwardRef.__eq__cCst|j|jf�S)N)�hashrsrv)r[rCrCrD�__hash__sz_ForwardRef.__hash__cCstd��dS)Nz4Forward references cannot be used with isinstance().)rP)r[�objrCrCrD�__instancecheck__sz_ForwardRef.__instancecheck__cCstd��dS)Nz4Forward references cannot be used with issubclass().)rP)r[rVrCrCrD�__subclasscheck__sz_ForwardRef.__subclasscheck__cCsd|jfS)Nz_ForwardRef(%r))rs)r[rCrCrDrf	sz_ForwardRef.__repr__)rsrtrurv)rArdr@rgrpr^rarr�r�r�rfrCrC)rZrDrG�srGc@speZdZdZdZdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)rFa: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 cannot
    be used in instance and subclass checks in parameterized form, i.e.
    ``isinstance(42, Match[str])`` raises ``TypeError`` instead of returning
    ``False``.
    rW�type_var�	impl_type�type_checkercCs�t|t�s!tt|���t|t�sBtt|���t|t�sdtt|���t|ttf�s�tt|���||_||_||_	||_
dS)atInitializer.

        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)rkrl�AssertionError�reprrnrNrHrWr�r�r�)r[rWr�r�r�rCrCrDr^s!!"'			z_TypeAlias.__init__cCsd|jt|j�fS)Nz%s[%s])rWrSr�)r[rCrCrDrf,sz_TypeAlias.__repr__cCs�t|jt�s"td|��|jjrkt|t�rkt||jj�sktd||jf��t|t�r�||jk	r�td|��|j|j||j	|j
�S)Nz#%s cannot be further parameterized.z&%s is not a valid substitution for %s.z%s cannot be re-parameterized.)rkr�rrP�__constraints__rn�
issubclassrZrWr�r�)r[Z	parameterrCrCrD�__getitem__/sz_TypeAlias.__getitem__cCs5t|t�stS|j|jko4|j|jkS)N)rkrFr}rWr�)r[r~rCrCrDr;sz_TypeAlias.__eq__cCst|j|jf�S)N)r�rWr�)r[rCrCrDr�@sz_TypeAlias.__hash__cCs.t|jt�std��t||j�S)Nz<Parameterized type aliases cannot be used with isinstance().)rkr�rrPr�)r[r�rCrCrDr�Csz_TypeAlias.__instancecheck__cCs.t|jt�std��t||j�S)Nz<Parameterized type aliases cannot be used with issubclass().)rkr�rrPr�r�)r[rVrCrCrDr�Isz_TypeAlias.__subclasscheck__N)rWr�r�r�)rArdr@rgrpr^rfr�rr�r�r�rCrCrCrDrF
srFcCs@x9|D]1}t|t�s+t|t�r|j|�qWdS)N)rkrNrHrc)�typesrb�trCrCrDrcPs
rccCsg}t||�t|�S)N)rcrm)r�rbrCrCrD�
_type_varsVs
r�cCs2t|t�st|t�r.|j||�S|S)N)rkrNrHra)r�r_r`rCrCrDra\sracCs�|dkrtd�St|t�r1t|�}t|t�rUt|�jdksxt|ttf�r�t|�r�t|d|f��t|�jdkr�t|dd�s�t|t	�r�t
|�ttfkr�td|��|S)	a�Check that the argument is a type, and return it (internal helper).

    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).
    N�	_ClassVarz Got %.100r.�_Union�	_Optional�
__origin__z&Plain %s is not valid as type argument)r�r�)
rnrkrlrGrHrA�callablerP�getattrrN�_gorgr
�	_Protocol)rz�msgrCrCrDr|bs
$#'r|cCs�t|t�rOt|t�rO|jdkr8t|�Sd|jt|�fS|dkr_dSt|tj�rx|jSt|�S)a;Return the repr() of an object, special-casing types (internal helper).

    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.%s.z...)	rkrnrNrdrEr��FunctionTyperAr�)r�rCrCrDrS�s
rSc@s4eZdZdZfZdd�Zdd�ZdS)�_Anya`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.
    cCstd��dS)Nz%Any cannot be used with isinstance().)rP)r[r�rCrCrDr��sz_Any.__instancecheck__cCstd��dS)Nz%Any cannot be used with issubclass().)rP)r[rVrCrCrDr��sz_Any.__subclasscheck__N)rArdr@rgrpr�r�rCrCrCrDr��s
r�c@s4eZdZdZfZdd�Zdd�ZdS)�	_NoReturnaSpecial 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.
    cCstd��dS)Nz*NoReturn cannot be used with isinstance().)rP)r[r�rCrCrDr��sz_NoReturn.__instancecheck__cCstd��dS)Nz*NoReturn cannot be used with issubclass().)rP)r[rVrCrCrDr��sz_NoReturn.__subclasscheck__N)rArdr@rgrpr�r�rCrCrCrDr��sr�c	speZdZdZdZddd	d
dd
�fdd
�Zdd�Zdd�Zdd�Zdd�Z	�S)ra�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) -> List[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) and issubclass(C, T) will raise TypeError.

    Type variables defined with covariant=True or contravariant=True
    can be used do declare covariant or contravariant generic types.
    See PEP 484 for more details. By default generic types are invariant
    in all type variables.

    Type variables can be introspected. e.g.:

      T.__name__ == 'T'
      T.__constraints__ == ()
      T.__covariant__ == False
      T.__contravariant__ = False
      A.__constraints__ == (str, bytes)
    rA�	__bound__r��
__covariant__�__contravariant__�boundN�	covariantF�
contravariantc	s�t�j||d|d|d|�||_|rF|rFtd��t|�|_t|�|_|r�|dk	r�td��|r�t|�dkr�td��d�t	�fd	d
�|D��|_
|r�t|d�|_n	d|_dS)Nr�r�r�z"Bivariant types are not supported.z-Constraints cannot be combined with bound=...rKz"A single constraint is not allowedz:TypeVar(name, constraint, ...): constraints must be types.c3s|]}t|��VqdS)N)r|)�.0r�)r�rCrD�	<genexpr>sz#TypeVar.__init__.<locals>.<genexpr>zBound must be a type.)
rTr^rA�
ValueError�boolr�r�rPrjrmr�r|r�)r[rWr�r�r�Zconstraints)rZ)r�rDr^�s 
	"zTypeVar.__init__cCs||kr|j|�dS)N)�append)r[rbrCrCrDrcszTypeVar._get_type_varscCs5|jrd}n|jr$d}nd}||jS)N�+�-�~)r�r�rA)r[�prefixrCrCrDrf
s				zTypeVar.__repr__cCstd��dS)Nz0Type variables cannot be used with isinstance().)rP)r[�instancerCrCrDr�szTypeVar.__instancecheck__cCstd��dS)Nz0Type variables cannot be used with issubclass().)rP)r[rVrCrCrDr�szTypeVar.__subclasscheck__)rAr�r�r�r�)
rArdr@rgrpr^rcrfr�r�rCrC)rZrDr�s(		�T�KT�VT�T_cor��V_co�VT_co�T_contrar�cCs�|dkrg}t|d�rFt|ttf�rF|j||�St|t�r�x.t|�D] \}}||krb||SqbW|S)z�An internal helper function: replace arg if it is a type variable
    found in tvars with corresponding substitution from args or
    with corresponding substitution sub-tree if arg is a generic type.
    N�
_subs_tree)�hasattrrkrrHr�r�	enumerate)rzrbr\�iZtvarrCrCrD�_replace_arg)s$r�c	Cs�|jdkr|S|j}g}x)|jdk	rM|j|�|j}q%Wg}x*|jD]}|jt|||��q^WxJ|D]B}g}x-|jD]"}|jt||j|��q�W|}q�W|S)a�An internal helper function: calculate substitution tree
    for generic cls after replacing its type parameters with
    substitutions in tvars -> args (if any).
    Repeat the same following __origin__'s.

    Return a list of arguments with all possible substitutions
    performed. Arguments that are generic classes themselves are represented
    as tuples (so that no new classes are created by this function).
    For example: _subs_tree(List[Tuple[int, T]][str]) == [(Tuple, int, str)]
    N)r�r��__args__r��__parameters__)	rVrbr\ZcurrentZ
orig_chain�	tree_argsrzZoclsZ
new_tree_argsrCrCrDr�Ds 	


 
r�cs�g}x�|D]�}t|t�rD|jtkrD|j|j�q
t|t�r�t|�dkr�|dtkr�|j|dd��q
|j|�q
Wt	|��t��t|�krg}x4|D],}|�kr�|j|��j
|�q�W|}�st���t	|��xS|D]K�t�t�sEq-t
�fdd���hD��r-�j
��q-Wt�fdd�|D��S)z�An internal helper for Union creation and substitution: flatten Union's
    among parameters, then remove duplicates and strict subclasses.
    rrKNc3sK|]A}t|t�o$|jdk	st|t�oBt�|�VqdS)N)rkrr�rnr�)r�Zt2)�t1rCrDr��sz'_remove_dups_flatten.<locals>.<genexpr>c3s!|]}|�kr|VqdS)NrC)r�r�)�
all_paramsrCrDr��s)rkr�r�r�extendr�rmrjr��set�remover�rn�any)�
parameters�params�pZ
new_paramsr�rC)r�r�rD�_remove_dups_flattenes0
1


r�cCs~|jstdt|���t|�}t|j�}||krztd||kr^dndt|�||f��dS)Nz%s is not a generic classz0Too %s parameters for %s; actual %s, expected %sZmanyZfew)r�rPr�rj)rVr�ZalenZelenrCrCrD�_check_generic�s	r�csJtj����tj�j�tj����fdd��}|S)zInternal wrapper caching __getitem__ of generic types with a fallback to
    original function for non-hashable arguments.
    cs3y�||�SWntk
r%YnX�||�S)N)rP)r\r])�cached�funcrCrD�inner�s

z_tp_cache.<locals>.inner)�	functools�	lru_cache�	_cleanupsr��cache_clear�wraps)r�r�rC)r�r�rD�	_tp_cache�s$r�cs�eZdZdZdZdddd�fd	d
�Zdd�Zd
d�Z�fdd�Z�fdd�Z	e
dd��Zdddd�Zdd�Z
dd�Zdd�Zdd�Z�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

    - Similar for object::

        Union[int, object] == object

    - You cannot subclass or instantiate a union.

    - You can use Optional[X] as a shorthand for Union[X, None].
    r�r�r��
__tree_hash__NrOFcst�j||||d|�}|dkrad|_d|_d|_ttd��|_|St|t	�s|t
d��|tkr�t|�}t
|�dkr�|dSt|�|_||_||_|j�}t|t	�rtt|��|_nt|�|_|S)NrOrzExpected parameters=<tuple>rKr)r)rTrUr�r�r�r��	frozensetr�rkrmrPrr�rjr�r�)rVr��originrOr\r[Z	subs_tree)rZrCrDrU�s*!					z_Union.__new__cs�|jdkr|St��fdd�|jD��}t|j���}||jkro||jkro|S|j||dd�S)Nc3s!|]}t|���VqdS)N)ra)r�r�)r_r`rCrDr��sz$_Union._eval_type.<locals>.<genexpr>rOT)r�rmrar�rZ)r[r_r`�ev_args�	ev_originrC)r_r`rDra�s%z_Union._eval_typecCs&|jr"|jr"t|j|�dS)N)r�r�rc)r[rbrCrCrDrcsz_Union._get_type_varscsR|jdkrt�j�S|j�}t|t�sAt|�S|dj|�S)Nr)r�rTrfr�rkrmr��
_tree_repr)r[�tree)rZrCrDrfs

z_Union.__repr__cs~g}xW|dd�D]E}t|t�sB|jt|��q|j|dj|��qWt�j�ddj|�S)NrKrz[%s]z, )rkrmr�rSr�rTrfrQ)r[r��arg_listrz)rZrCrDr�
sz_Union._tree_reprcs�|fkrtd��t|t�s0|f}|jdkrHd�nd�t�fdd�|D��}|tk	r�t||�|j|d|dd�S)	Nz Cannot take a Union of no types.z)Union[arg, ...]: each arg must be a type.z*Parameters to generic types must be types.c3s|]}t|��VqdS)N)r|)r�r�)r�rCrDr� sz%_Union.__getitem__.<locals>.<genexpr>r�rOT)rPrkrmr�rr�rZ)r[r�rC)r�rDr�s		
z_Union.__getitem__cCsS|tkrtSt|||�}t|�}t|�dkrH|dStf|S)NrKr)rr�r�rj)r[rbr\r�rCrCrDr�%sz_Union._subs_treecCsIt|t�r|j|jkS|tk	r;|j�|kS||kSdS)N)rkr�r�rr�)r[r~rCrCrDr.s
z
_Union.__eq__cCs|jS)N)r�)r[rCrCrDr�6sz_Union.__hash__cCstd��dS)Nz(Unions cannot be used with isinstance().)rP)r[r�rCrCrDr�9sz_Union.__instancecheck__cCstd��dS)Nz(Unions cannot be used with issubclass().)rP)r[rVrCrCrDr�<sz_Union.__subclasscheck__)r�r�r�r�)rArdr@rgrprUrarcrfr�r�r�r�rr�r�r�rCrC)rZrDr��s*
		r�c@s.eZdZdZfZedd��ZdS)r�zEOptional type.

    Optional[X] is equivalent to Union[X, None].
    cCs#t|d�}t|td�fS)Nz#Optional[t] requires a single type.)r|rrn)r[rzrCrCrDr�Ksz_Optional.__getitem__N)rArdr@rgrpr�r�rCrCrCrDr�Csr�cCs8t|t�st�x|jdk	r3|j}qW|S)z@Return the farthest origin of a generic class (internal helper).N)rkrr�r�)�arCrCrDr�Ts
r�cCs:t|t�rt|t�s$t�t|�t|�kS)a6Return whether two generic classes are equivalent (internal helper).

    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.
    )rkrr�r�)r��brCrCrD�_geqv\s
$r�cCsft}xYt|jdd��D]>\}}t|t�r t|�tkr |j|d}q W|S)z�Helper for Generic.__new__.

    Returns the class after the last occurrence of Generic or
    Generic[...] in cls.__mro__.
    NrK���)�objectr��__mro__rkrr�r
)rVZnext_in_mror��crCrCrD�_next_in_mroks
&!r�cs@t�jtj�r*�fdd�}n�fdd�}|S)z�Construct a __subclasshook__ callable that incorporates
    the associated __extra__ class in subclass checks performed
    against cls.
    cs{�jj|�}|tk	r"|S�j|jkr8dSx<�jj�D]+}t|t�r`qHt||�rHdSqHWtS)NT)�	__extra__�__subclasshook__r}r��__subclasses__rkrr�)�subclass�res�scls)rVrCrD�
__extrahook__�sz)_make_subclasshook.<locals>.__extrahook__cs#�jrt|�j�rdStS)NT)r�r�r})r�)rVrCrDr��s)rkr��abc�ABCMeta)rVr�rC)rVrD�_make_subclasshookysr�cCsAt|�}d|kr=x"|dD]}|j|d�q#W|S)z�Internal helper: copy class __dict__ and clean slots class variables.
    (They will be re-created if necessary by normal class machinery.)
    rpN)�dict�pop)ZdctZ	dict_copyZslotrCrCrD�_no_slots_copy�s
r�cs9eZdZdZddddd�fdd�Zedd��Zejdd��Zedd	��Zejd
d	��Zdd�Z	d
d�Z
�fdd�Z�fdd�Zdddd�Z
dd�Zdd�Zedd��Z�fdd�Zdd�Zdd �Z�fd!d"�Z�S)#racMetaclass for generic types.

    This is a metaclass for typing.Generic and generic ABCs defined in
    typing module. User defined subclasses of GenericMeta can override
    __new__ and invoke super().__new__. Note that GenericMeta.__new__
    has strict rules on what is allowed in its bases argument:
    * plain Generic is disallowed in bases;
    * Generic[...] should appear in bases at most once;
    * if Generic[...] is present, then it should list all type variables
      that appear in other bases.
    In addition, type of all generic bases is erased, e.g., C[int] is
    stripped to plain C.
    Nc	s�|dk	rF|dk	st�tdd�|D��s�t|��nI|dks^t|��|dksvt|��|dks�t|��t|�}d}	xe|D]]}
|
tkr�td��t|
t�r�|
jtkr�|	dk	r�td��|
j}	q�W|	dkr|}	nrt	|�}t	|	��|�ks�tddj
�fdd�|D��dj
d	d�|	D��f��|	}|}|dk	r�t|�tj
kr�||kr�|f|}td
d�|D��}tdd�|D��rtdd�|D��}|jd
|d|i�t�j||||dd�}
||
_|r|tdd�|D��nd|
_t|
�|
_|dkr�||
_d|kr�|s�t|
jdd�dkr�t|
�|
_t|tj
�r|j|
_|j|
_n$|dk	r6|j|
_|j|
_|rWt|d�rW|j|
_|rot|
j��ntt|
�j �|
_!|
S)z�Create a new generic class. GenericMeta.__new__ accepts
        keyword arguments that are used for internal bookkeeping, therefore
        an override should pass unused keyword arguments to super().
        Ncss|]}t|t�VqdS)N)rkr)r�r�rCrCrDr��sz&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, c3s'|]}|�krt|�VqdS)N)rl)r�r�)�gvarsetrCrDr��scss|]}t|�VqdS)N)rl)r��grCrCrDr��scss0|]&}t|t�r$t|�n|VqdS)N)rkrr�)r�r�rCrCrDr��scss*|] }t|t�o!|tk	VqdS)N)rkrr
)r�r�rCrCrDr��scss!|]}|tk	r|VqdS)N)r
)r�r�rCrCrDr��sr�r�rOTcss9|]/}|tkrdn|tkr-fn|VqdS).N)�_TypingEllipsis�_TypingEmpty)r�r�rCrCrDr��sr�rA�r�r@)"r��allr�r
rPrkrr�r�r�rQrnr�r�rmr��updaterTrUr�r��__next_in_mro__�__orig_bases__r�r�r��
_abc_registry�
_abc_cacher�r@r�r�r�r�)rVrWrXrYrbr\r��extra�
orig_basesZgvars�baseZtvarsetZ
initial_basesr[)rZ)r�rDrU�sl(
	
	#-
!	(	zGenericMeta.__new__cCs,t|jtj�r|jjSt|�jS)N)rkr�r�r��_abc_negative_cacher��_abc_generic_negative_cache)r[rCrCrDr�s
zGenericMeta._abc_negative_cachecCs@|jdkr<t|jtj�r3||j_n	||_dS)N)r�rkr�r�r�r�r�)r[�valuerCrCrDr�scCs,t|jtj�r|jjSt|�jS)N)rkr�r�r��_abc_negative_cache_versionr��#_abc_generic_negative_cache_version)r[rCrCrDr�s
z'GenericMeta._abc_negative_cache_versioncCs@|jdkr<t|jtj�r3||j_n	||_dS)N)r�rkr�r�r�r�r�)r[r�rCrCrDr�$scCs&|jr"|jr"t|j|�dS)N)r�r�rc)r[rbrCrCrDrc,szGenericMeta._get_type_varscs�|jr|jj���nd}|jrRt��fdd�|jD��nd}||jkrz||jkrz|S|j|j|jt|j�d|r�t	|�ndd|d|d|j
d|j�S)Nc3s!|]}t|���VqdS)N)ra)r�r�)r_r`rCrDr�3sz)GenericMeta._eval_type.<locals>.<genexpr>rbr\r�r�r�)r�rar�rmrZrA�	__bases__r��__dict__r�r�r�)r[r_r`r�r�rC)r_r`rDra0s$4	zGenericMeta._eval_typecs/|jdkrt�j�S|j|j��S)N)r�rTrfr�r�)r[)rZrCrDrf@s
zGenericMeta.__repr__cs�g}xs|dd�D]a}|fkr9|jd�qt|t�s^|jt|��q|j|dj|��qWt�j�ddj|�S)NrKz()rz[%s]z, )r�rkrmrSr�rTrfrQ)r[r�r�rz)rZrCrDr�EszGenericMeta._tree_reprcCs<|jdkr|St|||�}t|�ft|�S)N)r�r�r�rm)r[rbr\r�rCrCrDr�PszGenericMeta._subs_treecCsKt|t�stS|jdks1|jdkr;||kS|j|jkS)N)rkrr}r�r�)r[r~rCrCrDrVs

zGenericMeta.__eq__cCs|jS)N)r�)r[rCrCrDr�]szGenericMeta.__hash__cs�t|t�s|f}|rGt|�tk	rGtdt|���d�t�fdd�|D��}|tkr�tdd�|D��s�td��tt	|��t|�kr�td��|}|}n�|tt
fkr�t|�}|}nh|tkr|}|}nM|j
ttfkrFtdt|���nt||�t|�}|}|j
dkr}|fnf}|j|j||jt|j�d	|d
|d|d|jd
|j�S)Nz)Parameter list to %s[...] cannot be emptyz*Parameters to generic types must be types.c3s|]}t|��VqdS)N)r|)r�r�)r�rCrDr�hsz*GenericMeta.__getitem__.<locals>.<genexpr>css|]}t|t�VqdS)N)rkr)r�r�rCrCrDr�ksz5Parameters to Generic[...] must all be type variablesz-Parameters to Generic[...] must all be uniquez'Cannot subscript already-subscripted %srbr\r�r�r�)rkrmr�rrPrEr
r�rjr�rr�r�r�r�r�rZrArr�rr�r�)r[r�rbr\ZprependrC)r�rDr�`sJ						

	zGenericMeta.__getitem__csg|jdk	r;tjd�jddkr7td��dS|tkrWtd|��t�j|�S)	NrKrAr�r�zCParameterized generics cannot be used with class or instance checksFz5Class %r cannot be used with class or instance checks)r�r�)r�r>�	_getframe�	f_globalsrPr
rTr�)r[rV)rZrCrDr��s
zGenericMeta.__subclasscheck__cCst|j|�S)N)r�rZ)r[r�rCrCrDr��szGenericMeta.__instancecheck__c	Cs@|j|j|jt|j�|j|j|j|j|j	�S)N)
rZrArr�rr�r�r�r�r�)r[rCrCrD�__copy__�szGenericMeta.__copy__csl|jd�r|jd�s-|jd�rItt|�j||�nttt|��j||�dS)N�__�_abc_)rL�endswithrTr�__setattr__r�)r[�attrr�)rZrCrDr�szGenericMeta.__setattr__)rArdr@rgrU�propertyr��setterr�rcrarfr�r�rr�r�r�r�r�rrrCrC)rZrDr�s$
!^.cOsq|jdkr|j|�St|�}|j|�}y
||_Wntk
rXYnX|j||�|SdS)N)r�rUr�Z__orig_class__�AttributeErrorr^)Zbase_clsrVr\r]r�r�rCrCrD�_generic_new�s


r
c@s(eZdZdZfZdd�ZdS)r
aCAbstract base class for generic types.

    A generic type is typically declared by inheriting from
    this class parameterized 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
    cOs1t|t�rtd��t|j|||�S)NzHType Generic cannot be instantiated; it can be used only as a base class)r�r
rPr
r�)rVr\r]rCrCrDrU�szGeneric.__new__N)rArdr@rgrprUrCrCrCrDr
�sc@seZdZdZdS)r�z�Internal placeholder for () or []. Used by TupleMeta and CallableMeta
    to allow empty list/tuple in specific places, without allowing them
    to sneak in where prohibited.
    N)rArdr@rgrCrCrCrDr��sr�c@seZdZdZdS)r�z(Internal placeholder for ... (ellipsis).N)rArdr@rgrCrCrCrDr��sr�csFeZdZdZe�fdd��Zdd�Zdd�Z�S)�	TupleMetazMetaclass for Tuple (internal).cs�|jdk	st|t�r/t�j|�S|fkrNt�jtf�St|t�sf|f}t|�dkr�|ddkr�d�t	|d��}t�j|t
f�Sd�t�fdd�|D��}t�j|�S)	NrrK.z Tuple[t, ...]: t must be a type.rz*Tuple[t0, t1, ...]: each t must be a type.c3s|]}t|��VqdS)N)r|)r�r�)r�rCrDr�sz(TupleMeta.__getitem__.<locals>.<genexpr>)r�r�rrTr�r�rkrmrjr|r�)r[r�r�)rZ)r�rDr��s	"zTupleMeta.__getitem__cCs,|jdkrt|t�Std��dS)Nz5Parameterized Tuple cannot be used with isinstance().)r�rkrmrP)r[r�rCrCrDr�s
zTupleMeta.__instancecheck__cCs,|jdkrt|t�Std��dS)Nz5Parameterized Tuple cannot be used with issubclass().)r�r�rmrP)r[rVrCrCrDr�
s
zTupleMeta.__subclasscheck__)rArdr@rgr�r�r�r�rCrC)rZrDr�src@s(eZdZdZfZdd�ZdS)ra@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, ...].
    cOs.t|t�rtd��tt|||�S)Nz6Type Tuple cannot be instantiated; use tuple() instead)r�rrPr
rm)rVr\r]rCrCrDrUsz
Tuple.__new__N)rArdr@rgrprUrCrCrCrDrsr�csdeZdZdZ�fdd�Z�fdd�Z�fdd�Ze�fdd	��Z�S)
�CallableMetaz"Metaclass for Callable (internal).cs/|jdkrt�j�S|j|j��S)N)r�rTrfr�r�)r[)rZrCrDrf's
zCallableMeta.__repr__cs�t|�tk	r"t�j|�Sg}xW|dd�D]E}t|t�sd|jt|��q9|j|dj|��q9W|ddkr�t|d�d|dSt|d�ddj	|dd��|dfS)	NrKrz...z	[..., %s]z
[[%s], %s]z, r�r�)
r�rrTr�rkrmr�rSr�rQ)r[r�r�rz)rZrCrDr�,s
zCallableMeta._tree_reprcs�|jdk	st|t�r/t�j|�St|t�sQt|�dkr]td��|\}}|t	kr�t	|f}n4t|t
�s�td|f��t|�|f}|j|�S)zxA thin wrapper around __getitem_inner__ to provide the latter
        with hashable arguments to improve speed.
        Nrz6Callable must be used as Callable[[arg, ...], result].z8Callable[args, result]: args must be a list. Got %.100r.)r�r�rrTr�rkrmrjrP�Ellipsis�list�__getitem_inner__)r[r�r\�result)rZrCrDr�<s"
zCallableMeta.__getitem__cs�|\}}d�t|��}|tkrCt�jt|f�Sd�t�fdd�|D��}||f}t�j|�S)Nz.Callable[args, result]: result must be a type.z6Callable[[arg, ...], result]: each arg must be a type.c3s|]}t|��VqdS)N)r|)r�rz)r�rCrDr�Xsz1CallableMeta.__getitem_inner__.<locals>.<genexpr>)r|rrTr�r�rm)r[r�r\r)rZ)r�rDrPs
zCallableMeta.__getitem_inner__)	rArdr@rgrfr�r�r�rrCrC)rZrDr$s
rc@s(eZdZdZfZdd�ZdS)ra�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.
    cOs1t|t�rtd��t|j|||�S)NzIType Callable cannot be instantiated; use a non-abstract subclass instead)r�rrPr
r�)rVr\r]rCrCrDrUjszCallable.__new__N)rArdr@rgrprUrCrCrCrDr]s	csmeZdZdZdZddd�Zdd�Zdd	�Z�fd
d�Zdd
�Z	dd�Z
�S)r�a3Special 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().
    �__type__NcKs
||_dS)N)r)r[�tpr]rCrCrDr^�sz_ClassVar.__init__cCspt|�}|jdkrJ|t|dj|jdd���dd�Stdj|jdd����dS)Nz{} accepts only single type.rKrOTz {} cannot be further subscripted)rnrr|�formatrArP)r[�itemrVrCrCrDr��s		z_ClassVar.__getitem__cCs>t|j||�}||jkr(|St|�|dd�S)NrOT)rarrn)r[r_r`Znew_tprCrCrDra�sz_ClassVar._eval_typecs>t�j�}|jdk	r:|djt|j��7}|S)Nz[{}])rTrfrrrS)r[�r)rZrCrDrf�sz_ClassVar.__repr__cCstt|�j|jf�S)N)r�rnrAr)r[rCrCrDr��sz_ClassVar.__hash__cCs<t|t�stS|jdk	r2|j|jkS||kS)N)rkr�r}r)r[r~rCrCrDr�s
z_ClassVar.__eq__)r)rArdr@rgrpr^r�rarfr�rrCrC)rZrDr�qs	r�cCs|S)z�Cast 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).
    rC)�typ�valrCrCrDr6�sc
Cs�y
|j}Wntk
r%iSYnX|j}|j}|d|�}|jpTf}|j}|rrt|�ni}|t|�}xCt||d�|�D](\}}	||ks�t	�|	||<q�W|S)z:Internal helper to extract the default arguments, by name.N)
�__code__r�co_argcount�co_varnames�__defaults__�__kwdefaults__r�rj�zipr�)
r�r{Z	pos_countZ	arg_names�defaultsZ
kwdefaultsr�Z
pos_offsetrWr�rCrCrD�
_get_defaults�s

				&r"c	Cst|dd�riS|dkrIt|di�}|dkr[|}n|dkr[|}t|t�ri}x�t|j�D]�}|jjdi�}xi|j�D][\}}|dkr�td�}t|t�r�t	|�}t
|||�}|||<q�Wq�W|St|dd�}|dkrUt|t�r@iStdj
|���t|�}t|�}x�|j�D]�\}}|dkr�td�}t|t�r�t	|�}t
|||�}||kr�||dkr�t|}|||<qzW|S)a}Return type hints for an 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.

    The argument may be a module, class, method, or function. The annotations
    are returned as a dictionary. For classes, annotations include also
    inherited members.

    TypeError is raised if the argument is not of a type that can contain
    annotations, and an empty dictionary is returned if no annotations are
    present.

    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__�__annotations__z1{!r} is not a module, class, method, or function.)r�rkrn�reversedr�r�get�itemsrlrGra�_allowed_typesrPrr"r�r)	r�r_r`Zhintsr�ZannrWr�r!rCrCrDr7�sL		
cCs�t|t�r�|jj�}x9|jj�D](\}}||jkr.|j|�q.WxH|j�D]:}t|tj	�r�d|_
t|t�rgt|�qgWy
d|_
Wntk
r�YnX|S)aIDecorator 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 and classes defined in that class
    (but not to methods defined in its superclasses or subclasses).

    This mutates the function(s) or class(es) in place.
    T)
rkrnr�copyr(rr��valuesr�r�r#r9rP)rzZ	arg_attrsr	rr�rCrCrDr9s		

cs%tj���fdd��}|S)z�Decorator to give another decorator the @no_type_check effect.

    This wraps the decorator with something that wraps the decorated
    function in @no_type_check.
    cs�||�}t|�}|S)N)r9)r\r]r�)�	decoratorrCrD�wrapped_decorator8sz2no_type_check_decorator.<locals>.wrapped_decorator)r�r�)r,r-rC)r,rDr:1s!cOstd��dS)z*Helper for @overload to raise when called.z�You 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)r\r]rCrCrD�_overload_dummyAsr/cCstS)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�rCrCrDr;Jscs@eZdZdZ�fdd�Zdd�Zdd�Z�S)�
_ProtocolMetaz~Internal metaclass for _Protocol.

    This exists so _Protocol classes can be generic without deriving
    from Generic.
    cs/t|jkrt�j|�Std��dS)Nz+Protocols cannot be used with isinstance().)r�rrTr�rP)r[r�)rZrCrDr�nsz_ProtocolMeta.__instancecheck__csd|js
tS|tkrdS|j�}x4|D],�t�fdd�|jD��s0dSq0WdS)NTc3s|]}�|jkVqdS)N)r)r��d)r	rCrDr��sz2_ProtocolMeta.__subclasscheck__.<locals>.<genexpr>F)rhr}r��_get_protocol_attrsr�r�)r[rV�attrsrC)r	rDr�ss	
"z_ProtocolMeta.__subclasscheck__cCs�g}x?|jD]4}t|dd�r|jdkr|j|�qWt�}x<|D]4}x+|jj�D]}x|jD]5}||k	r~||jkr~t|dd�r~Pq~W|jd�rn|dkrn|dkrn|dkrn|dkrn|dkrn|d	krn|d
krn|dkrn|dkrn|d
krn|dkrn|dkrn|dkrn|dkrn|dkrn|j|�qnWqXW|S)NrhFr�r�__abstractmethods__r%rirr�rpr2r�r�r�r�r�r�rd)	r�r�rAr�r�r�keysrL�add)r[Zprotocol_basesr�r3r�r	rCrCrDr2�s:!	
z!_ProtocolMeta._get_protocol_attrs)rArdr@rgr�r�r2rCrC)rZrDr0gsr0c@s"eZdZdZfZdZdS)r�z�Internal base class for protocol classes.

    This implements a simple-minded structural issubclass check
    (similar but more general than the one-offs in collections.abc
    such as Hashable).
    TN)rArdr@rgrprhrCrCrCrDr��sr��	Awaitablec@seZdZfZdS)r7N)rArdr@rprCrCrCrDr7�s�	Coroutinec@seZdZfZdS)r8N)rArdr@rprCrCrCrDr8�s�
AsyncIterablec@seZdZfZdS)r9N)rArdr@rprCrCrCrDr9�sc@seZdZfZdS)�
AsyncIteratorN)rArdr@rprCrCrCrDr:�sr:c@seZdZfZdS)rN)rArdr@rprCrCrCrDr�sc@seZdZfZdS)rN)rArdr@rprCrCrCrDr�sc@s1eZdZfZeeddd���ZdS)r*)�returncCsdS)NrC)r[rCrCrD�__int__�szSupportsInt.__int__N)rArdr@rpr�intr<rCrCrCrDr*�sc@s1eZdZfZeeddd���ZdS)r))r;cCsdS)NrC)r[rCrCrD�	__float__�szSupportsFloat.__float__N)rArdr@rpr�floatr>rCrCrCrDr)�sc@s1eZdZfZeeddd���ZdS)r()r;cCsdS)NrC)r[rCrCrD�__complex__�szSupportsComplex.__complex__N)rArdr@rpr�complexr@rCrCrCrDr(�sc@s1eZdZfZeeddd���ZdS)r')r;cCsdS)NrC)r[rCrCrD�	__bytes__�szSupportsBytes.__bytes__N)rArdr@rpr�bytesrBrCrCrCrDr'�sc@s1eZdZfZeeddd���ZdS)r&)r;cCsdS)NrC)r[rCrCrD�__abs__szSupportsAbs.__abs__N)rArdr@rprr�rDrCrCrCrDr&sc@s7eZdZfZedeeddd���ZdS)r+r)�ndigitsr;cCsdS)NrC)r[rErCrCrD�	__round__szSupportsRound.__round__N)rArdr@rprr=r�rFrCrCrCrDr+	sc@seZdZfZdS)r%N)rArdr@rprCrCrCrDr%sc@s1eZdZfZedddd���ZdS)r%zIterator[T_co])r;cCsdS)NrC)r[rCrCrD�__reversed__szReversible.__reversed__N)rArdr@rprrGrCrCrCrDr%sc@seZdZfZdS)rN)rArdr@rprCrCrCrDr s�
Collectionc@seZdZfZdS)rHN)rArdr@rprCrCrCrDrH%sc@seZdZfZdS)rN)rArdr@rprCrCrCrDr/sc@seZdZfZdS)rN)rArdr@rprCrCrCrDr3sc@seZdZfZdS)r!N)rArdr@rprCrCrCrDr!8sc@seZdZfZdS)rN)rArdr@rprCrCrCrDr>sc@seZdZfZdS)rN)rArdr@rprCrCrCrDrBsc@seZdZfZdS)rN)rArdr@rprCrCrCrDrGsc@seZdZfZdS)r"N)rArdr@rprCrCrCrDr"Msc@seZdZfZdS)r"N)rArdr@rprCrCrCrDr"Qsc@seZdZfZdS)r"N)rArdr@rprCrCrCrDr"Usc@seZdZfZdS)r N)rArdr@rprCrCrCrDr Zsc@seZdZfZdS)rN)rArdr@rprCrCrCrDr^sc@s"eZdZfZdd�ZdS)r0cOs.t|t�rtd��tt|||�S)Nz4Type List cannot be instantiated; use list() instead)r�r0rPr
r)rVr\r]rCrCrDrUfszList.__new__N)rArdr@rprUrCrCrCrDr0bsc@s"eZdZfZdd�ZdS)r-cOs5t|t�rtj||�Sttj|||�S)N)r�r-�collections�dequer
)rVr\r]rCrCrDrUqsz
Deque.__new__N)rArdr@rprUrCrCrCrDr-msc@s"eZdZfZdd�ZdS)r1cOs.t|t�rtd��tt|||�S)Nz2Type Set cannot be instantiated; use set() instead)r�r1rPr
r�)rVr\r]rCrCrDrU{szSet.__new__N)rArdr@rprUrCrCrCrDr1wsc@s"eZdZfZdd�ZdS)r2cOs.t|t�rtd��tt|||�S)Nz>Type FrozenSet cannot be instantiated; use frozenset() instead)r�r2rPr
r�)rVr\r]rCrCrDrU�szFrozenSet.__new__N)rArdr@rprUrCrCrCrDr2�sc@seZdZfZdS)rN)rArdr@rprCrCrCrDr�sc@seZdZfZdS)rN)rArdr@rprCrCrCrDr�sc@seZdZfZdS)rN)rArdr@rprCrCrCrDr�sc@seZdZfZdS)r$N)rArdr@rprCrCrCrDr$�s�AbstractContextManagerc@seZdZfZdS)rN)rArdr@rprCrCrCrDr�sc@sIeZdZfZdd�Zejdd��Zedd��Z	dS)rcCs|S)NrC)r[rCrCrD�	__enter__�szContextManager.__enter__cCsdS)NrC)r[�exc_type�	exc_value�	tracebackrCrCrD�__exit__�szContextManager.__exit__cCsL|tkrHtdd�|jD��rHtdd�|jD��rHdStS)Ncss|]}d|jkVqdS)rLN)r)r��BrCrCrDr��sz2ContextManager.__subclasshook__.<locals>.<genexpr>css|]}d|jkVqdS)rPN)r)r�rQrCrCrDr��sT)rr�r�r})rV�CrCrCrDr��s
zContextManager.__subclasshook__N)
rArdr@rprLr�rrP�classmethodr�rCrCrCrDr�s�AbstractAsyncContextManagerc@seZdZfZdS)�AsyncContextManagerN)rArdr@rprCrCrCrDrU�srU�a�
class AsyncContextManager(Generic[T_co]):
    __slots__ = ()

    async def __aenter__(self):
        return self

    @abc.abstractmethod
    async def __aexit__(self, exc_type, exc_value, traceback):
        return None

    @classmethod
    def __subclasshook__(cls, C):
        if cls is AsyncContextManager:
            if sys.version_info[:2] >= (3, 6):
                return _collections_abc._check_methods(C, "__aenter__", "__aexit__")
            if (any("__aenter__" in B.__dict__ for B in C.__mro__) and
                    any("__aexit__" in B.__dict__ for B in C.__mro__)):
                return True
        return NotImplemented

__all__.append('AsyncContextManager')
c@s"eZdZfZdd�ZdS)r.cOs.t|t�rtd��tt|||�S)Nz4Type Dict cannot be instantiated; use dict() instead)r�r.rPr
r�)rVr\r]rCrCrDrU�szDict.__new__N)rArdr@rprUrCrCrCrDr.�sc@s"eZdZfZdd�ZdS)r/cOs5t|t�rtj||�Sttj|||�S)N)r�r/rI�defaultdictr
)rVr\r]rCrCrDrU�szDefaultDict.__new__N)rArdr@rprUrCrCrCrDr/�sc@s"eZdZfZdd�ZdS)r,cOs5t|t�rtj||�Sttj|||�S)N)r�r,rIr
)rVr\r]rCrCrDrU�szCounter.__new__N)rArdr@rprUrCrCrCrDr,�s�ChainMapc@s"eZdZfZdd�ZdS)rXcOs5t|t�rtj||�Sttj|||�S)N)r�rXrIr
)rVr\r]rCrCrDrUszChainMap.__new__N)rArdr@rprUrCrCrCrDrXsc@s"eZdZfZdd�ZdS)r4cOs.t|t�rtd��tt|||�S)Nz@Type Generator cannot be instantiated; create a subclass instead)r�r4rPr
�_G_base)rVr\r]rCrCrDrUszGenerator.__new__N)rArdr@rprUrCrCrCrDr4s�AsyncGeneratorc@seZdZfZdS)rZN)rArdr@rprCrCrCrDrZ s�CT_cor�c@seZdZdZfZdS)ra�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)rArdr@rgrprCrCrCrDr,scs�d��fdd�|D�}tj|dd�|D��}tj|�|_|_y%tjd�jjdd�|_	Wnt
tfk
r�YnX|S)NzDNamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a typecs+g|]!\}}|t|��f�qSrC)r|)r��nr�)r�rCrD�
<listcomp>Is	z!_make_nmtuple.<locals>.<listcomp>cSsg|]\}}|�qSrCrC)r�r\r�rCrCrDr]Js	rrA�__main__)rI�
namedtuple�OrderedDictr%�_field_typesr>rrr'rdrr�)rWr��nm_tplrC)r�rD�
_make_nmtupleGs%rcrUr^rp�__getnewargs__�_fields�_field_defaultsra�_make�_replace�_asdict�_sourcerdrAr@r%cs"eZdZ�fdd�Z�S)�NamedTupleMetacsb|jdd�r+t�j||||�Sts=td��|jdi�}t||j��}g}i}xq|D]i}||kr�||}	|j|	�|	||<qw|rwtdjd|ddj	|j
�����qwWt|�|j_||_
x\|D]T}
|
tkr+td	|
��q|
tkr|
|jkrt||
||
�qW|S)
NrOFz<Class syntax for NamedTuple is only supported in Python 3.6+r%zXNon-default namedtuple field {field_name} cannot follow default field(s) {default_names}�
field_nameZ
default_namesz, z&Cannot overwrite NamedTuple attribute )r'rTrU�_PY36rPrcr(r�rrQr5rmrrf�_prohibitedr�_specialre�setattr)rV�typenamerX�nsr�rbr!Z
defaults_dictrlZ
default_value�key)rZrCrDrUas2



	
zNamedTupleMeta.__new__)rArdr@rUrCrC)rZrDrk_srkc@s+eZdZdZdZddd�ZdS)r3a4Typed version of namedtuple.

    Usage in Python versions >= 3.6::

        class Employee(NamedTuple):
            name: str
            id: int

    This is equivalent to::

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

    The resulting class has extra __annotations__ and _field_types
    attributes, giving an ordered dict mapping field names to types.
    __annotations__ should be preferred, while _field_types
    is kept to maintain pre PEP 526 compatibility. (The field names
    are in the _fields attribute, which is part of the namedtuple
    API.) Alternative equivalent keyword syntax is also accepted::

        Employee = NamedTuple('Employee', name=str, id=int)

    In Python versions <= 3.5 use::

        Employee = NamedTuple('Employee', [('name', str), ('id', int)])
    TNcKsS|rtrtd��|dkr4|j�}n|rFtd��t||�S)Nz>Keyword syntax for NamedTuple is only supported in Python 3.6+zIEither list of fields or keywords can be provided to NamedTuple, not both)rmrPr(rc)r[rqZfields�kwargsrCrCrDrU�s
zNamedTuple.__new__)rArdr@rgrOrUrCrCrCrDr3�scCs"dd�}||_||_|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
    cSs|S)NrC)rBrCrCrD�new_type�szNewType.<locals>.new_type)rAZ
__supertype__)rWrrurCrCrDr8�s		Fc@sgeZdZdZfZeeddd���Zeeddd���Ze	dddd	���Z
e	edd
d���Ze	e
ddd
���Ze	dddd���Ze	eddd���Ze	d6e
eddd���Ze	eddd���Ze	d7e
eddd���Ze	d8e
eeddd���Ze	de
e
e
dd d!���Ze	edd"d#���Ze	e
dd$d%���Ze	de
e
d&d'd(���Ze	edd)d*���Ze	ee
d+d,d-���Ze	eedd.d/d0���Ze	d1dd2d3���Ze	ddd4d5���ZdS)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;cCsdS)NrC)r[rCrCrD�mode�szIO.modecCsdS)NrC)r[rCrCrDrW�szIO.nameNcCsdS)NrC)r[rCrCrD�close�szIO.closecCsdS)NrC)r[rCrCrD�closed�sz	IO.closedcCsdS)NrC)r[rCrCrD�fileno�sz	IO.filenocCsdS)NrC)r[rCrCrD�flush�szIO.flushcCsdS)NrC)r[rCrCrD�isatty�sz	IO.isattyrK)r\r;cCsdS)NrC)r[r\rCrCrD�read�szIO.readcCsdS)NrC)r[rCrCrD�readable�szIO.readable)�limitr;cCsdS)NrC)r[rrCrCrD�readline�szIO.readline)�hintr;cCsdS)NrC)r[r�rCrCrD�	readlines	szIO.readlinesr)�offset�whencer;cCsdS)NrC)r[r�r�rCrCrD�seek	szIO.seekcCsdS)NrC)r[rCrCrD�seekable
	szIO.seekablecCsdS)NrC)r[rCrCrD�tell	szIO.tell)�sizer;cCsdS)NrC)r[r�rCrCrD�truncate	szIO.truncatecCsdS)NrC)r[rCrCrD�writable	szIO.writable)�sr;cCsdS)NrC)r[r�rCrCrD�write	szIO.write)�linesr;cCsdS)NrC)r[r�rCrCrD�
writelines	sz
IO.writelinesz
IO[AnyStr]cCsdS)NrC)r[rCrCrDrL"	szIO.__enter__cCsdS)NrC)r[rnr�rOrCrCrDrP&	szIO.__exit__r�r�r�) rArdr@rgrprrlrwrWrrxr�ryr=rzr{r|r5r}r~r�r0r�r�r�r�r�r�r�r�rLrPrCrCrCrDrv�sT"!rvc@s_eZdZdZfZeeeefe	ddd���Z
edddd���ZdS)	�BinaryIOz5Typed version of the return of open() in binary mode.)r�r;cCsdS)NrC)r[r�rCrCrDr�0	szBinaryIO.write)r;cCsdS)NrC)r[rCrCrDrL4	szBinaryIO.__enter__N)rArdr@rgrprrrC�	bytearrayr=r�rLrCrCrCrDr�+	s%r�c@s�eZdZdZfZeeddd���Zeeddd���Z	ee
eddd���Zeedd	d
���Z
eeddd���Zeddd
d���ZdS)�TextIOz3Typed version of the return of open() in text mode.)r;cCsdS)NrC)r[rCrCrD�buffer>	sz
TextIO.buffercCsdS)NrC)r[rCrCrD�encodingB	szTextIO.encodingcCsdS)NrC)r[rCrCrD�errorsF	sz
TextIO.errorscCsdS)NrC)r[rCrCrD�line_bufferingJ	szTextIO.line_bufferingcCsdS)NrC)r[rCrCrD�newlinesN	szTextIO.newlinescCsdS)NrC)r[rCrCrDrLR	szTextIO.__enter__N)rArdr@rgrprr�r�rlr�rr�r�r�r
r�rrLrCrCrCrDr�9	sr�c@s7eZdZdZdddgZeZeZeZdS)�ioz)Wrapper namespace for IO generic classes.rvr�r�N)rArdr@rg�__all__rvr�r�rCrCrCrDr�W	s
r�z.io�Patternr�cCs|jS)N)�pattern)r�rCrCrD�<lambda>e	sr��MatchcCs
|jjS)N)�rer�)�mrCrCrDr�g	sc@s.eZdZdZddgZeZeZdS)r�z&Wrapper namespace for re type aliases.r�r�N)rArdr@rgr�r�r�rCrCrCrDr�j	sr�z.re)�r�rrrI�
contextlibr�r�Z	stdlib_rer>r��collections.abcZcollections_abc�ImportErrorr?�_collections_abcrrr	rnr�r^�__str__rlrQr�rErMrNrHrIrGrFrcr�rar|rSr�r
r�ZNoReturnrr�r�r�r�r�r�r�rCr5r�r�r�r�r�r�r�rr�rr�r�r�r�r�r�rr
r
r�r�rrmrrrr�rr6r"r��BuiltinFunctionType�
MethodType�
ModuleTyper)r7r9r:r/r;r0r�rr�r7r�r8r9r:rrr*r)r(r'r&r+r%r#rrHr1rr!rrr"r r=rrr0rJr-r�r�r2rrrr$rKrrTrU�execr�r.rWr/r,rXr4rY�
GeneratorTyperZr[rrcrmrnrorkr3r8r<r=rvr�r�r�rA�modulesrxr��matchr�rCrCrCrD�<module>s�
 
	*%5CW!)��""9"6I	C	#
'
#

##&	#!
!#$.)!!###)
##
&#&)#
/

#	'	
$
 	!(`