AlkantarClanX12

Your IP : 3.138.135.4


Current Path : /lib64/python3.6/__pycache__/
Upload File :
Current File : //lib64/python3.6/__pycache__/typing.cpython-36.pyc

3


 \�9�D@s�ddlZddlmZmZddlZddlZddlZddlZddlZddl	Z	yddl
jZWnek
rrddlZYnXej
dd�d�kr�ddlZyddl	mZmZmZWn4e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�dBedCdD�ZGdEdF�dFedCdG�ZGdHdI�dIedCdG�ZGdJdK�dKedCdG�ZdLdM�Z dNdO�Z!dPdQ�Z"dRdS�Z#dTdU�Z$GdVdW�dWedCdG�Z%e%dCdG�Z&GdXdY�dYedCdG�Z'e'dCdG�Z(GdZd�dedCdG�Z)e)d[�Z*e)d\�Z+e)d]�Z,e)d^dCd_�Z-e)d`dCd_�Z.e)dadCd_�Z/e)dbdCdc�Z0e)d2e1e�Z2ddde�Z3d�dfdg�Z4dhdi�Z5djdk�Z6gZ7dldm�Z8Gdndo�doedCdG�Z9e9dCdG�Z:Gdpdq�dqedCdG�Z;e;dCdG�Z<drds�Z=dtdu�Z>dvdw�Z?Gdxd�deej@�ZAdZBdydz�ZCGd{d
�d
eAd|�ZBGd}d~�d~�ZDGdd��d��ZEGd�d��d�eA�ZFGd�d�deGeGeFd��ZHGd�d��d�eA�ZIGd�d�dejJeId��ZJGd�d��d�edCdG�ZKeKdCdG�ZLd�d3�ZMd�d��ZNe	jOe	jPe	jQe	jReeefZSd�d�d4�ZTd�d6�ZUd�d7�ZVd�d��ZWd�d8�ZXGd�d��d�eA�ZYGd�d��d�eYd|�ZZej[Z[e\ed���rjGd�d��d�eBe-ej]d��Z]ej^d��e\ed���r�Gd�d��d�e]e.eBe-e0e.fej_d��Z_ej^d��e\ed���r�Gd�d��d�eBe-ej`d��Z`Gd�d��d�e`e-ejad��Zaej^d��ej^d��Gd�d�deBe-ejbd��ZbGd�d�debe-ejcd��ZcGd�d'�d'eZ�ZdGd�d&�d&eZ�ZeGd�d%�d%eZ�ZfGd�d$�d$eZ�ZgGd�d#�d#eZe-�ZhGd�d(�d(eZe-�Zie\ed"��r�Gd�d"�d"ebe-ejjd��ZjnGd�d"�d"eZe-�ZjejkZkGd�d�deBe-ejld��Zle\ed���r*Gd�d��d�ekebe-ele-ejmd��Zmej^d��e\ed���rRGd�d�deme-ejnd��Zon"Gd�d�dekebe-ele-ejnd��ZoGd�d�deoe*ejpd��Zpe\ed���r�Gd�d�deme+eBe+e/fejqd��Zqn,Gd�d�dekebe+ele+eBe+e/fejqd��ZqGd�d�deqe+e,fejrd��Zre\ed"��rhe\ed���rDGd�d�deje-eme-ejsd��Zsn"Gd�d�dekeje-ele-ejsd��Zsn"Gd�d�dekebe-ele-ejsd��ZsGd�d�dese*ejtd��ZtGd�d�deseuejvd��ZvGd�d-�d-ewete*ewd��ZxGd�d*�d*ejyete*ejyd��ZzGd�d.�d.e{epe*e{d��ZnGd�d/�d/e|eoe-e|d��Z}Gd�d�dekebe-ej~d��Z~Gd�d�de~e+eoe+ejd��ZGd�d�de~eHe+e/feoeHe+e/feBe+e/fej�d��Z�Gd�d!�d!e~e/ej�d��Z�e\ed���r�Gd�d�deBe-ej�d��Z�nGd�d�deBe-�Z�e\edÃ�	r(Gd�dńd�eBe-ej�d��Z�ej^dŃnej
dd�d�k�	rDe�dǃGd�d+�d+e�ere+e,fe�d��Z�Gd�d,�d,ej�ere+e,fej�d��Z�Gd�d)�d)ej�e�e*eufej�d��Z�e\ed˃�	r�ej^d˃Gd�d˄d�ej�ere+e,fej�d��Z�e\ed1��	r�ej�Z�ne	j�Z�Gd�d1�d1ece-eBe-e0e.fe�d��Z�e\ed΃�
rVGd�d΄d�eae-eBe-e0fej�d��Z�ej^d΃e)d�dCedэZ�Gd�d
�d
eBe�ed��Z�d�dԄZ�ej
dd�d�kZ��dZ��dZ�Gd�d�d�e�Z�Gd�d0�d0e�d|�Z�d�d5�Z�eZ�d�Z�Gd�d�d�eBe2�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�/usr/lib64/python3.6/typing.py�	_qualnamegsrEcCs&d}|jd�r"||kr"|dd�}|S)N�
_TypeAlias�_ForwardRef�_TypingBase�_FinalTypingBase�_�)rFrGrHrI)�
startswith)ZnmZ	whitelistrCrCrD�
_trim_nameosrMcsJeZdZdZdZdd��fdd�
Zdd�Zdd	�Zd
d�Zdd
�Z	�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)�_rootcs2|s tddjtt|��pd��t�j||||�S)NzCannot subclass %sz, z())�	TypeError�join�map�
_type_repr�super�__new__)�cls�name�bases�	namespacerO)�	__class__rCrDrU�szTypingMeta.__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_varscCstt|��}d|j|fS)Nz%s.%s)rMrE�
__module__)r[�qnamerCrCrD�__repr__�szTypingMeta.__repr__)rArdr@�__doc__�_is_protocolrUr^rarcrf�
__classcell__rCrC)rZrDrNvs
rNcsLeZdZdZdZdd�Z�fdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
�ZS)rHz0Internal indicator of special typing constructs.�__weakref__cOsdS)NrC)r[r\r]rCrCrDr^�sz_TypingBase.__init__cs@t|�dkr4t|dt�r4t|dt�r4td|��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)rPro)r[r\r]rCrCrD�__call__�sz_TypingBase.__call__)rj)rArdr@rg�	__slots__r^rUrarcrfrprirCrC)rZrDrH�srHT)�	metaclassrOcs2eZdZdZfZdd��fdd�
Zdd�Z�ZS)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.
    F)rOcs0t�j|f|�|�}|dkr |Std|��dS)NTzCannot instantiate %r)rTrUrP)rVrOr\r]r[)rZrCrDrU�sz_FinalTypingBase.__new__cCstt|�j�S)N)rMrorA)r[rCrCrD�
__reduce__�sz_FinalTypingBase.__reduce__)rArdr@rgrqrUrsrirCrC)rZrDrI�srI)rOcsTeZdZdZdZ�fdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Z�ZS)rGz-Internal wrapper to hold a forward reference.�__forward_arg__�__forward_code__�__forward_evaluated__�__forward_value__cstt�j|�t|t�s$td|f��yt|dd�}Wn"tk
rVtd|f��YnX||_||_d|_	d|_
dS)Nz,Forward reference must be a string -- got %rz<string>�evalz1Forward reference must be an expression -- got %rF)rTr^rlrmrP�compile�SyntaxErrorrtrurvrw)r[�arg�code)rZrCrDr^�s
z_ForwardRef.__init__cCsf|js||k	r`|dkr*|dkr*i}}n|dkr8|}n|dkrD|}tt|j||�d�|_d|_|jS)Nz*Forward references must evaluate to types.T)rv�_type_checkrxrurw)r[r_r`rCrCrDra�s
z_ForwardRef._eval_typecCs&t|t�stS|j|jko$|j|jkS)N)rlrG�NotImplementedrtrw)r[�otherrCrCrD�__eq__�s
z_ForwardRef.__eq__cCst|j|jf�S)N)�hashrtrw)r[rCrCrD�__hash__sz_ForwardRef.__hash__cCstd��dS)Nz4Forward references cannot be used with isinstance().)rP)r[�objrCrCrD�__instancecheck__sz_ForwardRef.__instancecheck__cCstd��dS)Nz4Forward references cannot be used with issubclass().)rP)r[rVrCrCrD�__subclasscheck__sz_ForwardRef.__subclasscheck__cCsd|jfS)Nz_ForwardRef(%r))rt)r[rCrCrDrf	sz_ForwardRef.__repr__)rtrurvrw)
rArdr@rgrqr^rar�r�r�r�rfrirCrC)rZrDrG�srGc@sLeZdZdZdZdd�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_checkercCszt|t�stt|���t|t�s,tt|���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)rlrm�AssertionError�reprrorNrHrWr�r�r�)r[rWr�r�r�rCrCrDr^sz_TypeAlias.__init__cCsd|jt|j�fS)Nz%s[%s])rWrSr�)r[rCrCrDrf,sz_TypeAlias.__repr__cCs�t|jt�std|��|jjrJt|t�rJt||jj�sJtd||jf��t|t�rj||jk	rjtd|��|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.)rlr�rrP�__constraints__ro�
issubclassrZrWr�r�)r[Z	parameterrCrCrD�__getitem__/s
z_TypeAlias.__getitem__cCs&t|t�stS|j|jko$|j|jkS)N)rlrFr~rWr�)r[rrCrCrDr�;s
z_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().)rlr�rrPr�)r[r�rCrCrDr�Csz_TypeAlias.__instancecheck__cCs t|jt�std��t||j�S)Nz<Parameterized type aliases cannot be used with issubclass().)rlr�rrPr�r�)r[rVrCrCrDr�Isz_TypeAlias.__subclasscheck__N)rWr�r�r�)rArdr@rgrqr^rfr�r�r�r�r�rCrCrCrDrF
srFcCs0x*|D]"}t|t�st|t�r|j|�qWdS)N)rlrNrHrc)�typesrb�trCrCrDrcPs
rccCsg}t||�t|�S)N)rcrn)r�rbrCrCrD�
_type_varsVs
r�cCs$t|t�st|t�r |j||�S|S)N)rlrNrHra)r�r_r`rCrCrDra\sracCs�|dkrtd�St|t�r"t|�}t|t�r:t|�jdksTt|ttf�rft|�rft|d|f��t|�jdkr�t|dd�s�t|t	�r�|j
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�)
rorlrmrGrHrA�callablerP�getattrrN�_gorgr
�	_Protocol)r{�msgrCrCrDr}bs
r}cCs`t|t�r:t|t�r:|jdkr(t|�Sd|jt|�fS|dkrFdSt|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...)	rlrorNrdrEr��FunctionTyperAr�)r�rCrCrDrS�s
rSc@s$eZdZdZfZdd�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.
    cCstd��dS)Nz%Any cannot be used with isinstance().)rP)r[r�rCrCrDr��sz_Any.__instancecheck__cCstd��dS)Nz%Any cannot be used with issubclass().)rP)r[rVrCrCrDr��sz_Any.__subclasscheck__N)rArdr@rgrqr�r�rCrCrCrDr��s
r�c@s$eZdZdZfZdd�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.
    cCstd��dS)Nz*NoReturn cannot be used with isinstance().)rP)r[r�rCrCrDr��sz_NoReturn.__instancecheck__cCstd��dS)Nz*NoReturn cannot be used with issubclass().)rP)r[rVrCrCrDr��sz_NoReturn.__subclasscheck__N)rArdr@rgrqr�r�rCrCrCrDr��sr�csNeZdZdZdZdddd	��fd
d�
Zdd
�Zdd�Zdd�Zdd�Z	�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__NF)�bound�	covariant�
contravariantcs�t�j|f|�|||d��||_|r2|r2td��t|�|_t|�|_|rZ|dk	rZtd��|rrt|�dkrrtd��d�t	�fdd�|D��|_
|r�t|d	�|_nd|_dS)
N)r�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�rPrkrnr�r}r�)r[rWr�r�r�Zconstraints)rZ)r�rDr^�s 

zTypeVar.__init__cCs||kr|j|�dS)N)�append)r[rbrCrCrDrcszTypeVar._get_type_varscCs&|jrd}n|jrd}nd}||jS)N�+�-�~)r�r�rA)r[�prefixrCrCrDrf
szTypeVar.__repr__cCstd��dS)Nz0Type variables cannot be used with isinstance().)rP)r[�instancerCrCrDr�szTypeVar.__instancecheck__cCstd��dS)Nz0Type variables cannot be used with issubclass().)rP)r[rVrCrCrDr�szTypeVar.__subclasscheck__)rAr�r�r�r�)rArdr@rgrqr^rcrfr�r�rirCrC)rZrDr�s(	�T�KT�VT�T_co)r��V_co�VT_co�T_contra)r�cCsd|dkrg}t|d�r0t|ttf�r0|j||�St|t�r`x$t|�D]\}}||krD||SqDW|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)�hasattrrlrrHr�r�	enumerate)r{rbr\�iZtvarrCrCrD�_replace_arg)s
r�c	Cs�|jdkr|S|j}g}x|jdk	r6|j|�|j}qWg}x |jD]}|jt|||��qDWx8|D]0}g}x"|jD]}|jt||j|��qtW|}qdW|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_argsr{ZoclsZ
new_tree_argsrCrCrDr�Ds 



