3 \�9�D@s� ddlZddlmZmZddlZddlZddlZddlZddlZddl Z yddl jZ Wne k rrddlZ YnXej dd�d�kr�ddlZyddl mZmZmZWn4e k r�eej�Zee�j�Zeej�ZYnXddd d d d 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�Zdvdw�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�de jJeId��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|�ZZe j[Z[e\e d���rjGd�d��d�eBe-e j]d��Z]ej^d��e\e d���r�Gd�d��d�e]e.eBe-e0e.fe j_d��Z_ej^d��e\e d���r�Gd�d��d�eBe-e j`d��Z`Gd�d��d�e`e-e jad��Zaej^d��ej^d��Gd�d�deBe-e jbd��ZbGd�d�debe-e jcd��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\e d"��r�Gd�d"�d"ebe-e jjd��ZjnGd�d"�d"eZe-�Zje jkZkGd�d�deBe-e jld��Zle\e d���r*Gd�d��d�ekebe-ele-e jmd��Zmej^d��e\e d���rRGd�d�deme-e jnd��Zon"Gd�d�dekebe-ele-e jnd��ZoGd�d�deoe*e jpd��Zpe\e d���r�Gd�d�deme+eBe+e/fe jqd��Zqn,Gd�d�dekebe+ele+eBe+e/fe jqd��ZqGd�d�deqe+e,fe jrd��Zre\e d"��rhe\e d���rDGd�d�deje-eme-e jsd��Zsn"Gd�d�dekeje-ele-e jsd��Zsn"Gd�d�dekebe-ele-e jsd��ZsGd�d�dese*e jtd��ZtGd�d�deseue jvd��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-e j~d��Z~Gd�d�de~e+eoe+e jd��ZGd�d�de~eHe+e/feoeHe+e/feBe+e/fe j�d��Z�Gd�d!�d!e~e/e j�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\e d1�� r�e j�Z�ne j�Z�Gd�d1�d1ece-eBe-e0e.fe�d��Z�e\e d΃� rVGd�d΄d�eae-eBe-e0fe j�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 �Zd d �Z d d�Z �Z S)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__c stt�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�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�Z dS)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||_||_||_||_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)rWr�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 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��s r�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� sz#TypeVar.__init__..zBound must be a type.) rTr^rA� ValueError�boolr�r�rPrkrnr�r}r�)r[rWr�r�r�Z constraints)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�csg}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|}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..c3s|]}|�kr|VqdS)NrC)r�r�)� all_paramsrCrDr��s) rlr�r�r�extendr�rnrkr��set�removero�any)� parameters�params�pZ new_paramsr�rC)r�r�rD�_remove_dups_flattenes. "     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. c s*y �||�Stk rYnX�||�S)N)rP)r\r])�cached�funcrCrD�inner�s  z_tp_cache..inner)� functools� lru_cache� _cleanupsr�� cache_clear�wraps)r�r�rC)r�r�rD� _tp_cache�s  r�cs�eZdZdZdZd dd��fd d � Zd d �Zd d�Z�fdd�Z�fdd�Z e dd��Z d!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��|t kr~t |�}t |�dkr~|dSt|�|_||_||_|j�}t|t �r�tt|��|_n t|�|_|S)NrOrzExpected parameters=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..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__..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 )rVZ next_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..__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 ��Zd d �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 sX|dk r n�t|�}d} xF|D]>} | tkr0td��t| t�r| jtkr| dk rTtd��| j} qW| dkrl|} nPt|�} t| ��| �ks�tddj�fdd�|D��djdd�| D��f��| }|} |dk r�t |�t j kr�||kr�|f|}t d d�|D��}t d d�|D���r t d d�|D��}|j|||�s2dn|jd ��t�j||||d d�} tt| �jd|�sj| n|j�|| _|�r�t dd�|D��nd| _t| �| _|dk�r�| | _d|k�r�|�s�t| jdd�dk�r�t| �| _t|t j ��r�|j| _|j| _n|dk �r|j| _|j| _|�r2t|d��r2|j| _|�rDt| 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(). Nz!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��sz&GenericMeta.__new__..css|]}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�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�sj           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 |j d�S)Nc3s|]}t|���VqdS)N)ra)r�r�)r_r`rCrDr�sz)GenericMeta._eval_type..)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__..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 �allrkr�r r�r�r�r�r�rZrAr�r�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 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__..) 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]rCrCrDrU s 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�r rTr�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�r rTr�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__..)r}rrTr�r�rn)r[r�r\r)rZ)r�rDr>s  zCallableMeta.__getitem_inner__) rArdr@rgrfr�r�r�rrirCrC)rZrDr s    r c@seZdZdZfZdd�ZdS)r a�Callable type; Callable[[int], str] is a function of (int) -> str. The subscription syntax must always be used with exactly two values: the argument list and the return type. The argument list must be a list of types or ellipsis; the return type must be a single type. There is no syntax to indicate optional or keyword arguments, such function types are rarely used as callback types. cOs&|jtkrtd��t|j|f|�|�S)NzIType Callable cannot be instantiated; use a non-abstract subclass instead)r�r rPr r�)rVr\r]rCrCrDrUXs zCallable.__new__N)rArdr@rgrqrUrCrCrCrDr Ks csNeZdZdZdZddd�Zdd�Zdd �Z�fd d �Zd d �Z dd�Z �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^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|�}x&t||d�|�D]\}} | ||<qxW|S)z:Internal helper to extract the default arguments, by name.N) �__code__r � co_argcount� co_varnames� __defaults__�__kwdefaults__r�rk�zip) 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�modulesrdr�get�itemsrmrGrar�� ModuleType�_allowed_typesrPrr r�r) r�r_r`Zhintsr�Z base_globalsZannrWr�rrCrCrDr7�sV            c Cs�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'r�r��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..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_dummy8sr/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;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�r�rTr�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__..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|d krT|d krT|d krT|dkrT|dkrT|dkrT|dkrT|dkrT|dkrT|j|�qTWqBW|S)NrhFr�r�__abstractmethods__r"rjr�rr�rqr2r�r�r�r�r�r�rd) r�r�rAr�r�r�keysrL�add)r[Zprotocol_basesr�r3r�rrCrCrDr2{s<   z!_ProtocolMeta._get_protocol_attrs)rArdr@rgr�r�r2rirCrC)rZrDr0^s r0c@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)r7N)rArdr@rqrCrCrCrDr7�s)r�� Coroutinec@seZdZfZdS)r8N)rArdr@rqrCrCrCrDr8�s� AsyncIterablec@seZdZfZdS)r9N)rArdr@rqrCrCrCrDr9�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�complexr@rCrCrCrDr(�sc@s"eZdZfZeed�dd��ZdS)r')r;cCsdS)NrC)r[rCrCrD� __bytes__�szSupportsBytes.__bytes__N)rArdr@rqr�bytesrBrCrCrCrDr'�sc@s"eZdZfZeed�dd��ZdS)r&)r;cCsdS)NrC)r[rCrCrD�__abs__�szSupportsAbs.__abs__N)rArdr@rqrr�rDrCrCrCrDr&�sc@s&eZdZfZedeed�dd��ZdS)r+r)�ndigitsr;cCsdS)NrC)r[rErCrCrD� __round__szSupportsRound.__round__N)r)rArdr@rqrr=r�rFrCrCrCrDr+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@rqrrGrCrCrCrDr% sc@seZdZfZdS)rN)rArdr@rqrCrCrCrDrs� Collectionc@seZdZfZdS)rHN)rArdr@rqrCrCrCrDrHsc@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 z Set.__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)rLN)r)r��BrCrCrDr��sz2ContextManager.__subclasshook__..css|]}d|jkVqdS)rPN)r)r�rQrCrCrDr��sT)rr�r�r~)rV�CrCrCrDr��s zContextManager.__subclasshook__N) rArdr@rqrLr�rrP� classmethodr�rCrCrCrDr�s�AbstractAsyncContextManagerc@seZdZfZdS)�AsyncContextManagerN)rArdr@rqrCrCrCrDrU�srU�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/rI� defaultdictr )rVr\r]rCrCrDrU�s  zDefaultDict.__new__N)rArdr@rqrUrCrCrCrDr/�sc@seZdZfZdd�ZdS)r,cOs*|jtkrtj||�Sttj|f|�|�S)N)r�r,rIr )rVr\r]rCrCrDrU�s  zCounter.__new__N)rArdr@rqrUrCrCrCrDr,�s�ChainMapc@seZdZfZdd�ZdS)rXcOs*|jtkrtj||�Sttj|f|�|�S)N)r�rXrIr )rVr\r]rCrCrDrU�s  zChainMap.__new__N)rArdr@rqrUrCrCrCrDrX�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)rZN)rArdr@rqrCrCrCrDrZs�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 t fk rpYnX|S)NzDNamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a typecsg|]\}}|t|��f�qSrC)r})r��nr�)r�rCrD� Asz!_make_nmtuple..cSsg|] \}}|�qSrCrC)r�r\r�rCrCrDr]BsrrA�__main__) rI� namedtuple� OrderedDictr"� _field_typesr>rrr&rdr r�)rWr��nm_tplrC)r�rD� _make_nmtuple?srcrUr^rq�__getnewargs__�_fields�_field_defaultsra�_make�_replace�_asdict�_sourcerdrAr@r"cseZdZ�fdd�Z�ZS)�NamedTupleMetac s|jdd�rt�j||||�Sts*td��|jdi�}t||j��}g}i}xP|D]H}||krz||} |j| �| ||<qR|rRtdj|dj |j ��d���qRWt j |�|j_ t|�|j_||_xD|D]<} | tkr�td| ��q�| tko�| |jkr�t|| || �q�W|S) NrOFz= 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)rmrPr'rc)r[rqZfields�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..new_type)rAZ __supertype__)rWrrurCrCrDr8�sFc@s�eZdZdZfZeed�dd��Zeed�dd��Ze dd�dd ��Z e e d�d d ��Z e e d�d d ��Ze dd�dd��Ze e d�dd��Ze d7e ed�dd��Ze e d�dd��Ze d9e ed�dd��Ze d;e eed�dd��Ze d�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�sz IO.readable)�limitr;cCsdS)NrC)r[rrCrCrD�readline�sz IO.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 sz IO.seekablecCsdS)NrC)r[rCrCrD�tell szIO.tell)�sizer;cCsdS)NrC)r[r�rCrCrD�truncate sz IO.truncatecCsdS)NrC)r[rCrCrD�writable sz IO.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[ror�rOrCrCrDrP sz IO.__exit__r�)r�r�)r�r�)r�)r)N) rArdr@rgrqrrmrwrWrrxr�ryr=rzr{r|r5r}r~r�r0r�r�r�r�r�r�r�r�rLrPrCrCrCrDrv�sT rvc@sBeZdZdZfZeeeefe d�dd��Z edd�dd��Z dS) �BinaryIOz5Typed version of the return of open() in binary mode.)r�r;cCsdS)NrC)r[r�rCrCrDr�) szBinaryIO.write)r;cCsdS)NrC)r[rCrCrDrL- szBinaryIO.__enter__N) rArdr@rgrqrrrC� bytearrayr=r�rLrCrCrCrDr�$ s r�c@s�eZdZdZfZeed�dd��Zeed�dd��Z ee ed�dd��Z ee d�d d ��Z eed�d d ��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[rCrCrDrLK szTextIO.__enter__N)rArdr@rgrqrr�r�rmr�rr�r�r�r r�rrLrCrCrCrDr�2 sr�c@s&eZdZdZdddgZeZeZeZdS)�ioz)Wrapper namespace for IO generic classes.rvr�r�N)rArdr@rg�__all__rvr�r�rCrCrCrDr�P s  r�z.io�Patternr�cCs|jS)N)�pattern)r�rCrCrD�^ 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)rrV)rr) rUr^rqrdrerfrargrhrirj)rdrAr@r")�r�rrrI� 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�rCr5r�r�r�r�r�r�r�rr�rr�r�r�r�rr r r�r�r rnrr r r�r r6r r��BuiltinFunctionType� MethodTyper(r)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�rAr%ryr��matchr�rCrCrCrD�s�   *%5C  W      !)    "96    R D                  "                   "      "(`