3 \9D@s ddlZddlmZmZddlZddlZddlZddlZddlZddl Z yddl jZ Wne k rrddlZ YnXej dddkrddlZyddl mZmZmZWn4e k reejZeejZeejZYnXddd 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@eZGdAdBdBedCdDZGdEdFdFedCdGZGdHdIdIedCdGZGdJdKdKedCdGZdLdMZ dNdOZ!dPdQZ"dRdSZ#dTdUZ$GdVdWdWedCdGZ%e%dCdGZ&GdXdYdYedCdGZ'e'dCdGZ(GdZddedCdGZ)e)d[Z*e)d\Z+e)d]Z,e)d^dCd_Z-e)d`dCd_Z.e)dadCd_Z/e)dbdCdcZ0e)d2e1eZ2dddeZ3ddfdgZ4dhdiZ5djdkZ6gZ7dldmZ8GdndodoedCdGZ9e9dCdGZ:GdpdqdqedCdGZ;e;dCdGZdvdwZ?Gdxddeej@ZAdZBdydzZCGd{d d eAd|ZBGd}d~d~ZDGdddZEGdddeAZFGdd d eGeGeFdZHGdddeAZIGddde jJeIdZJGdddedCdGZKeKdCdGZLdd3ZMddZNe jOe jPe jQe jReeefZSddd4ZTdd6ZUdd7ZVddZWdd8ZXGdddeAZYGdddeYd|ZZe j[Z[e\e drjGdddeBe-e j]dZ]ej^de\e drGddde]e.eBe-e0e.fe j_dZ_ej^de\e drGdddeBe-e j`dZ`Gddde`e-e jadZaej^dej^dGdddeBe-e jbdZbGdddebe-e jcdZcGdd'd'eZZdGdd&d&eZZeGdd%d%eZZfGdd$d$eZZgGdd#d#eZe-ZhGdd(d(eZe-Zie\e d"rGdd"d"ebe-e jjdZjnGdd"d"eZe-Zje jkZkGdddeBe-e jldZle\e dr*Gdddekebe-ele-e jmdZmej^de\e drRGdddeme-e jndZon"Gdddekebe-ele-e jndZoGdddeoe*e jpdZpe\e drGdddeme+eBe+e/fe jqdZqn,Gdddekebe+ele+eBe+e/fe jqdZqGdddeqe+e,fe jrdZre\e d"rhe\e drDGdddeje-eme-e jsdZsn"Gdddekeje-ele-e jsdZsn"Gdddekebe-ele-e jsdZsGdddese*e jtdZtGdddeseue jvdZvGdd-d-ewete*ewdZxGdd*d*ejyete*ejydZzGdd.d.e{epe*e{dZnGdd/d/e|eoe-e|dZ}Gdddekebe-e j~dZ~Gddde~e+eoe+e jdZGddde~eHe+e/feoeHe+e/feBe+e/fe jdZGdd!d!e~e/e jdZe\edrGdddeBe-ejdZnGdddeBe-Ze\edà r(GddńdeBe-ejdZej^dŃnej dddk rDedǃGdd+d+eere+e,fedZGdd,d,ejere+e,fejdZGdd)d)ejee*eufejdZe\ed˃ rej^d˃Gdd˄dejere+e,fejdZe\e d1 re jZne jZGdd1d1ece-eBe-e0e.fedZe\e d΃ rVGdd΄deae-eBe-e0fe jdZej^d΃e)ddCedэZGdd d eBeedZddԄZej dddkZdZdZGdddeZGdd0d0ed|Zdd5ZeZdZGdddeBe2ZGdddee1ZGdddeeZGdddZede_eejej<ede2eejdddZede2eejddddZGdddZede_eejej<dS(N)abstractmethodabstractproperty)WrapperDescriptorTypeMethodWrapperTypeMethodDescriptorTypeAnyCallableClassVarGenericOptionalTupleTypeTypeVarUnion AbstractSet GenericMeta ByteString ContainerContextManagerHashable ItemsViewIterableIteratorKeysViewMapping MappingViewMutableMappingMutableSequence MutableSetSequenceSized ValuesView Reversible SupportsAbs SupportsBytesSupportsComplex SupportsFloat SupportsInt SupportsRoundCounterDequeDict DefaultDictListSet FrozenSet NamedTuple GeneratorAnyStrcastget_type_hintsNewType no_type_checkno_type_check_decoratoroverloadText TYPE_CHECKINGcCs"tjdddkr|jS|jSdS)Nrr)rr)sys version_info __qualname____name__)xrC/usr/lib64/python3.6/typing.py _qualnamegsrEcCs&d}|jdr"||kr"|dd}|S)N _TypeAlias _ForwardRef _TypingBase_FinalTypingBase_)rFrGrHrI) startswith)ZnmZ whitelistrCrCrD _trim_nameos rMcsJeZdZdZdZddfdd ZddZdd Zd d Zd d Z Z S) TypingMetaaMetaclass 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|pdtj||||S)NzCannot subclass %sz, z()) TypeErrorjoinmap _type_reprsuper__new__)clsnamebases namespacerO) __class__rCrDrUszTypingMeta.__new__cOsdS)NrC)selfargskwdsrCrCrD__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[globalnslocalnsrCrCrD _eval_typeszTypingMeta._eval_typecCsdS)NrC)r[tvarsrCrCrD_get_type_varsszTypingMeta._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  rNcsLeZdZdZdZddZfddZddZd d Zd d Z d dZ Z S)rHz0Internal indicator of special typing constructs. __weakref__cOsdS)NrC)r[r\r]rCrCrDr^sz_TypingBase.__init__cs@t|dkr4t|dtr4t|dtr4td|tj|S)zConstructor. 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 isinstancestrtuplerPrTrU)rVr\r])rZrCrDrUs   z_TypingBase.__new__cCs|S)NrC)r[r_r`rCrCrDrasz_TypingBase._eval_typecCsdS)NrC)r[rbrCrCrDrcsz_TypingBase._get_type_varscCs"t|}tt|}d|j|fS)Nz%s.%s)typerMrErd)r[rVrerCrCrDrfs z_TypingBase.__repr__cOstdt|dS)NzCannot instantiate %r)rPro)r[r\r]rCrCrD__call__sz_TypingBase.__call__)rj) rArdr@rg __slots__r^rUrarcrfrprirCrC)rZrDrHs rHT) metaclassrOcs2eZdZdZfZddfdd ZddZZS)rIzInternal 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)rOcs0tj|f||}|dkr |Std|dS)NTzCannot instantiate %r)rTrUrP)rVrOr\r]r[)rZrCrDrUsz_FinalTypingBase.__new__cCstt|jS)N)rMrorA)r[rCrCrD __reduce__sz_FinalTypingBase.__reduce__)rArdr@rgrqrUrsrirCrC)rZrDrIsrI)rOcsTeZdZdZdZfddZdd Zd d Zd d ZddZ ddZ ddZ Z S)rGz-Internal wrapper to hold a forward reference.__forward_arg____forward_code____forward_evaluated____forward_value__c sttj|t|ts$td|fyt|dd}Wn"tk rVtd|fYnX||_||_d|_ d|_ dS)Nz,Forward reference must be a string -- got %rzevalz1Forward reference must be an expression -- got %rF) rTr^rlrmrPcompile SyntaxErrorrtrurvrw)r[argcode)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`rCrCrDras  z_ForwardRef._eval_typecCs&t|tstS|j|jko$|j|jkS)N)rlrGNotImplementedrtrw)r[otherrCrCrD__eq__s  z_ForwardRef.__eq__cCst|j|jfS)N)hashrtrw)r[rCrCrD__hash__sz_ForwardRef.__hash__cCs tddS)Nz4Forward references cannot be used with isinstance().)rP)r[objrCrCrD__instancecheck__sz_ForwardRef.__instancecheck__cCs tddS)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^rarrrrrfrirCrC)rZrDrGs rGc@sLeZdZdZdZddZdd Zd d Zd d ZddZ ddZ ddZ 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``. rWtype_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)rWrrr)r[rWrrrrCrCrDr^sz_TypeAlias.__init__cCsd|jt|jfS)Nz%s[%s])rWrSr)r[rCrCrDrf,sz_TypeAlias.__repr__cCst|jtstd||jjrJt|trJt||jjsJtd||jft|trj||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.) rlrrrP__constraints__ro issubclassrZrWrr)r[Z parameterrCrCrD __getitem__/s    z_TypeAlias.__getitem__cCs&t|tstS|j|jko$|j|jkS)N)rlrFr~rWr)r[rrCrCrDr;s z_TypeAlias.__eq__cCst|j|jfS)N)rrWr)r[rCrCrDr@sz_TypeAlias.__hash__cCs t|jtstdt||jS)Nz NoReturn: raise Exception('no way') This type is invalid in other positions, e.g., ``List[NoReturn]`` will fail in static type checkers. cCs tddS)Nz*NoReturn cannot be used with isinstance().)rP)r[rrCrCrDrsz_NoReturn.__instancecheck__cCs tddS)Nz*NoReturn cannot be used with issubclass().)rP)r[rVrCrCrDrsz_NoReturn.__subclasscheck__N)rArdr@rgrqrrrCrCrCrDrs rcsNeZdZdZdZdddd fd d Zd d ZddZddZddZ Z S)raType 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 contravariantcstj|f||||d||_|r2|r2tdt||_t||_|rZ|dk rZtd|rrt|dkrrtddt fdd|D|_ |rt |d |_ nd|_ dS) N)rrrz"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)rrCrD sz#TypeVar.__init__..zBound must be a type.) rTr^rA ValueErrorboolrrrPrkrnrr}r)r[rWrrrZ constraints)rZ)rrDr^s     zTypeVar.__init__cCs||kr|j|dS)N)append)r[rbrCrCrDrcszTypeVar._get_type_varscCs&|jr d}n|jrd}nd}||jS)N+-~)rrrA)r[prefixrCrCrDrf s zTypeVar.__repr__cCs tddS)Nz0Type variables cannot be used with isinstance().)rP)r[instancerCrCrDrszTypeVar.__instancecheck__cCs tddS)Nz0Type variables cannot be used with issubclass().)rP)r[rVrCrCrDrszTypeVar.__subclasscheck__)rArrrr) rArdr@rgrqr^rcrfrrrirCrC)rZrDrs( TKTVTT_co)rV_coVT_coT_contra)rcCsd|dkr g}t|dr0t|ttfr0|j||St|tr`x$t|D]\}}||krD||SqDW|S)zAn 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)hasattrrlrrHrr enumerate)r{rbr\iZtvarrCrCrD _replace_arg)s   rc 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)aAn 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)rr__args__r__parameters__) rVrbr\ZcurrentZ orig_chain tree_argsr{ZoclsZ new_tree_argsrCrCrDrDs       rcsg}xn|D]f}t|tr0|jtkr0|j|jq t|trft|dkrf|dtkrf|j|ddq |j|q Wt |tt|krg}x(|D] }|kr|j|j |qW|}t |x>|D]6tt sqt fddhDr̈j qWtfdd|DS)zAn internal helper for Union creation and substitution: flatten Union's among parameters, then remove duplicates and strict subclasses. rrKNc3s6|].}t|to|jdk st|to,t|VqdS)N)rlrrror)rZt2)t1rCrDrs z'_remove_dups_flatten..c3s|]}|kr|VqdS)NrC)rr) all_paramsrCrDrs) rlrrrextendrrnrkrsetremoveroany) parametersparamspZ new_paramsrrC)rrrD_remove_dups_flattenes. "     rcCsX|jstdt|t|}t|j}||krTtd||kr@dndt|||fdS)Nz%s is not a generic classz0Too %s parameters for %s; actual %s, expected %sZmanyZfew)rrPrrk)rVrZalenZelenrCrCrD_check_generics rcs4tjtjjtjfdd}|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])cachedfuncrCrDinners  z_tp_cache..inner) functools lru_cache _cleanupsr cache_clearwraps)rrrC)rrrD _tp_caches  rcseZdZdZdZd ddfd d Zd d Zd dZfddZfddZ e ddZ d!ddZ ddZ ddZddZddZZS)"raUnion 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]. rrr __tree_hash__NF)rOcstj|||f|d|i}|dkrHd|_d|_d|_ttd|_|St|t sZt d|t kr~t |}t |dkr~|dSt||_||_||_|j}t|t rtt||_n t||_|S)NrOrzExpected parameters=rKr)r)rTrUrrrr frozensetrrlrnrPrrrkrr)rVroriginrOr\r[Z subs_tree)rZrCrDrUs*     z_Union.__new__cs^|jdkr|Stfdd|jD}t|j}||jkrN||jkrN|S|j||ddS)Nc3s|]}t|VqdS)N)ra)rr)r_r`rCrDrsz$_Union._eval_type..T)rO)rrnrarrZ)r[r_r`ev_args ev_originrC)r_r`rDras z_Union._eval_typecCs|jr|jrt|j|dS)N)rrrc)r[rbrCrCrDrcs z_Union._get_type_varscs<|jdkrtjS|j}t|ts.t|S|dj|S)Nr)rrTrfrrlrnr _tree_repr)r[tree)rZrCrDrfs    z_Union.__repr__cs`g}xB|ddD]2}t|ts0|jt|q|j|dj|qWtjddj|S)NrKrz[%s]z, )rlrnrrSrrTrfrQ)r[rarg_listr{)rZrCrDr s  z_Union._tree_reprcsl|fkrtdt|ts |f}|jdkr0dndtfdd|D}|tk r\t|||j||ddS)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})rr)rrCrDr sz%_Union.__getitem__..T)rrO)rPrlrnrrrrZ)r[rrC)rrDrs   z_Union.__getitem__cCs>|tkr tSt|||}t|}t|dkr4|dStf|S)NrKr)rrrrk)r[rbr\rrCrCrDr%s  z_Union._subs_treecCs6t|tr|j|jkS|tk r*|j|kS||kSdS)N)rlrrrr)r[rrCrCrDr.s    z _Union.__eq__cCs|jS)N)r)r[rCrCrDr6sz_Union.__hash__cCs tddS)Nz(Unions cannot be used with isinstance().)rP)r[rrCrCrDr9sz_Union.__instancecheck__cCs tddS)Nz(Unions cannot be used with issubclass().)rP)r[rVrCrCrDr<sz_Union.__subclasscheck__)rrrr)NN)NN)rArdr@rgrqrUrarcrfrrrrrrrrrirCrC)rZrDrs*    rc@s eZdZdZfZeddZdS)rzEOptional type. Optional[X] is equivalent to Union[X, None]. cCst|d}t|tdfS)Nz#Optional[t] requires a single type.)r}rro)r[r{rCrCrDrKs z_Optional.__getitem__N)rArdr@rgrqrrrCrCrCrDrCsrcCsJt}x@t|jddD]*\}}t|tr|jtkr|j|d}qW|S)zHelper for Generic.__new__. Returns the class after the last occurrence of Generic or Generic[...] in cls.__mro__. NrK)objectr__mro__rlrrr )rVZ next_in_mrorcrCrCrD _next_in_mroTs rcs,tjtjrfdd}n fdd}|S)zConstruct a __subclasshook__ callable that incorporates the associated __extra__ class in subclass checks performed against cls. csZjj|}|tk r|Sj|jkr(dSx,jjD]}t|trDq4t||r4dSq4WtS)NT) __extra____subclasshook__r~r__subclasses__rlrr)subclassresscls)rVrCrD __extrahook__ks    z)_make_subclasshook..__extrahook__csjrt|jrdStS)NT)rrr~)r)rVrCrDrys)rlrabcABCMeta)rVrrC)rVrD_make_subclasshookbs rcCs2t|}d|kr.x|dD]}|j|dqW|S)zInternal helper: copy class __dict__ and clean slots class variables. (They will be re-created if necessary by normal class machinery.) rqN)dictpop)ZdctZ dict_copyZslotrCrCrD_no_slots_copys rcseZdZdZd!fdd ZeddZejddZedd Zejd d Zd d Z d dZ fddZ fddZ d"ddZ ddZddZeddZfddZddZfdd ZZS)#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 nt|}d} xF|D]>} | tkr0tdt| tr| jtkr| dk rTtd| j} qW| dkrl|} nPt|} t| | kstddjfdd|Ddjdd| Df| }|} |dk rt |t j kr||kr|f|}t d d|D}t d d|Dr t d d|D}|j|||s2dn|jd tj||||d d} tt| jd|sj| n|j|| _|rt dd|Dnd| _t| | _|dkr| | _d|kr|st| jdddkrt| | _t|t j r|j| _|j| _n|dk r|j| _|j| _|r2t|dr2|j| _|rDt| jn tt| j | _!| S)zCreate 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)rr)gvarsetrCrDrsz&GenericMeta.__new__..css|]}t|VqdS)N)rm)rgrCrCrDrscss"|]}t|tr|jn|VqdS)N)rlrr)rbrCrCrDrscss |]}t|to|tk VqdS)N)rlrr )rrrCrCrDrscss|]}|tk r|VqdS)N)r )rrrCrCrDrs)rrrT)rOrcss*|]"}|tkrdn|tkrfn|VqdS).N)_TypingEllipsis _TypingEmpty)rarCrCrDrsrrArr@)"rr rPrlrrrrrQrorrrnrupdaterrTrU __setattr__rr__next_in_mro____orig_bases__rrr _abc_registry _abc_cacherr@rrrr)rVrWrXrYrbr\rextra orig_basesZgvarsbaseZtvarsetZ initial_basesr[)rZ)rrDrUsj           zGenericMeta.__new__cCst|jtjr|jjS|jjS)N)rlrrr_abc_negative_cacher_abc_generic_negative_cache)r[rCrCrDrszGenericMeta._abc_negative_cachecCs,|jdkr(t|jtjr"||j_n||_dS)N)rrlrrrrr)r[valuerCrCrDrs  cCst|jtjr|jjS|jjS)N)rlrrr_abc_negative_cache_versionr#_abc_generic_negative_cache_version)r[rCrCrDr sz'GenericMeta._abc_negative_cache_versioncCs,|jdkr(t|jtjr"||j_n||_dS)N)rrlrrrrr)r[rrCrCrDrs  cCs|jr|jrt|j|dS)N)rrrc)r[rbrCrCrDrcs zGenericMeta._get_type_varsc s|jr|jjnd}|jr8tfdd|jDnd}||jkrT||jkrT|S|j|j|jt|j|rtt |nd|||j |j dS)Nc3s|]}t|VqdS)N)ra)rr)r_r`rCrDrsz)GenericMeta._eval_type..)rbr\rrr) rrarrnrZrA __bases__r__dict__rrr)r[r_r`rrrC)r_r`rDras$zGenericMeta._eval_typecs"|jdkrtjS|j|jS)N)rrTrfrr)r[)rZrCrDrf+s  zGenericMeta.__repr__cstg}xV|ddD]F}|fkr*|jdqt|tsD|jt|q|j|dj|qWtjddj|S)NrKz()rz[%s]z, )rrlrnrSrrTrfrQ)r[rrr{)rZrCrDr0s  zGenericMeta._tree_reprcCs*|jdkr|St|||}|jft|S)N)rrrrn)r[rbr\rrCrCrDr;s  zGenericMeta._subs_treecCs6t|tstS|jdks"|jdkr*||kS|j|jkS)N)rlrr~rr)r[rrCrCrDrAs  zGenericMeta.__eq__cCs|jS)N)r)r[rCrCrDrHszGenericMeta.__hash__c s6t|ts|f}| r0|jtk r0tdt|dtfdd|D}|tkrtdd|Dsltdtt |t|krtd|}|}nb|tt fkrt |}|}nH|t kr|}|}n6|j tt fkrtdt|nt||t |}|}|j dkr|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})rr)rrCrDrSsz*GenericMeta.__getitem__..css|]}t|tVqdS)N)rlr)rrrCrCrDrVsz5Parameters to Generic[...] must all be type variablesz-Parameters to Generic[...] must all be uniquez'Cannot subscript already-subscripted %s)rbr\rrr)rlrnrrrPrEr allrkrr rrrrrrZrArrrrr)r[rrbr\ZprependrC)rrDrKsJ   zGenericMeta.__getitem__csJ|jdk r*tjdjddkr&tddS|tkr>td|tj|S) NrKrArrzCParameterized generics cannot be used with class or instance checksFz5Class %r cannot be used with class or instance checks)rr)rr> _getframe f_globalsrPr rTr)r[rV)rZrCrDrys zGenericMeta.__subclasscheck__cCs t|j|S)N)rrZ)r[rrCrCrDrszGenericMeta.__instancecheck__csT|jdr|jds(|jds(|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&|jtkrtdt|j|f||S)NzHType Generic cannot be instantiated; it can be used only as a base class)rr rPr r)rVr\r]rCrCrDrUs zGeneric.__new__N)rArdr@rgrqrUrCrCrCrDr s)rrc@seZdZdZdS)rzInternal 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@rgrCrCrCrDrsrc@seZdZdZdS)rz(Internal placeholder for ... (ellipsis).N)rArdr@rgrCrCrCrDrsrcs4eZdZdZefddZddZddZZS) TupleMetazMetaclass for Tuple (internal).cs|jdk s|jtk r tj|S|fkr6tjtfSt|tsF|f}t|dkr|ddkrdt |d}tj|t fSdtfdd|D}tj|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})rr)rrCrDrsz(TupleMeta.__getitem__..) rrrrTrrrlrnrkr}r)r[rr)rZ)rrDrs  zTupleMeta.__getitem__cCs |jdkrt|tStddS)Nz5Parameterized Tuple cannot be used with isinstance().)rrlrnrP)r[rrCrCrDrs  zTupleMeta.__instancecheck__cCs |jdkrt|tStddS)Nz5Parameterized Tuple cannot be used with issubclass().)rrrnrP)r[rVrCrCrDrs  zTupleMeta.__subclasscheck__) rArdr@rgrrrrrirCrC)rZrDr sr c@seZdZdZfZddZdS)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$|jtkrtdtt|f||S)Nz6Type Tuple cannot be instantiated; use tuple() instead)rrrPr rn)rVr\r]rCrCrDrU s z Tuple.__new__N)rArdr@rgrqrUrCrCrCrDrs)rrrcsHeZdZdZfddZfddZfddZefdd ZZ S) CallableMetaz"Metaclass for Callable (internal).cs"|jdkrtjS|j|jS)N)rrTrfrr)r[)rZrCrDrfs  zCallableMeta.__repr__cs|jtk rtj|Sg}xB|ddD]2}t|tsF|jt|q(|j|dj|q(W|ddkrt|dd|dSt|dddj |dd|dfS) NrKrz...z [..., %s]z [[%s], %s]z, rr) rr rTrrlrnrrSrrQ)r[rrr{)rZrCrDrs     zCallableMeta._tree_reprcs|jdk s|jtk r tj|St|t s8t|dkr@td|\}}|t krZt |f}n$t|t srtd|ft||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.) rrr rTrrlrnrkrPEllipsislist__getitem_inner__)r[rr\result)rZrCrDr*s     zCallableMeta.__getitem__cs^|\}}dt|}|tkr.tjt|fSdtfdd|D}||f}tj|S)Nz.Callable[args, result]: result must be a type.z6Callable[[arg, ...], result]: each arg must be a type.c3s|]}t|VqdS)N)r})rr{)rrCrDrFsz1CallableMeta.__getitem_inner__..)r}rrTrrrn)r[rr\r)rZ)rrDr>s  zCallableMeta.__getitem_inner__) rArdr@rgrfrrrrrirCrC)rZrDr s    r c@seZdZdZfZddZdS)r aCallable 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&|jtkrtdt|j|f||S)NzIType Callable cannot be instantiated; use a non-abstract subclass instead)rr rPr r)rVr\r]rCrCrDrUXs zCallable.__new__N)rArdr@rgrqrUrCrCrCrDr Ks csNeZdZdZdZdddZddZdd Zfd d Zd d Z ddZ Z S)ra3Special 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|jddddStdj|jdddS)Nz{} accepts only single type.rKT)rOz {} cannot be further subscripted)rorr}formatrArP)r[itemrVrCrCrDrus z_ClassVar.__getitem__cCs,t|j||}||jkr|St||ddS)NT)rO)rarro)r[r_r`Znew_tprCrCrDra~s z_ClassVar._eval_typecs,tj}|jdk r(|djt|j7}|S)Nz[{}])rTrfrrrS)r[r)rZrCrDrfs  z_ClassVar.__repr__cCstt|j|jfS)N)rrorAr)r[rCrCrDrsz_ClassVar.__hash__cCs,t|tstS|jdk r$|j|jkS||kS)N)rlrr~r)r[rrCrCrDrs    z_ClassVar.__eq__)r)N) rArdr@rgrqr^rrarfrrrirCrC)rZrDr_s   rcCs|S)zCast a value to a type. This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don't check anything (we want this to be as fast as possible). rC)typvalrCrCrDr6sc Csy |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__rrkzip) rr|Z pos_countZ arg_namesdefaultsZ kwdefaultsrZ pos_offsetrWrrCrCrD _get_defaultss     r c Cst|ddriSt|tri}xt|jD]z}|dkrFtj|jj}n|}|jj di}xJ|j D]>\}}|dkrztd}t|t rt |}t |||}|||<qbWq*W|S|dkrt|tjr|j}n t|di}|dkr|}n |dkr|}t|dd}|dkr"t|triStdj|t|} t|}xp|j D]d\}}|dkrVtd}t|t rjt |}t |||}|| kr| |dkrt|}|||<qmodulesrdrgetitemsrmrGrar ModuleType_allowed_typesrPrr rr) rr_r`ZhintsrZ base_globalsZannrWrrrCrCrDr7sV            c Cst|tr||jj}x0|jjD]"\}}||j|fkr |j|q Wx4|jD](}t|tj rfd|_ t|trPt |qPWy d|_ Wnt k rYnX|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) rlrorcopyr'rrvaluesrrr!r9rP)r{Z arg_attrsrrrrCrCrDr9s      cstjfdd}|S)zDecorator to give another decorator the @no_type_check effect. This wraps the decorator with something that wraps the decorated function in @no_type_check. cs||}t|}|S)N)r9)r\r]r) decoratorrCrDwrapped_decorator/s z2no_type_check_decorator..wrapped_decorator)rr)r,r-rC)r,rDr:(scOs tddS)z*Helper for @overload to raise when called.zYou should not call an overloaded function. A series of @overload-decorated functions outside a stub module should always be followed by an implementation that is not @overload-ed.N)NotImplementedError)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/)rrCrCrDr;Ascs0eZdZdZfddZddZddZZS) _ProtocolMetaz~Internal metaclass for _Protocol. This exists so _Protocol classes can be generic without deriving from Generic. cs"t|jkrtj|StddS)Nz+Protocols cannot be used with isinstance().)rrrTrrP)r[r)rZrCrDres  z_ProtocolMeta.__instancecheck__csL|js tS|tkrdS|j}x(|D] tfdd|jDs$dSq$WdS)NTc3s|]}|jkVqdS)N)r)rd)rrCrDrwsz2_ProtocolMeta.__subclasscheck__..F)rhr~r_get_protocol_attrsrr)r[rVattrsrC)rrDrjs z_ProtocolMeta.__subclasscheck__cCs,g}x.|jD]$}t|ddr |jdkr |j|q Wt}x|D]}x|jjD]}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)NrhFrr__abstractmethods__r"rjrrrrqr2rrrrrrrd) rrrArrrkeysrLadd)r[Zprotocol_basesrr3rrrCrCrDr2{s<   z!_ProtocolMeta._get_protocol_attrs)rArdr@rgrrr2rirCrC)rZrDr0^s r0c@seZdZdZfZdZdS)rzInternal 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@rgrqrhrCrCrCrDrsr Awaitablec@seZdZfZdS)r7N)rArdr@rqrCrCrCrDr7s)r Coroutinec@seZdZfZdS)r8N)rArdr@rqrCrCrCrDr8s AsyncIterablec@seZdZfZdS)r9N)rArdr@rqrCrCrCrDr9sc@seZdZfZdS) AsyncIteratorN)rArdr@rqrCrCrCrDr:sr:c@seZdZfZdS)rN)rArdr@rqrCrCrCrDrsc@seZdZfZdS)rN)rArdr@rqrCrCrCrDrsc@s"eZdZfZeedddZdS)r*)returncCsdS)NrC)r[rCrCrD__int__szSupportsInt.__int__N)rArdr@rqrintr<rCrCrCrDr*sc@s"eZdZfZeedddZdS)r))r;cCsdS)NrC)r[rCrCrD __float__szSupportsFloat.__float__N)rArdr@rqrfloatr>rCrCrCrDr)sc@s"eZdZfZeedddZdS)r()r;cCsdS)NrC)r[rCrCrD __complex__szSupportsComplex.__complex__N)rArdr@rqrcomplexr@rCrCrCrDr(sc@s"eZdZfZeedddZdS)r')r;cCsdS)NrC)r[rCrCrD __bytes__szSupportsBytes.__bytes__N)rArdr@rqrbytesrBrCrCrCrDr'sc@s"eZdZfZeedddZdS)r&)r;cCsdS)NrC)r[rCrCrD__abs__szSupportsAbs.__abs__N)rArdr@rqrrrDrCrCrCrDr&sc@s&eZdZfZedeedddZdS)r+r)ndigitsr;cCsdS)NrC)r[rErCrCrD __round__szSupportsRound.__round__N)r)rArdr@rqrr=rrFrCrCrCrDr+sc@seZdZfZdS)r%N)rArdr@rqrCrCrCrDr% sc@s"eZdZfZeddddZdS)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@seZdZfZddZdS)r0cOs$|jtkrtdtt|f||S)Nz4Type List cannot be instantiated; use list() instead)rr0rPr r)rVr\r]rCrCrDrU^s z List.__new__N)rArdr@rqrUrCrCrCrDr0Zsc@seZdZfZddZdS)r-cOs*|jtkrtj||Sttj|f||S)N)rr- collectionsdequer )rVr\r]rCrCrDrUis  z Deque.__new__N)rArdr@rqrUrCrCrCrDr-esc@seZdZfZddZdS)r1cOs$|jtkrtdtt|f||S)Nz2Type Set cannot be instantiated; use set() instead)rr1rPr r)rVr\r]rCrCrDrUss z Set.__new__N)rArdr@rqrUrCrCrCrDr1osc@seZdZfZddZdS)r2cOs$|jtkrtdtt|f||S)Nz>Type FrozenSet cannot be instantiated; use frozenset() instead)rr2rPr r)rVr\r]rCrCrDrU}s zFrozenSet.__new__N)rArdr@rqrUrCrCrCrDr2zsc@seZdZfZdS)rN)rArdr@rqrCrCrCrDrsc@seZdZfZdS)rN)rArdr@rqrCrCrCrDrsc@seZdZfZdS)rN)rArdr@rqrCrCrCrDrsc@seZdZfZdS)r$N)rArdr@rqrCrCrCrDr$sAbstractContextManagerc@seZdZfZdS)rN)rArdr@rqrCrCrCrDrsc@s2eZdZfZddZejddZeddZ dS)rcCs|S)NrC)r[rCrCrD __enter__szContextManager.__enter__cCsdS)NrC)r[exc_type exc_value tracebackrCrCrD__exit__szContextManager.__exit__cCs8|tkr4tdd|jDr4tdd|jDr4dStS)Ncss|]}d|jkVqdS)rLN)r)rBrCrCrDrsz2ContextManager.__subclasshook__..css|]}d|jkVqdS)rPN)r)rrQrCrCrDrsT)rrrr~)rVCrCrCrDrs zContextManager.__subclasshook__N) rArdr@rqrLrrrP classmethodrrCrCrCrDrsAbstractAsyncContextManagerc@seZdZfZdS)AsyncContextManagerN)rArdr@rqrCrCrCrDrUsrUa 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@seZdZfZddZdS)r.cOs$|jtkrtdtt|f||S)Nz4Type Dict cannot be instantiated; use dict() instead)rr.rPr r)rVr\r]rCrCrDrUs z Dict.__new__N)rArdr@rqrUrCrCrCrDr.sc@seZdZfZddZdS)r/cOs*|jtkrtj||Sttj|f||S)N)rr/rI defaultdictr )rVr\r]rCrCrDrUs  zDefaultDict.__new__N)rArdr@rqrUrCrCrCrDr/sc@seZdZfZddZdS)r,cOs*|jtkrtj||Sttj|f||S)N)rr,rIr )rVr\r]rCrCrDrUs  zCounter.__new__N)rArdr@rqrUrCrCrCrDr,sChainMapc@seZdZfZddZdS)rXcOs*|jtkrtj||Sttj|f||S)N)rrXrIr )rVr\r]rCrCrDrUs  zChainMap.__new__N)rArdr@rqrUrCrCrCrDrXsc@seZdZfZddZdS)r4cOs$|jtkrtdtt|f||S)Nz@Type Generator cannot be instantiated; create a subclass instead)rr4rPr _G_base)rVr\r]rCrCrDrUs zGenerator.__new__N)rArdr@rqrUrCrCrCrDr4 sAsyncGeneratorc@seZdZfZdS)rZN)rArdr@rqrCrCrCrDrZsCT_co)rrc@seZdZdZfZdS)raA 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 svdfdd|D}tj|dd|D}tj||_|_ytjdjjdd|_ Wnt t fk rpYnX|S)NzDNamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a typecsg|]\}}|t|fqSrC)r})rnr)rrCrD Asz!_make_nmtuple..cSsg|] \}}|qSrCrC)rr\rrCrCrDr]BsrrA__main__) rI namedtuple OrderedDictr" _field_typesr>rrr&rdr r)rWrnm_tplrC)rrD _make_nmtuple?srcrUr^rq__getnewargs___fields_field_defaultsra_make_replace_asdict_sourcerdrAr@r"cseZdZfddZZS)NamedTupleMetac s|jddrtj||||Sts*td|jdi}t||j}g}i}xP|D]H}||krz||} |j| | ||<qR|rRtdj|dj |j dqRWt j ||j_ t||j_||_xD|D]<} | tkrtd| q| tko| |jkrt|| || qW|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 |r0tdt||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[rqZfieldskwargsrCrCrDrUs  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)rBrCrCrDnew_typeszNewType..new_type)rAZ __supertype__)rWrrurCrCrDr8sFc@seZdZdZfZeedddZeedddZe dddd Z e e dd d Z e e dd d Ze ddddZe e dddZe d7e edddZe e dddZe d9e edddZe d;e eedddZe dIOaGeneric 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[rCrCrDmodeszIO.modecCsdS)NrC)r[rCrCrDrWszIO.nameNcCsdS)NrC)r[rCrCrDcloseszIO.closecCsdS)NrC)r[rCrCrDclosedsz IO.closedcCsdS)NrC)r[rCrCrDfilenosz IO.filenocCsdS)NrC)r[rCrCrDflushszIO.flushcCsdS)NrC)r[rCrCrDisattysz IO.isattyrK)r\r;cCsdS)NrC)r[r\rCrCrDreadszIO.readcCsdS)NrC)r[rCrCrDreadablesz IO.readable)limitr;cCsdS)NrC)r[rrCrCrDreadlinesz IO.readline)hintr;cCsdS)NrC)r[rrCrCrD readlinessz IO.readlinesr)offsetwhencer;cCsdS)NrC)r[rrrCrCrDseekszIO.seekcCsdS)NrC)r[rCrCrDseekable sz IO.seekablecCsdS)NrC)r[rCrCrDtell szIO.tell)sizer;cCsdS)NrC)r[rrCrCrDtruncate sz IO.truncatecCsdS)NrC)r[rCrCrDwritable sz IO.writable)sr;cCsdS)NrC)r[rrCrCrDwrite szIO.write)linesr;cCsdS)NrC)r[rrCrCrD writelines sz IO.writelinesz IO[AnyStr]cCsdS)NrC)r[rCrCrDrL sz IO.__enter__cCsdS)NrC)r[rorrOrCrCrDrP sz IO.__exit__r)rr)rr)r)r)N) rArdr@rgrqrrmrwrWrrxrryr=rzr{r|r5r}r~rr0rrrrrrrrrLrPrCrCrCrDrvsT rvc@sBeZdZdZfZeeeefe dddZ eddddZ dS) BinaryIOz5Typed version of the return of open() in binary mode.)rr;cCsdS)NrC)r[rrCrCrDr) szBinaryIO.write)r;cCsdS)NrC)r[rCrCrDrL- szBinaryIO.__enter__N) rArdr@rgrqrrrC bytearrayr=rrLrCrCrCrDr$ s rc@seZdZdZfZeedddZeedddZ ee edddZ ee dd d Z eedd d Zeddd dZdS)TextIOz3Typed version of the return of open() in text mode.)r;cCsdS)NrC)r[rCrCrDbuffer7 sz TextIO.buffercCsdS)NrC)r[rCrCrDencoding; szTextIO.encodingcCsdS)NrC)r[rCrCrDerrors? sz TextIO.errorscCsdS)NrC)r[rCrCrDline_bufferingC szTextIO.line_bufferingcCsdS)NrC)r[rCrCrDnewlinesG szTextIO.newlinescCsdS)NrC)r[rCrCrDrLK szTextIO.__enter__N)rArdr@rgrqrrrrmrrrrrr rrrLrCrCrCrDr2 src@s&eZdZdZdddgZeZeZeZdS)ioz)Wrapper namespace for IO generic classes.rvrrN)rArdr@rg__all__rvrrrCrCrCrDrP s  rz.ioPatternrcCs|jS)N)pattern)rrCrCrD^ srMatchcCs|jjS)N)rer)mrCrCrDr` sc@s eZdZdZddgZeZeZdS)rz&Wrapper namespace for re type aliases.rrN)rArdr@rgrrrrCrCrCrDrc srz.re)rr)NN)NN)rrV)rr) rUr^rqrdrerfrargrhrirj)rdrAr@r")rrrrI contextlibrrZ stdlib_rer>rcollections.abcZcollections_abc ImportErrorr?_collections_abcrrr rorr^__str__rmrQrrErMrNrHrIrGrFrcrrar}rSrr rZNoReturnrrrrrrrrrCr5rrrrrrrrrrrrrrrr r rrr rnrr r rr r6r rBuiltinFunctionType MethodTyper(r)r7r9r:r/r;r0rrrr7rr8r9r:rrr*r)r(r'r&r+r%r#rrHr1rr!rrr"r r=rrr0rJr-rrr2rrrr$rKrrTrUexecrr.rWr/r,rXr4rY GeneratorTyperZr[rrcrmrnrorkr3r8r<r=rvrrrrAr%ryrmatchrrCrCrCrDs   *%5C  W      !)    "96    R D                  "                   "      "(`