r�cs*g}xn|D]f}t|t�r0|jtkr0|j|j�q
t|t�rft|�dkrf|dtkrf|j|dd��q
|j|�q
Wt	|��t��t|�kr�g}x(|D] }|�kr�|j|��j
|�q�W|}�s�t���t	|��x>|D]6�t�t�s�q�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.
    rrKNc3s6|].}t|t�o|jdk	st|t�o,t�|�VqdS)N)rlrr�ror�)r�Zt2)�t1rCrDr��s
z'_remove_dups_flatten.<locals>.<genexpr>c3s|]}|�kr|VqdS)NrC)r�r�)�
all_paramsrCrDr��s)rlr�r�r�extendr�rnrkr��set�remover�ro�any)�
parameters�params�pZ
new_paramsr�rC)r�r�rD�_remove_dups_flattenes0
"



r�cCsX|jstdt|���t|�}t|j�}||krTtd||kr@dndt|�||f��dS)Nz%s is not a generic classz0Too %s parameters for %s; actual %s, expected %sZmanyZfew)r�rPr�rk)rVr�ZalenZelenrCrCrD�_check_generic�s
r�cs4tj����tj�j�tj����fdd��}|S)zInternal wrapper caching __getitem__ of generic types with a fallback to
    original function for non-hashable arguments.
    cs*y
�||�Stk
rYnX�||�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�eZdZdZdZd dd��fd	d
�Zdd�Zd
d�Z�fdd�Z�fdd�Z	e
dd��Zd!dd�Zdd�Z
dd�Zdd�Zdd�Z�ZS)"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__NF)rOcs�t�j|||f|�d|i�}|dkrHd|_d|_d|_ttd��|_|St|t	�sZt
d��|tkr~t|�}t
|�dkr~|dSt|�|_||_||_|j�}t|t	�r�tt|��|_n
t|�|_|S)NrOrzExpected parameters=<tuple>rKr)r)rTrUr�r�r�r��	frozensetr�rlrnrPrr�rkr�r�)rVr��originrOr\r[Z	subs_tree)rZrCrDrU�s*



z_Union.__new__cs^|jdkr|St��fdd�|jD��}t|j���}||jkrN||jkrN|S|j||dd�S)Nc3s|]}t|���VqdS)N)ra)r�r�)r_r`rCrDr��sz$_Union._eval_type.<locals>.<genexpr>T)rO)r�rnrar�rZ)r[r_r`�ev_args�	ev_originrC)r_r`rDra�s
z_Union._eval_typecCs|jr|jrt|j|�dS)N)r�r�rc)r[rbrCrCrDrcsz_Union._get_type_varscs<|jdkrt�j�S|j�}t|t�s.t|�S|dj|�S)Nr)r�rTrfr�rlrnr��
_tree_repr)r[�tree)rZrCrDrfs


z_Union.__repr__cs`g}xB|dd�D]2}t|t�s0|jt|��q|j|dj|��qWt�j�ddj|�S)NrKrz[%s]z, )rlrnr�rSr�rTrfrQ)r[r��arg_listr{)rZrCrDr�
s
z_Union._tree_reprcsl|fkrtd��t|t�s |f}|jdkr0d�nd�t�fdd�|D��}|tk	r\t||�|j||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>T)r�rO)rPrlrnr�rr�rZ)r[r�rC)r�rDr�s


z_Union.__getitem__cCs>|tkrtSt|||�}t|�}t|�dkr4|dStf|S)NrKr)rr�r�rk)r[rbr\r�rCrCrDr�%sz_Union._subs_treecCs6t|t�r|j|jkS|tk	r*|j�|kS||kSdS)N)rlr�r�rr�)r[rrCrCrDr�.s

z
_Union.__eq__cCs|jS)N)r�)r[rCrCrDr�6sz_Union.__hash__cCstd��dS)Nz(Unions cannot be used with isinstance().)rP)r[r�rCrCrDr�9sz_Union.__instancecheck__cCstd��dS)Nz(Unions cannot be used with issubclass().)rP)r[rVrCrCrDr�<sz_Union.__subclasscheck__)r�r�r�r�)NN)NN)rArdr@rgrqrUrarcrfr�r�r�r�r�r�r�r�rirCrC)rZrDr��s*
	
	r�c@s eZdZdZfZedd��ZdS)r�zEOptional type.

    Optional[X] is equivalent to Union[X, None].
    cCst|d�}t|td�fS)Nz#Optional[t] requires a single type.)r}rro)r[r{rCrCrDr�Ks
z_Optional.__getitem__N)rArdr@rgrqr�r�rCrCrCrDr�Csr�cCsJt}x@t|jdd��D]*\}}t|t�r|jtkr|j|d}qW|S)z�Helper for Generic.__new__.

    Returns the class after the last occurrence of Generic or
    Generic[...] in cls.__mro__.
    NrK���)�objectr��__mro__rlrr�r
)rVZnext_in_mror��crCrCrD�_next_in_mroTs
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.
    csZ�jj|�}|tk	r|S�j|jkr(dSx,�jj�D]}t|t�rDq4t||�r4dSq4WtS)NT)�	__extra__�__subclasshook__r~r��__subclasses__rlrr�)�subclass�res�scls)rVrCrD�
__extrahook__ks

z)_make_subclasshook.<locals>.__extrahook__cs�jrt|�j�rdStS)NT)r�r�r~)r�)rVrCrDr�ys)rlr��abc�ABCMeta)rVr�rC)rVrD�_make_subclasshookbsr�cCs2t|�}d|kr.x|dD]}|j|d�qW|S)z�Internal helper: copy class __dict__ and clean slots class variables.
    (They will be re-created if necessary by normal class machinery.)
    rqN)�dict�pop)ZdctZ	dict_copyZslotrCrCrD�_no_slots_copy�s
r�cs�eZdZdZd!�fdd�	Zedd��Zejdd��Zedd	��Zejd
d	��Zdd�Z	d
d�Z
�fdd�Z�fdd�Zd"dd�Z
dd�Zdd�Zedd��Z�fdd�Zdd�Z�fdd �Z�ZS)#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	r0|dk	st�tdd�|D��s.t|��n�|dks@t|��|dksPt|��|dks`t|��t|�}d}	xF|D]>}
|
tkr�td��t|
t�rr|
jtkrr|	dk	r�td��|
j}	qrW|	dkr�|}	nRt	|�}t	|	��|�k�stddj
�fdd�|D��dj
d	d�|	D��f��|	}|}|dk	�rFt|�tj
k�rF||k�rF|f|}td
d�|D��}tdd�|D���r~tdd�|D��}|j|||�s�dn|jd
��t�j||||dd�}
tt|
�jd|�s�|
n|j�||
_|�r�tdd�|D��nd|
_t|
�|
_|dk�r||
_d|k�r|�s2t|
jdd�dk�r<t|
�|
_t|tj
��r\|j|
_|j|
_n|dk	�rv|j|
_|j|
_|�r�t|d��r�|j|
_|�r�t |
j!��ntt|
�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)rlr)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)rm)r�r�)�gvarsetrCrDr��scss|]}t|�VqdS)N)rm)r��grCrCrDr��scss"|]}t|t�r|jn|VqdS)N)rlrr�)r��brCrCrDr��scss |]}t|t�o|tk	VqdS)N)rlrr
)r�r�rCrCrDr��scss|]}|tk	r|VqdS)N)r
)r�r�rCrCrDr��s)r�r�r�T)rOr�css*|]"}|tkrdn|tkrfn|VqdS).N)�_TypingEllipsis�_TypingEmpty)r��arCrCrDr��sr�rA�r�r@)$r��allr�r
rPrlrr�r�r�rQror�r�rnr��updater�rTrU�__setattr__r�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�sr




$





zGenericMeta.__new__cCst|jtj�r|jjS|jjS)N)rlr�r�r��_abc_negative_cacher��_abc_generic_negative_cache)r[rCrCrDr��szGenericMeta._abc_negative_cachecCs,|jdkr(t|jtj�r"||j_n||_dS)N)r�rlr�r�r�r�r�)r[�valuerCrCrDr�s

cCst|jtj�r|jjS|jjS)N)rlr�r�r��_abc_negative_cache_versionr��#_abc_generic_negative_cache_version)r[rCrCrDr�	sz'GenericMeta._abc_negative_cache_versioncCs,|jdkr(t|jtj�r"||j_n||_dS)N)r�rlr�r�r�r�r)r[r�rCrCrDr�s

cCs|jr|jrt|j|�dS)N)r�r�rc)r[rbrCrCrDrcszGenericMeta._get_type_varsc
s�|jr|jj���nd}|jr8t��fdd�|jD��nd}||jkrT||jkrT|S|j|j|jt|j�|rtt	|�nd|||j
|jd�S)Nc3s|]}t|���VqdS)N)ra)r�r�)r_r`rCrDr�sz)GenericMeta._eval_type.<locals>.<genexpr>)rbr\r�r�r�)r�rar�rnrZrA�	__bases__r��__dict__r�r�r�)r[r_r`r�r�rC)r_r`rDras$zGenericMeta._eval_typecs"|jdkrt�j�S|j|j��S)N)r�rTrfr�r�)r[)rZrCrDrf+s

zGenericMeta.__repr__cstg}xV|dd�D]F}|fkr*|jd�qt|t�sD|jt|��q|j|dj|��qWt�j�ddj|�S)NrKz()rz[%s]z, )r�rlrnrSr�rTrfrQ)r[r�r�r{)rZrCrDr�0s
zGenericMeta._tree_reprcCs*|jdkr|St|||�}|jft|�S)N)r�r�r�rn)r[rbr\r�rCrCrDr�;s
zGenericMeta._subs_treecCs6t|t�stS|jdks"|jdkr*||kS|j|jkS)N)rlrr~r�r�)r[rrCrCrDr�As

zGenericMeta.__eq__cCs|jS)N)r�)r[rCrCrDr�HszGenericMeta.__hash__c
s6t|t�s|f}|r0|jtk	r0tdt|���d�t�fdd�|D��}|tkr�tdd�|D��sltd��tt	|��t|�kr�td��|}|}nb|tt
fkr�t|�}|}nH|tkr�|}|}n6|j
ttfkr�tdt|���nt||�t|�}|}|j
dk�r|fnf}|j|j||jt|j�||||j|jd	�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�Ssz*GenericMeta.__getitem__.<locals>.<genexpr>css|]}t|t�VqdS)N)rlr)r�r�rCrCrDr�Vsz5Parameters to Generic[...] must all be type variablesz-Parameters to Generic[...] must all be uniquez'Cannot subscript already-subscripted %s)rbr\r�r�r�)rlrnr�rrPrEr
r�rkr�rr�r�r�r�r�rZrArr�rr�r�)r[r�rbr\ZprependrC)r�rDr�KsJ

zGenericMeta.__getitem__csJ|jdk	r*tjd�jddkr&td��dS|tkr>td|��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�ys
zGenericMeta.__subclasscheck__cCst|j|�S)N)r�rZ)r[r�rCrCrDr��szGenericMeta.__instancecheck__csT|jd�r|jd�s(|jd�s(|jdkr<tt|�j||�ntt|j�j||�dS)N�__�_abc_)rL�endswithr�rTrr�)r[�attrr�)rZrCrDr��s


zGenericMeta.__setattr__)NNNNN)NN)rArdr@rgrU�propertyr��setterr�rcrarfr�r�r�r�r�r�r�r�r�rirCrC)rZrDr�s"
`
.cOs�|jdkr@|jtjkr,|jtjk	r,|j|�S|j|f|�|�Snl|j}|jtjkrj|jtjk	rj|j|�}n|j|f|�|�}y
||_Wntk
r�YnX|j||�|SdS)N)r�rUr�r^r�Z__orig_class__�AttributeError)Zbase_clsrVr\r]r�r�rCrCrD�_generic_new�s 


rc@seZdZdZfZdd�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
    cOs&|jtkrtd��t|j|f|�|�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@rgrqrUrCrCrCrDr
�s)rrc@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��sr�c@seZdZdZdS)r�z(Internal placeholder for ... (ellipsis).N)rArdr@rgrCrCrCrDr��sr�cs4eZdZdZe�fdd��Zdd�Zdd�Z�ZS)�	TupleMetazMetaclass for Tuple (internal).cs�|jdk	s|jtk	r t�j|�S|fkr6t�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�rlrnrkr}r�)r[r�r�)rZ)r�rDr��s
zTupleMeta.__getitem__cCs |jdkrt|t�Std��dS)Nz5Parameterized Tuple cannot be used with isinstance().)r�rlrnrP)r[r�rCrCrDr��s

zTupleMeta.__instancecheck__cCs |jdkrt|t�Std��dS)Nz5Parameterized Tuple cannot be used with issubclass().)r�r�rnrP)r[rVrCrCrDr��s

zTupleMeta.__subclasscheck__)	rArdr@rgr�r�r�r�rirCrC)rZrDr
�sr
c@seZdZdZfZdd�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$|jtkrtd��tt|f|�|�S)Nz6Type Tuple cannot be instantiated; use tuple() instead)r�rrPrrn)rVr\r]rCrCrDrUs
z
Tuple.__new__N)rArdr@rgrqrUrCrCrCrDr�s)r�rrcsHeZdZdZ�fdd�Z�fdd�Z�fdd�Ze�fdd	��Z�Z	S)
�CallableMetaz"Metaclass for Callable (internal).cs"|jdkrt�j�S|j|j��S)N)r�rTrfr�r�)r[)rZrCrDrfs

zCallableMeta.__repr__cs�|jtk	rt�j|�Sg}xB|dd�D]2}t|t�sF|jt|��q(|j|dj|��q(W|ddkr�t|d�d|dSt|d�ddj	|dd��|dfS)	NrKrz...z	[..., %s]z
[[%s], %s]z, r�r�)
r�rrTr�rlrnr�rSr�rQ)r[r�r�r{)rZrCrDr�s


zCallableMeta._tree_reprcs�|jdk	s|jtk	r t�j|�St|t�s8t|�dkr@td��|\}}|t	krZt	|f}n$t|t
�srtd|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�rlrnrkrP�Ellipsis�list�__getitem_inner__)r[r�r\�result)rZrCrDr�*s


zCallableMeta.__getitem__cs^|\}}d�t|��}|tkr.t�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�r{)r�rCrDr�Fsz1CallableMeta.__getitem_inner__.<locals>.<genexpr>)r}rrTr�r�rn)r[r�r\r)rZ)r�rDr>s

zCallableMeta.__getitem_inner__)
rArdr@rgrfr�r�r�rrirCrC)rZrDrs
rc@seZdZdZfZdd�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.
    cOs&|jtkrtd��t|j|f|�|�S)NzIType Callable cannot be instantiated; use a non-abstract subclass instead)r�rrPrr�)rVr\r]rCrCrDrUXs
zCallable.__new__N)rArdr@rgrqrUrCrCrCrDrKs	csNeZdZdZdZddd�Zdd�Zdd	�Z�fd
d�Zdd
�Z	dd�Z
�ZS)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^rsz_ClassVar.__init__cCsPt|�}|jdkr4|t|dj|jdd���dd�Stdj|jdd����dS)Nz{} accepts only single type.rKT)rOz {} cannot be further subscripted)rorr}�formatrArP)r[�itemrVrCrCrDr�us
z_ClassVar.__getitem__cCs,t|j||�}||jkr|St|�|dd�S)NT)rO)rarro)r[r_r`Znew_tprCrCrDra~s
z_ClassVar._eval_typecs,t�j�}|jdk	r(|djt|j��7}|S)Nz[{}])rTrfrrrS)r[�r)rZrCrDrf�s

z_ClassVar.__repr__cCstt|�j|jf�S)N)r�rorAr)r[rCrCrDr��sz_ClassVar.__hash__cCs,t|t�stS|jdk	r$|j|jkS||kS)N)rlr�r~r)r[rrCrCrDr��s


z_ClassVar.__eq__)r)N)rArdr@rgrqr^r�rarfr�r�rirCrC)rZrDr�_s
	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
riSX|j}|j}|d|�}|jp@f}|j}|rTt|�ni}|t|�}x2t||d�|�D]\}}	||ks�t	�|	||<qxW|S)z:Internal helper to extract the default arguments, by name.N)
�__code__r�co_argcount�co_varnames�__defaults__�__kwdefaults__r�rk�zipr�)
r�r|Z	pos_countZ	arg_names�defaultsZ
kwdefaultsr�Z
pos_offsetrWr�rCrCrD�
_get_defaults�s

r!c
Cs�t|dd�riSt|t�r�i}x�t|j�D]z}|dkrFtj|jj}n|}|jj	di�}xJ|j
�D]>\}}|dkrztd�}t|t�r�t|�}t
|||�}|||<qbWq*W|S|dkr�t|tj�r�|j}nt|di�}|dkr�|}n|dkr�|}t|dd�}|dk�r"t|t��riStdj|���t|�}	t|�}xp|j
�D]d\}}|dk�rVtd�}t|t��rjt|�}t
|||�}||	k�r�|	|dk�r�t|}|||<�q<W|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 (or the respective module's globals for classes),
      and these are also used as the locals.  If the object does not appear
      to have globals, an empty dictionary is used.

    - 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�__annotations__�__globals__z1{!r} is not a module, class, method, or function.)r�rlro�reversedr�r>�modulesrdr�get�itemsrmrGrar��
ModuleType�_allowed_typesrPrr!r�r)
r�r_r`Zhintsr�Zbase_globalsZannrWr�r rCrCrDr7�sV



cCs�t|t�r||jj�}x0|jj�D]"\}}||j|fkr |j|�q Wx4|j�D](}t|tj	�rfd|_
t|t�rPt|�qPWy
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)
rlror�copyr(rr��valuesr�r�r"r9rP)r{Z	arg_attrsrrr�rCrCrDr9s	



cstj���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_decorator/s
z2no_type_check_decorator.<locals>.wrapped_decorator)r�r�)r-r.rC)r-rDr:(scOstd��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_dummy8sr0cCstS)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
    )r0)r�rCrCrDr;Ascs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�
_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�es
z_ProtocolMeta.__instancecheck__csL|js
tS|tkrdS|j�}x(|D] �t�fdd�|jD��s$dSq$WdS)NTc3s|]}�|jkVqdS)N)r)r��d)rrCrDr�wsz2_ProtocolMeta.__subclasscheck__.<locals>.<genexpr>F)rhr~r��_get_protocol_attrsr�r�)r[rV�attrsrC)rrDr�js
z_ProtocolMeta.__subclasscheck__cCs,g}x.|jD]$}t|dd�r|jdkr|j|�qWt�}�x�|D�]�}x�|jj�D]�}x�|jD]&}||k	r`||jkr`t|dd�r`Pq`W|jd�rT|dkrT|dkrT|dkrT|dkrT|dkrT|d	krT|d
krT|dkrT|dkrT|d
krT|dkrT|dkrT|dkrT|dkrT|dkrT|dkrT|j|�qTWqBW|S)NrhFr�r�__abstractmethods__r#rjr�rr�rqr3r�r�r�r�r�r�rd)	r�r�rAr�r�r�keysrL�add)r[Zprotocol_basesr�r4r�rrCrCrDr3{s<z!_ProtocolMeta._get_protocol_attrs)rArdr@rgr�r�r3rirCrC)rZrDr1^sr1c@seZdZdZfZdZdS)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@rgrqrhrCrCrCrDr��sr��	Awaitablec@seZdZfZdS)r8N)rArdr@rqrCrCrCrDr8�s)r��	Coroutinec@seZdZfZdS)r9N)rArdr@rqrCrCrCrDr9�s�
AsyncIterablec@seZdZfZdS)r:N)rArdr@rqrCrCrCrDr:�sc@seZdZfZdS)�
AsyncIteratorN)rArdr@rqrCrCrCrDr;�sr;c@seZdZfZdS)rN)rArdr@rqrCrCrCrDr�sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr�sc@s"eZdZfZeed�dd��ZdS)r*)�returncCsdS)NrC)r[rCrCrD�__int__�szSupportsInt.__int__N)rArdr@rqr�intr=rCrCrCrDr*�sc@s"eZdZfZeed�dd��ZdS)r))r<cCsdS)NrC)r[rCrCrD�	__float__�szSupportsFloat.__float__N)rArdr@rqr�floatr?rCrCrCrDr)�sc@s"eZdZfZeed�dd��ZdS)r()r<cCsdS)NrC)r[rCrCrD�__complex__�szSupportsComplex.__complex__N)rArdr@rqr�complexrArCrCrCrDr(�sc@s"eZdZfZeed�dd��ZdS)r')r<cCsdS)NrC)r[rCrCrD�	__bytes__�szSupportsBytes.__bytes__N)rArdr@rqr�bytesrCrCrCrCrDr'�sc@s"eZdZfZeed�dd��ZdS)r&)r<cCsdS)NrC)r[rCrCrD�__abs__�szSupportsAbs.__abs__N)rArdr@rqrr�rErCrCrCrDr&�sc@s&eZdZfZedeed�dd��ZdS)r+r)�ndigitsr<cCsdS)NrC)r[rFrCrCrD�	__round__szSupportsRound.__round__N)r)rArdr@rqrr>r�rGrCrCrCrDr+sc@seZdZfZdS)r%N)rArdr@rqrCrCrCrDr%
sc@s"eZdZfZedd�dd��ZdS)r%zIterator[T_co])r<cCsdS)NrC)r[rCrCrD�__reversed__szReversible.__reversed__N)rArdr@rqrrHrCrCrCrDr%
sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDrs�
Collectionc@seZdZfZdS)rIN)rArdr@rqrCrCrCrDrIsc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr'sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr+sc@seZdZfZdS)r!N)rArdr@rqrCrCrCrDr!0sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr6sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr:sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr?sc@seZdZfZdS)r"N)rArdr@rqrCrCrCrDr"Esc@seZdZfZdS)r"N)rArdr@rqrCrCrCrDr"Isc@seZdZfZdS)r"N)rArdr@rqrCrCrCrDr"Msc@seZdZfZdS)r N)rArdr@rqrCrCrCrDr Rsc@seZdZfZdS)rN)rArdr@rqrCrCrCrDrVsc@seZdZfZdd�ZdS)r0cOs$|jtkrtd��tt|f|�|�S)Nz4Type List cannot be instantiated; use list() instead)r�r0rPrr)rVr\r]rCrCrDrU^s
zList.__new__N)rArdr@rqrUrCrCrCrDr0Zsc@seZdZfZdd�ZdS)r-cOs*|jtkrtj||�Sttj|f|�|�S)N)r�r-�collections�dequer)rVr\r]rCrCrDrUis
z
Deque.__new__N)rArdr@rqrUrCrCrCrDr-esc@seZdZfZdd�ZdS)r1cOs$|jtkrtd��tt|f|�|�S)Nz2Type Set cannot be instantiated; use set() instead)r�r1rPrr�)rVr\r]rCrCrDrUss
zSet.__new__N)rArdr@rqrUrCrCrCrDr1osc@seZdZfZdd�ZdS)r2cOs$|jtkrtd��tt|f|�|�S)Nz>Type FrozenSet cannot be instantiated; use frozenset() instead)r�r2rPrr�)rVr\r]rCrCrDrU}s
zFrozenSet.__new__N)rArdr@rqrUrCrCrCrDr2zsc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr�sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr�sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr�sc@seZdZfZdS)r$N)rArdr@rqrCrCrCrDr$�s�AbstractContextManagerc@seZdZfZdS)rN)rArdr@rqrCrCrCrDr�sc@s2eZdZfZdd�Zejdd��Zedd��Z	dS)rcCs|S)NrC)r[rCrCrD�	__enter__�szContextManager.__enter__cCsdS)NrC)r[�exc_type�	exc_value�	tracebackrCrCrD�__exit__�szContextManager.__exit__cCs8|tkr4tdd�|jD��r4tdd�|jD��r4dStS)Ncss|]}d|jkVqdS)rMN)r)r��BrCrCrDr��sz2ContextManager.__subclasshook__.<locals>.<genexpr>css|]}d|jkVqdS)rQN)r)r�rRrCrCrDr��sT)rr�r�r~)rV�CrCrCrDr��s
zContextManager.__subclasshook__N)
rArdr@rqrMr�rrQ�classmethodr�rCrCrCrDr�s�AbstractAsyncContextManagerc@seZdZfZdS)�AsyncContextManagerN)rArdr@rqrCrCrCrDrV�srV�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@seZdZfZdd�ZdS)r.cOs$|jtkrtd��tt|f|�|�S)Nz4Type Dict cannot be instantiated; use dict() instead)r�r.rPrr�)rVr\r]rCrCrDrU�s
zDict.__new__N)rArdr@rqrUrCrCrCrDr.�sc@seZdZfZdd�ZdS)r/cOs*|jtkrtj||�Sttj|f|�|�S)N)r�r/rJ�defaultdictr)rVr\r]rCrCrDrU�s
zDefaultDict.__new__N)rArdr@rqrUrCrCrCrDr/�sc@seZdZfZdd�ZdS)r,cOs*|jtkrtj||�Sttj|f|�|�S)N)r�r,rJr)rVr\r]rCrCrDrU�s
zCounter.__new__N)rArdr@rqrUrCrCrCrDr,�s�ChainMapc@seZdZfZdd�ZdS)rYcOs*|jtkrtj||�Sttj|f|�|�S)N)r�rYrJr)rVr\r]rCrCrDrU�s
zChainMap.__new__N)rArdr@rqrUrCrCrCrDrY�sc@seZdZfZdd�ZdS)r4cOs$|jtkrtd��tt|f|�|�S)Nz@Type Generator cannot be instantiated; create a subclass instead)r�r4rPr�_G_base)rVr\r]rCrCrDrUs
zGenerator.__new__N)rArdr@rqrUrCrCrCrDr4s�AsyncGeneratorc@seZdZfZdS)r[N)rArdr@rqrCrCrCrDr[s�CT_co)r�r�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@rgrqrCrCrCrDr$scsvd��fdd�|D�}tj|dd�|D��}tj|�|_|_ytjd�jjdd�|_	Wnt
tfk
rpYnX|S)NzDNamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a typecsg|]\}}|t|��f�qSrC)r})r��nr�)r�rCrD�
<listcomp>Asz!_make_nmtuple.<locals>.<listcomp>cSsg|]\}}|�qSrCrC)r�r]r�rCrCrDr^BsrrA�__main__)rJ�
namedtuple�OrderedDictr#�_field_typesr>rrr'rdrr�)rWr��nm_tplrC)r�rD�
_make_nmtuple?srdrUr^rq�__getnewargs__�_fields�_field_defaultsrb�_make�_replace�_asdict�_sourcerdrAr@r#cseZdZ�fdd�Z�ZS)�NamedTupleMetacs|jdd�rt�j||||�Sts*td��|jdi�}t||j��}g}i}xP|D]H}||krz||}	|j|	�|	||<qR|rRtdj|dj	|j
��d���qRWtj|�|j_
t|�|j_||_xD|D]<}
|
tkr�td|
��q�|
tko�|
|jkr�t||
||
�q�W|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}z, )�
field_nameZ
default_namesz&Cannot overwrite NamedTuple attribute )r'rTrU�_PY36rPrdr(r�rrQr6rJrar#rnrrg�_prohibitedr�_specialrf�setattr)rV�typenamerX�nsr�rcr Z
defaults_dictrmZ
default_value�key)rZrCrDrUYs4



zNamedTupleMeta.__new__)rArdr@rUrirCrC)rZrDrlWsrlc@seZdZdZdZddd�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)])
    TNcKs:|rtrtd��|dkr$|j�}n|r0td��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)rnrPr(rd)r[rrZfields�kwargsrCrCrDrU�s

zNamedTuple.__new__)N)rArdr@rgrOrUrCrCrCrDr3yscCsdd�}||_||_|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__)rWrrvrCrCrDr8�sFc@s�eZdZdZfZeed�dd��Zeed�dd��Ze	dd�dd	��Z
e	ed�d
d��Ze	e
d�dd
��Ze	dd�dd��Ze	ed�dd��Ze	d7e
ed�dd��Ze	ed�dd��Ze	d9e
ed�dd��Ze	d;e
eed�dd��Ze	d<e
e
e
d�d d!��Ze	ed�d"d#��Ze	e
d�d$d%��Ze	d=e
e
d&�d'd(��Ze	ed�d)d*��Ze	ee
d+�d,d-��Ze	eedd.�d/d0��Ze	d1d�d2d3��Ze	dd�d4d5��ZdS)>�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[r�rCrCrD�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[rCrCrDrM	szIO.__enter__cCsdS)NrC)r[ror�rPrCrCrDrQ	szIO.__exit__r�)r�r�)r�r�)r�)r)N) rArdr@rgrqrrmrxrWrryr�rzr>r{r|r}r5r~rr�r0r�r�r�r�r�r�r�r�rMrQrCrCrCrDrw�sTrwc@sBeZdZdZfZeeeefe	d�dd��Z
edd�dd��ZdS)	�BinaryIOz5Typed version of the return of open() in binary mode.)r�r<cCsdS)NrC)r[r�rCrCrDr�)	szBinaryIO.write)r<cCsdS)NrC)r[rCrCrDrM-	szBinaryIO.__enter__N)rArdr@rgrqrrrD�	bytearrayr>r�rMrCrCrCrDr�$	sr�c@s�eZdZdZfZeed�dd��Zeed�dd��Z	ee
ed�dd��Zeed�d	d
��Z
eed�dd��Zedd�d
d��ZdS)�TextIOz3Typed version of the return of open() in text mode.)r<cCsdS)NrC)r[rCrCrD�buffer7	sz
TextIO.buffercCsdS)NrC)r[rCrCrD�encoding;	szTextIO.encodingcCsdS)NrC)r[rCrCrD�errors?	sz
TextIO.errorscCsdS)NrC)r[rCrCrD�line_bufferingC	szTextIO.line_bufferingcCsdS)NrC)r[rCrCrD�newlinesG	szTextIO.newlinescCsdS)NrC)r[rCrCrDrMK	szTextIO.__enter__N)rArdr@rgrqrr�r�rmr�rr�r�r�r
r�rrMrCrCrCrDr�2	sr�c@s&eZdZdZdddgZeZeZeZdS)�ioz)Wrapper namespace for IO generic classes.rwr�r�N)rArdr@rg�__all__rwr�r�rCrCrCrDr�P	s

r�z.io�Patternr�cCs|jS)N)�pattern)r�rCrCrD�<lambda>^	sr��MatchcCs|jjS)N)�rer�)�mrCrCrDr�`	sc@s eZdZdZddgZeZeZdS)r�z&Wrapper namespace for re type aliases.r�r�N)rArdr@rgr�r�r�rCrCrCrDr�c	sr�z.re)rr)NN)NN)rrW)rr)rUr^rqrerfrgrbrhrirjrk)rdrAr@r#)�r�rrrJ�
contextlibr�r�Z	stdlib_rer>r��collections.abcZcollections_abc�ImportErrorr?�_collections_abcrrr	ror�r^�__str__rmrQr�rErMrNrHrIrGrFrcr�rar}rSr�r
r�ZNoReturnrr�r�r�r�r�r�r�rDr5r�r�r�r�r�r�r�rr�rr�r�r�r�rr
rr�r�r
rnrrrr�rr6r!r��BuiltinFunctionType�
MethodTyper)r*r7r9r:r0r;r1r�rr�r8r�r9r:r;rrr*r)r(r'r&r+r%r#rrIr1rr!rrr"r r>rrr0rKr-r�r�r2rrrr$rLrrUrV�execr�r.rXr/r,rYr4rZ�
GeneratorTyper[r\rrdrnrorprlr3r8r<r=rwr�r�r�rAr&ryr��matchr�rCrCrCrD�<module>s�
*%5C

W
!)

"96


R	D








"









"





"(`