a 4dgb$@sddlmZmZddlZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl m Z m Z mZmZgdZddZddd Zd d Zd d ZddZddZddZddZgZdddddZefddZGdddZGdddZGd d!d!edd"ZGd#d$d$edd"Z ed%d&Z!ed'd(Z"ed)d*Z#ed+d,Z$ed-d.Z%ed/d0Z&e d1d2Z'Gd3d4d4edd"Z(Gd5d6d6eedd"Z)d7d8Z*Gd9d:d:edd"Z+Gd;d<dd>e+dd"Z-Gd?d@d@e,dd"Z.GdAdBdBe-dd"Z/GdCdDdDe-dd"Z0GdEdFdFe,dd"Z1dGdHZ2GdIdJdJe,dd"Z3GdKdLdLZ4GdMdNdNZ5GdOdPdPZ6gdQZ7gdRZ8e7e8dSgZ9dTdUZ:dVdWZ;dXdYZGd`dadaeZ?Gdbdcdce4e?ddZ@Gdedfdfe,dd"ZAGdgdhdhZBdidjZCdkdlZDdmdnZEe jFe jGe jHe jIe e efZJddodpZKdqdrZLdsdtZMdudvZNdwdxZOdydzZPd{d|ZQd}d~ZRddZSe)dZTe)dZUe)dZVe)dddZWe)dddZXe)dddZYe)dddZZe)dde[dZ\e)de]e^Z_e-Z`e`ejjadZae`ejjbdZbe`ejjcdZce`ejjddZde`ejjedZee`ejjfdZfe`ejjgdZge`ejjhdZhe`ejjidZie`ejjjdZje`ejjkdZke/ejjldZldel_me`ejjndddZoe`ejjpdZpe`ejjqdZqe`ejjrdZre`ejjsdZse`ejjtdZte`ejjudZue0evddddZwdew_me`exddddZye`ejzdddZ{e`e|ddddZne`eddddZ}e`ejj~dZ~e`ejjdZe`ejjdZe`ejjdZe`ejdddZe`ejdddZe`eddddZe`ejdddZe`ejdZe`ejdZe`ejdZe`ejjdZe`ejjdZe`e[ddddZde_meCGddde@ZeCGddde@ZeCGddde@ZeCGddde@ZeCGddde@ZeCGddde@eWZeCGddde@eWZdddZehdZehdZGddde[ZdddZe[eddiZddZee_Gddde[ZdddddZe[eddiZdde_dd„Ze^ZdZGddĄde4e_ZGddƄdee]ZGddȄdee^ZGddʄdʃZede_ee jej<e`e jdZe`e jdZGdd̈́d̓Zede_ee jej<dS))abstractmethodABCMetaN)WrapperDescriptorTypeMethodWrapperTypeMethodDescriptorType GenericAlias)M AnnotatedAnyCallableClassVarFinal ForwardRefGenericLiteralOptionalProtocolTupleTypeTypeVarUnion AbstractSet ByteString ContainerContextManagerHashable ItemsViewIterableIteratorKeysViewMapping MappingViewMutableMappingMutableSequence MutableSetSequenceSized ValuesView Awaitable AsyncIterator AsyncIterable Coroutine CollectionAsyncGeneratorAsyncContextManager Reversible SupportsAbs SupportsBytesSupportsComplex SupportsFloat SupportsIndex SupportsInt SupportsRoundChainMapCounterDequeDict DefaultDictList OrderedDictSet FrozenSet NamedTuple TypedDict GeneratorBinaryIOIOMatchPatternTextIOAnyStrcastfinalget_args get_originget_type_hintsNewType no_type_checkno_type_check_decoratorNoReturnoverloadruntime_checkableText TYPE_CHECKINGcCs&|durtdSt|tr"t|S|SN)type isinstancestrr )argrZ"/usr/local/lib/python3.9/typing.py _type_converts  r\TcCsttf}|r|ttf}t|}t|trB|j|vrBt|d|t t fvrR|St|t sh|ttfvrxtd|dt|t t tfr|St|st|d|dd|S)Nz is not valid as type argumentzPlain z Got z.100.)rrr r r\rW _GenericAlias __origin__ TypeErrorr rP _SpecialFormrVrr callable)rYmsg is_argumentinvalid_generic_formsrZrZr[ _type_checks"    rfcCsft|tjrt|St|tr@|jdkr.|jS|jd|jS|durLdSt|tjr^|jSt|S)Nbuiltinsr].z...) rWtypesrreprrV __module__ __qualname__ FunctionType__name__)objrZrZr[ _type_reprs    rocsZg|D]H}t|tr(|vr(|t|ttfrfdd|jDqtS)Ncsg|]}|vr|qSrZrZ.0ttvarsrZr[ z&_collect_type_vars..)rWrappendr^rextend__parameters__tuple)rhrrrZrsr[_collect_type_varss r{c CsR|st|dt|}||krNtd||kr2dndd|d|d|dS)Nz is not a generic classzToo manyfewz parameters for z ; actual z , expected )r`len)cls parameterselenalenrZrZr[_check_genericsrcCsJt|}t|t|krFg}|D] }||vr ||||q |}|SrU)setr~rwremove)params all_params new_paramsrrrZrZr[ _deduplicates  rcCsrg}|D]\}t|tr$||jqt|trZt|dkrZ|dturZ||ddq||qtt|S)Nr) rW_UnionGenericAliasrx__args__rzr~rrwrrrprZrZr[_remove_dups_flattens " rcCs8g}|D]&}t|tr$||jq||qt|SrU)rW_LiteralGenericAliasrxrrwrzrrZrZr[_flatten_literal_paramss   rFtypedcs fdd}|dur||S|S)Ncs8tjdtjtfdd}|S)Nrcs2z|i|WSty"Yn0|i|SrUr`argskwdscachedfuncrZr[inner s  z+_tp_cache..decorator..inner) functools lru_cache _cleanupsrw cache_clearwraps)rrrrr[ decorator s  z_tp_cache..decoratorrZ)rrrrZrr[ _tp_caches rcstt|tr|St|ttfrptfdd|jD}||jkrP|St|trft|j|S||S|S)Nc3s|]}t|VqdSrU) _eval_typerqaglobalnslocalnsrecursive_guardrZr[ $rvz_eval_type..) rWr _evaluater^rrzrr_ copy_with)rrrrrev_argsrZrr[rs     rc@seZdZdZddZdS)_Final) __weakref__cOsd|vrtddS)N_rootz&Cannot subclass special typing classesrselfrrrZrZr[__init_subclass__3sz_Final.__init_subclass__N)rmrjrk __slots__rrZrZrZr[r.src@s eZdZdZddZddZdS) _ImmutablerZcCs|SrUrZrrZrZr[__copy__;sz_Immutable.__copy__cCs|SrUrZ)rmemorZrZr[ __deepcopy__>sz_Immutable.__deepcopy__N)rmrjrkrrrrZrZrZr[r7src@sTeZdZdZddZddZddZdd Zd d Zd d Z ddZ e ddZ dS)ra)_name__doc___getitemcCs||_|j|_|j|_dSrU)rrmrr)rgetitemrZrZr[__init__Gsz_SpecialForm.__init__cCstd|dS)NzCannot subclass r)rbasesrZrZr[__mro_entries__Lsz_SpecialForm.__mro_entries__cCs d|jSNtyping.rrrZrZr[__repr__Osz_SpecialForm.__repr__cCs|jSrUrrrZrZr[ __reduce__Rsz_SpecialForm.__reduce__cOstd|dS)NzCannot instantiate rrrZrZr[__call__Usz_SpecialForm.__call__cCst|ddS)Nz! cannot be used with isinstance()rrrnrZrZr[__instancecheck__Xsz_SpecialForm.__instancecheck__cCst|ddS)Nz! cannot be used with issubclass()rrrrZrZr[__subclasscheck__[sz_SpecialForm.__subclasscheck__cCs |||SrUrrrrZrZr[ __getitem__^sz_SpecialForm.__getitem__N) rmrjrkrrrrrrrrrrrZrZrZr[raDsra)rc@seZdZeddddZdS)_LiteralSpecialFormTrcCs |||SrUrrrZrZr[rdsz_LiteralSpecialForm.__getitem__NrmrjrkrrrZrZrZr[rcsrcCst|ddSNz is not subscriptablerrrZrZr[r is r cCst|ddSrrrrZrZr[rPws rPcCst||d}t||fSNz accepts only single type.rfr^rritemrZrZr[r sr cCst||d}t||fSrrrrZrZr[r sr cs`|dkrtdt|ts |f}dtfdd|D}t|}t|dkrV|dSt||S)NrZz Cannot take a Union of no types.z)Union[arg, ...]: each arg must be a type.c3s|]}t|VqdSrUrfrqrrcrZr[rrvzUnion..rr)r`rWrzrr~rrrZrr[rs  rcCs t||d}t|tdfS)Nz requires a single type.)rfrrV)rrrYrZrZr[rsrcCsXt|ts|f}t|}z"tddttt|D}WntyLYn0t||S)Ncss|]\}}|VqdSrUrZ)rqr_rZrZr[rrvzLiteral..)rWrzrrlist_value_and_type_iterr`rrrZrZr[rs " rc@s:eZdZdZdddZddZddZd d Zd d Zd S)r )__forward_arg____forward_code____forward_evaluated____forward_value____forward_is_argument__TcCslt|tstd|zt|dd}Wn tyHtd|Yn0||_||_d|_d|_||_ dS)Nz*Forward reference must be a string -- got zevalz/Forward reference must be an expression -- got F) rWrXr`compile SyntaxErrorrrrrr)rrYrdcoderZrZr[r s  zForwardRef.__init__cCs|j|vr|S|jr||ur|dur6|dur6i}}n|durD|}n |durP|}tt|j||d|jd}t|||||jhB|_d|_|jS)Nz*Forward references must evaluate to types.rdT)rrrfrrrrr)rrrrtype_rZrZr[rs&   zForwardRef._evaluatecCs>t|tstS|jr2|jr2|j|jko0|j|jkS|j|jkSrU)rWr NotImplementedrrrrotherrZrZr[__eq__,s    zForwardRef.__eq__cCs t|jSrU)hashrrrZrZr[__hash__4szForwardRef.__hash__cCsd|jdS)Nz ForwardRef())rrrZrZr[r7szForwardRef.__repr__N)T) rmrjrkrrrrrrrZrZrZr[r s  r c@s2eZdZdZddddddZddZd d ZdS) r)rm __bound____constraints__ __covariant____contravariant____dict__NF)bound covariant contravariantc s||_|r|rtdt||_t||_|r>|dur>td|rVt|dkrVtddtfdd|D|_|rt |d|_ nd|_ zt dj d d }Wnttfyd}Yn0|d kr||_dS) Nz"Bivariant types are not supported.z-Constraints cannot be combined with bound=...rz"A single constraint is not allowedz:TypeVar(name, constraint, ...): constraints must be types.c3s|]}t|VqdSrUrrprrZr[rvrvz#TypeVar.__init__..zBound must be a type.rm__main__typing)rm ValueErrorboolrrr`r~rzrrfrsys _getframe f_globalsgetAttributeErrorrj)rnamerrr constraintsdef_modrZrr[rjs(    zTypeVar.__init__cCs&|jr d}n|jrd}nd}||jS)N+-~)rrrm)rprefixrZrZr[rs zTypeVar.__repr__cCs|jSrU)rmrrZrZr[rszTypeVar.__reduce__)rmrjrkrrrrrZrZrZr[r;s ,  rcCs|do|dS)N__) startswithendswith)attrrZrZr[ _is_dundersr csTeZdZdddddZddZdd Zd d Zfd d ZddZddZ Z S)_BaseGenericAliasTNinstrcCs||_||_||_d|_dSrU)_instrr_r)roriginr rrZrZr[rsz_BaseGenericAlias.__init__cOsT|js"td|jd|jjd|j|i|}z ||_WntyNYn0|S)NzType z cannot be instantiated; use z () instead)r r`rr_rm__orig_class__r)rrkwargsresultrZrZr[rs    z_BaseGenericAlias.__call__cCsdg}|j|vr||j||}||ddD]}t|tsLt|tr4q\q4|tt|S)Nr)r_rwindexrWr  issubclassrrz)rrresibrZrZr[rs    z!_BaseGenericAlias.__mro_entries__cCs*d|jvrt|st|j|St|dS)Nr_)rr getattrr_r)rrrZrZr[ __getattr__s z_BaseGenericAlias.__getattr__cs2t|s|dvr t||nt|j||dS)N)rr _nparams)r super __setattr__setattrr_)rrval __class__rZr[rsz_BaseGenericAlias.__setattr__cCs|t|SrU)rrVrrZrZr[rsz#_BaseGenericAlias.__instancecheck__cCs tddS)NzBSubscripted generics cannot be used with class and instance checksrrrZrZr[rsz#_BaseGenericAlias.__subclasscheck__) rmrjrkrrrrrrr __classcell__rZrZrr[r s    r csdeZdZdddfdd ZddZdd Zed d Zd d ZddZ ddZ fddZ Z S)r^TNr csPtj|||dt|ts"|f}tdd|D|_t||_|sL|j|_dS)Nr css*|]"}|turdn|turdn|VqdS).rZN)_TypingEllipsis _TypingEmptyrrZrZr[rs  z)_GenericAlias.__init__..)rrrWrzrr{ryrj)rrrr rrrZr[rs   z_GenericAlias.__init__cCs&t|tstS|j|jko$|j|jkSrU)rWr^rr_rrrZrZr[rs    z_GenericAlias.__eq__cCst|j|jfSrU)rr_rrrZrZr[rsz_GenericAlias.__hash__cs|jttfvrtd|t|ts,|f}dtfdd|D}t||t|jt t |j|g}|j D]X}t|t r|}n6t|t tfr|j}|rtfdd|D}||}||qr|t|S)Nz%Cannot subscript already-subscripted *Parameters to generic types must be types.c3s|]}t|VqdSrUrrrrZr[rrvz,_GenericAlias.__getitem__..c3s|]}|VqdSrUrZ)rqx)substrZr[rrv)r_rrr`rWrzrr~rydictziprrr^rrwr)rrnew_argsrY subparamssubargsrZ)rcr%r[rs&     z_GenericAlias.__getitem__cCs|j|j||j|jdSN)rr )rr_rr rrrZrZr[rsz_GenericAlias.copy_withcCsB|jrd|j}n t|j}ddd|jD}|d|dS)Nr, cSsg|] }t|qSrZrorrZrZr[ru rvz*_GenericAlias.__repr__..[])rror_joinr)rrrrZrZr[rs   z_GenericAlias.__repr__cCsR|jrt|j}n|j}t|j}t|dkrDt|dtsD|\}tj||ffS)Nrr) rglobalsr_rzrr~rWoperatorr)rrrrZrZr[rs z_GenericAlias.__reduce__csh|jrt|S|jtur`t|vr(dS||}||ddD]}t|trB||urBdSqB|jfS)NrZr) rrrr_rrrrWr )rrrrrrZr[rs   z_GenericAlias.__mro_entries__) rmrjrkrrrrrrrrrr rZrZrr[r^s   r^csTeZdZdddfdd ZeddZdd Zd d Zfd d ZddZ Z S)_SpecialGenericAliasTNr cs^|dur|j}tj|||d||_|jdkrBd|jd|_nd|jd|jd|_dS)Nr rgzA generic version of r])rmrrrrjrkr)rrnparamsr rrrZr[r,s z_SpecialGenericAlias.__init__csBt|ts|f}dtfdd|D}t|||j||S)Nr#c3s|]}t|VqdSrUrrrrZr[r;rvz3_SpecialGenericAlias.__getitem__..)rWrzrrrr,rZrr[r6s  z _SpecialGenericAlias.__getitem__cCst|j||j|jdSr+)r^r_rr r,rZrZr[r?sz_SpecialGenericAlias.copy_withcCs d|jSrrrrZrZr[rCsz_SpecialGenericAlias.__repr__cs:t|trt|j|jSt|ts.t||jSt|SrU)rWr4rr_r^rrrrrZr[rFs    z&_SpecialGenericAlias.__subclasscheck__cCs|jSrUrrrZrZr[rMsz_SpecialGenericAlias.__reduce__) rmrjrkrrrrrrrr rZrZrr[r4+s   r4cs$eZdZfddZddZZS)_CallableGenericAliascs\t|jdkr&|jdtur&tSdddd|jddDdt|jdd S) Nrztyping.Callable[[r-cSsg|] }t|qSrZr.rrZrZr[ruWrvz2_CallableGenericAlias.__repr__..z], r0)r~rEllipsisrrr1rorrrZr[rRs  z_CallableGenericAlias.__repr__cCsD|j}t|dkr|ddus6t|dd|df}tjt|ffS)Nr7r.r8)rr~rr3rr rrrZrZr[rZsz _CallableGenericAlias.__reduce__)rmrjrkrrr rZrZrr[r6Qs r6c@s(eZdZddZddZeddZdS) _CallableTypecCst|j||j|jdSr+)r6r_rr r,rZrZr[rbsz_CallableType.copy_withcCsPt|trt|dkrtd|\}}t|tr>t||f}n||f}||S)Nr7z6Callable must be used as Callable[[arg, ...], result].)rWrzr~r`r__getitem_inner__)rrrrrZrZr[rfs z_CallableType.__getitem__cCsb|\}}d}t||}|tur,|t|fSt|ts<|f}tdd|D}||f}||S)Nz.Callable[args, result]: result must be a type.css|]}t|VqdSrU)r\)rqrYrZrZr[r}rvz2_CallableType.__getitem_inner__..)rfr9rr!rWrz)rrrrrcrZrZr[r<ts   z_CallableType.__getitem_inner__N)rmrjrkrrrr<rZrZrZr[r;asr;c@seZdZeddZdS) _TupleTypecs|dkr|tfSt|ts$|f}t|dkr\|ddur\dt|d}||tfSdtfdd |D}||S) NrZr7r.z Tuple[t, ...]: t must be a type.rz*Tuple[t0, t1, ...]: each t must be a type.c3s|]}t|VqdSrUrrrrZr[rrvz)_TupleType.__getitem__..)rr"rWrzr~rfr!)rrrrZrr[rs  z_TupleType.__getitem__NrrZrZrZr[r=sr=cs4eZdZddZddZddZfddZZS) rcCst|SrU)rr,rZrZr[rsz_UnionGenericAlias.copy_withcCs"t|tstSt|jt|jkSrU)rWrrrrrrZrZr[rs z_UnionGenericAlias.__eq__cCstt|jSrU)r frozensetrrrZrZr[rsz_UnionGenericAlias.__hash__csd|j}t|dkrZ|dtdur6dt|ddS|dtdurZdt|ddStS)Nr7rztyping.Optional[rr0)rr~rVrorrr:rrZr[rs z_UnionGenericAlias.__repr__)rmrjrkrrrrr rZrZrr[rsrcCsdd|DS)Ncss|]}|t|fVqdSrU)rVrrZrZr[rrvz'_value_and_type_iter..rZ)rrZrZr[rsrc@seZdZddZddZdS)rcCs*t|tstStt|jtt|jkSrU)rWrrrrrrrZrZr[rs z_LiteralGenericAlias.__eq__cCsttt|jSrU)rr>rrrrZrZr[rsz_LiteralGenericAlias.__hash__N)rmrjrkrrrZrZrZr[rsrcs0eZdZdZdZeddZfddZZS)rrZFcst|ts|f}|s.|tur.td|jddtfdd|D}|ttfvrtdd|Dsxtd|jdt t |t |krtd|jd nt ||t |j t ||S) NzParameter list to z[...] cannot be emptyr#c3s|]}t|VqdSrUrrrrZr[rrvz,Generic.__class_getitem__..css|]}t|tVqdSrU)rWrrrZrZr[rrvzParameters to z [...] must all be type variablesz[...] must all be unique)rWrzrr`rkrrallrmr~rrryr^)rrrZrr[__class_getitem__s&      zGeneric.__class_getitem__c stj|i|g}d|jvr,t|jv}nt|jvo>|jdk}|rLtdd|jvrt|j}d}|jD].}t |t rl|j turl|durtd|j }ql|durt |}t ||ksdfdd|D}ddd|D} td |d | d |}t||_ dS) N__orig_bases__rz!Cannot inherit from plain Genericz0Cannot inherit from Generic[...] multiple types.r-c3s|]}|vrt|VqdSrUrXrpgvarsetrZr[rrvz,Generic.__init_subclass__..css|]}t|VqdSrUrB)rqgrZrZr[rrvzSome type variables (z) are not listed in Generic[r0)rrrrrA __bases__rmr`r{rWr^r_ryrr1rz) rrrrterrorgvarsbasetvarsets_varss_argsrrCr[rs<          zGeneric.__init_subclass__) rmrjrkr _is_protocolrr@rr rZrZrr[rs  rc@s eZdZdS)r"NrmrjrkrZrZrZr[r" sr"c@s eZdZdS)r!NrNrZrZrZr[r!sr!)ryrArrM_is_runtime_protocol) __abstractmethods____annotations__rrrrj__new__r__subclasshook__rr@_MutableMapping__markercCsrt}|jddD]X}|jdvr$qt|di}t|jt|D] }|dsJ|tvrJ| |qJq|S)Nr8)rrrQ_abc_) r__mro__rmrrrkeysrEXCLUDED_ATTRIBUTESadd)rattrsrI annotationsrrZrZr[_get_protocol_attrss  r\cstfddtDS)Nc3s|]}tt|dVqdSrU)rbrrqrrrZr[r2rvz,_is_callable_members_only..)r?r\r^rZr^r[_is_callable_members_only0sr_cOst|jrtddS)Nz Protocols cannot be instantiated)rVrMr`)rrrrZrZr[_no_init5s r`c Cs4ztdjddvWSttfy.YdS0dS)Nrm)abcrT)rrrrrrZrZrZr[_allow_reckless_class_cheks:src) r r'rrr)rr%rr+r.AbstractContextManagerAbstractAsyncContextManager)zcollections.abc contextlibcseZdZfddZZS) _ProtocolMetacsVtddrtr$tjr$dSjrJtfddtDrJdStS)NrMFTc3s8|]0}t|o.tt|d p.t|duVqdSrU)hasattrrbrr]rinstancerZr[rZs z2_ProtocolMeta.__instancecheck__..) rr_rrrMr?r\rrrirrir[rRs  z_ProtocolMeta.__instancecheck__)rmrjrkrr rZrZrr[rgOsrgcs(eZdZdZdZdZfddZZS)rrZTFcstj|i|jdds6tddjD_fdd}djvrR|_js\dSjD]F}|tt fvsb|j t vr|j t |j vsbt |t r|jsbtd|qbt_dS) NrMFcss|]}|tuVqdSrU)r)rqrrZrZr[rrvz-Protocol.__init_subclass__..csjddstStdds0tr(tStdtsJtrBtStdt|ts\tdt D]v}|j D]b}||jvr|j|durtSqdt|di}t|t j j rn||vrnt|trn|jrnqdqntSqddS) NrMFrOzLInstance and class checks can only be used with @runtime_checkable protocolsz._proto_hookrSz7Protocols can only inherit from other protocols, got %r)rrrranyrFrMrSobjectrrj_PROTO_WHITELISTrmrr`r`r)rrrrlrIrr^r[rs, &   zProtocol.__init_subclass__)rmrjrkrrMrOrr rZrZrr[rcsr) metaclasscsDeZdZfddZddZddZddZd d Zd d ZZ S) _AnnotatedAliascs2t|tr|j|}|j}t||||_dSrU)rWrq __metadata__r_rr)rrmetadatarrZr[rs   z_AnnotatedAlias.__init__cCs|d}t||jS)Nr)rqrr)rrnew_typerZrZr[rsz_AnnotatedAlias.copy_withcCs$dt|jddd|jDS)Nztyping.Annotated[{}, {}]r-css|]}t|VqdSrU)rirrZrZr[rrvz+_AnnotatedAlias.__repr__..)formatror_r1rrrrZrZr[rsz_AnnotatedAlias.__repr__cCstjt|jf|jffSrU)r3rrr_rrrrZrZr[rsz_AnnotatedAlias.__reduce__cCs&t|tstS|j|jko$|j|jkSrU)rWrqrr_rrrrZrZr[rs    z_AnnotatedAlias.__eq__cCst|j|jfSrU)rr_rrrrZrZr[rsz_AnnotatedAlias.__hash__) rmrjrkrrrrrrr rZrZrr[rqs  rqc@s,eZdZdZddZeddZddZdS) rrZcOs tddS)Nz&Type Annotated cannot be instantiated.rrrrrZrZr[rRszAnnotated.__new__cCsJt|trt|dkrtdd}t|d|}t|dd}t||S)Nr7zUAnnotated[...] should be used with at least two arguments (a type and an annotation).z$Annotated[t, ...]: t must be a type.rr)rWrzr~r`rfrq)rrrcrrsrZrZr[r@s zAnnotated.__class_getitem__cOstd|jdS)NzCannot subclass {}.Annotated)r`rurjrvrZrZr[rs zAnnotated.__init_subclass__N)rmrjrkrrRrr@rrZrZrZr[rs  rcCs&t|tr|jstd|d|_|S)NzB@runtime_checkable can be only applied to protocol classes, got %rT)rrrMr`rOr^rZrZr[rR#s rRcCs|SrUrZ)typrrZrZr[rH<srHc Csz |j}Wnty iYS0|j}|j}|d|}|jpBd}|j}|rVt|ni}|t|}t||d|D]\}} | ||<qx|S)NrZ) __code__r co_argcount co_varnames __defaults____kwdefaults__r&r~r') rr pos_count arg_namesdefaults kwdefaultsr pos_offsetrvaluerZrZr[ _get_defaultsGs       rc Cst|ddriSt|tri}t|jD]z}|durDtj|jj}n|}|j di}| D]B\}} | durvtd} t| t rt | dd} t | ||} | ||<q^q(|r|Sdd| DS|durt|tjr|j}n"|} t| dr| j} qt| di}|dur|}n|dur|}t|dd}|durPt|trBiStd |t|} t|}| D]d\}} | durtd} t| t rt | } t | ||} || vr| |durt| } | ||<qh|r|Sd d| DS) N__no_type_check__rQFrcSsi|]\}}|t|qSrZ_strip_annotationsrqkrrrZrZr[ rvz"get_type_hints.. __wrapped__ __globals__z1{!r} is not a module, class, method, or function.cSsi|]\}}|t|qSrZrrrZrZr[rrv)rrWrVreversedrVrmodulesrjrritemsrXr rrh ModuleTyperhr_allowed_typesr`rurr&r) rnrrinclude_extrashintsrI base_globalsannrrnsobjrrZrZr[rL`s^                   rLcCst|trt|jSt|trJtdd|jD}||jkr@|S||St|trtdd|jD}||jkrv|St|j|S|S)Ncss|]}t|VqdSrUrrrZrZr[rrvz%_strip_annotations..css|]}t|VqdSrUrrrZrZr[rrv) rWrqrr_r^rzrrr)rr stripped_argsrZrZr[rs        rcCs2t|trtSt|ttfr"|jS|tur.tSdSrU)rWrqrr rr_r)tprZrZr[rKs rKcCsft|tr|jf|jSt|ttfrb|j}|jtjj ur^|dt ur^t |dd|df}|SdS)Nrr8rZ) rWrqr_rrr^rrrkrbr r9r)rrrZrZr[rJs rJcCst|trt|j}|jD]"\}}||j|fvr||q|D](}t|tj r`d|_ t|trJt |qJz d|_ Wnt yYn0|S)NT) rWrVrcopyrrFpopvaluesrhrlrrNr`)rY arg_attrsrrrnrZrZr[rNs         rNcstfdd}|S)Ncs|i|}t|}|SrU)rN)rrrrrZr[wrapped_decoratorsz2no_type_check_decorator..wrapped_decorator)rr)rrrZrr[rOsrOcOs tddS)NzYou 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.)NotImplementedErrorrrZrZr[_overload_dummysrcCstSrU)r)rrZrZr[rQ(srQcCs|SrUrZ)frZrZr[rIEsrITKTVTT_co)rV_coVT_coT_contra)rCT_co)rrrGrrar7aCallable 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. r)rr8rr a@Tuple type; Tuple[X, Y] is the cross-product type of X and Y. Example: Tuple[T1, T2] is a tuple of two elements corresponding to type variables T1 and T2. Tuple[int, float, str] is a tuple of an int, a float and a string. To specify a variable-length tuple of homogeneous type, use Tuple[T, ...]. r;r8r=r>rr-r9r: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. c@s"eZdZdZeedddZdS)r4rZreturncCsdSrUrZrrZrZr[__int__szSupportsInt.__int__N)rmrjrkrrintrrZrZrZr[r4sr4c@s"eZdZdZeedddZdS)r2rZrcCsdSrUrZrrZrZr[ __float__szSupportsFloat.__float__N)rmrjrkrrfloatrrZrZrZr[r2sr2c@s"eZdZdZeedddZdS)r1rZrcCsdSrUrZrrZrZr[ __complex__szSupportsComplex.__complex__N)rmrjrkrrcomplexrrZrZrZr[r1sr1c@s"eZdZdZeedddZdS)r0rZrcCsdSrUrZrrZrZr[ __bytes__szSupportsBytes.__bytes__N)rmrjrkrrbytesrrZrZrZr[r0sr0c@s"eZdZdZeedddZdS)r3rZrcCsdSrUrZrrZrZr[ __index__szSupportsIndex.__index__N)rmrjrkrrrrrZrZrZr[r3sr3c@s"eZdZdZeedddZdS)r/rZrcCsdSrUrZrrZrZr[__abs__szSupportsAbs.__abs__N)rmrjrkrrrrrZrZrZr[r/sr/c@s&eZdZdZedeedddZdS)r5rZr)ndigitsrcCsdSrUrZ)rrrZrZr[ __round__szSupportsRound.__round__N)r)rmrjrkrrrrrrZrZrZr[r5sr5rZcCs@dd|D}dd|D}tj||||d}||_|j_|S)NcSsg|] \}}|qSrZrZrqnrrrZrZr[rurvz!_make_nmtuple..cSs$i|]\}}|t|d|dqS)zfield z annotation must be a typerrrZrZr[rsz!_make_nmtuple..rmodule)rk namedtuplerQrR)rrhrrfieldsnm_tplrZrZr[ _make_nmtuple sr> _field_defaults__getnewargs__rR_maker_fields_replace_asdict_sourcer>rQrjrmc@seZdZddZdS)NamedTupleMetac sdi}g}|D]L}|vr,||q|rtd|dt|dkrJdnddd|qt||fd d |Dd d }D]<}|tvrtd |q|t vr||j vrt |||q|S)NrQzNon-default namedtuple field z cannot follow default fieldrs r-csg|] }|qSrZrZ)rqrnsrZr[ru.rvz*NamedTupleMeta.__new__..rjrz&Cannot overwrite NamedTuple attribute ) rrwr`r~r1rr _prohibitedr_specialrr) rtypenamerrrh default_names field_namerkeyrZrr[rR!s*     zNamedTupleMeta.__new__N)rmrjrkrRrZrZrZr[rsrc Ks`|dur|}n |rtdztdjdd}WnttfyPd}Yn0t|||dS)NzIEither list of fields or keywords can be provided to NamedTuple, not bothrrmr)r) rr`rrrrrrr)rrrrrZrZr[r?9s  r?cCst|dkrtdtfS)Nrz5Multiple inheritance with NamedTuple is not supported)r~r` _NamedTuplerrZrZr[_namedtuple_mro_entries^s rc@s&eZdZdddZeZddZeZdS)_TypedDictMetaTc s |D]}t|turtdqtt|tf|}i}|di}t|} dfdd|D}t} t} |D]@}| |j di| |j dd| |j ddqv| ||r| | n | | ||_ t | |_ t | |_t|d s||_|S) NzHcannot inherit from both a TypedDict type and a non-TypedDict base classrQz?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typecsi|]\}}|t|qSrZr)rqrrrrZr[rzsz*_TypedDictMeta.__new__..__required_keys__rZ__optional_keys__ __total__)rVrr`rRr&rrrWrupdaterrQr>rrrhr) rrrrtotalrItp_dictr[own_annotationsown_annotation_keys required_keys optional_keysrZrr[rRhs6           z_TypedDictMeta.__new__cCs tddS)Nz4TypedDict does not support instance and class checksr)rrrZrZr[rsz _TypedDictMeta.__subclasscheck__N)T)rmrjrkrRr&rrrrZrZrZr[rgs *rrc Ksj|dur|}n |rtddt|i}ztdjdd|d<WnttfyXYn0t|d||dS) Nz@TypedDict takes either a dict or keyword arguments, but not bothrQrrmrrjrZr) r`r&rrrrrrr)rrrrrrZrZr[r@s* r@cCstfSrU) _TypedDictrrZrZr[rvrcCsdd}||_||_|S)NcSs|SrUrZ)r$rZrZr[rtszNewType..new_type)rm __supertype__)rrrtrZrZr[rMsrMc@seZdZdZeeedddZeeedddZedddd Z eee dd d Z ee dd d Z eddddZee dddZed6e edddZee dddZed7e edddZed8e eedddZed9e e e dd d!Zee dd"d#Zee dd$d%Zed:e e d&d'd(Zee dd)d*Zeee d+d,d-Zeeedd.d/d0Zed1dd2d3Zeddd4d5ZdS);rCrZrcCsdSrUrZrrZrZr[mode szIO.modecCsdSrUrZrrZrZr[rszIO.nameNcCsdSrUrZrrZrZr[closeszIO.closecCsdSrUrZrrZrZr[closedsz IO.closedcCsdSrUrZrrZrZr[filenosz IO.filenocCsdSrUrZrrZrZr[flush!szIO.flushcCsdSrUrZrrZrZr[isatty%sz IO.isattyr8)rrcCsdSrUrZ)rrrZrZr[read)szIO.readcCsdSrUrZrrZrZr[readable-sz IO.readable)limitrcCsdSrUrZ)rrrZrZr[readline1sz IO.readline)hintrcCsdSrUrZ)rrrZrZr[ readlines5sz IO.readlinesr)offsetwhencercCsdSrUrZ)rrrrZrZr[seek9szIO.seekcCsdSrUrZrrZrZr[seekable=sz IO.seekablecCsdSrUrZrrZrZr[tellAszIO.tell)sizercCsdSrUrZ)rrrZrZr[truncateEsz IO.truncatecCsdSrUrZrrZrZr[writableIsz IO.writablerrcCsdSrUrZrrrZrZr[writeMszIO.write)linesrcCsdSrUrZ)rrrZrZr[ writelinesQsz IO.writelinesz IO[AnyStr]cCsdSrUrZrrZrZr[ __enter__Usz IO.__enter__cCsdSrUrZ)rrVr tracebackrZrZr[__exit__Ysz IO.__exit__)r8)r8)r8)r)N)rmrjrkrpropertyrrXrrrrrrrrrrGrrrr;rrrrrrrrrrrZrZrZr[rCsX rCc@s>eZdZdZeeeefedddZ eddddZ dS) rBrZrcCsdSrUrZrrZrZr[rcszBinaryIO.writercCsdSrUrZrrZrZr[rgszBinaryIO.__enter__N) rmrjrkrrrr bytearrayrrrrZrZrZr[rB^s rBc@seZdZdZeeedddZeeedddZ eee edddZ eee dd d Z eeedd d Zeddd dZdS)rFrZrcCsdSrUrZrrZrZr[bufferqsz TextIO.buffercCsdSrUrZrrZrZr[encodingvszTextIO.encodingcCsdSrUrZrrZrZr[errors{sz TextIO.errorscCsdSrUrZrrZrZr[line_bufferingszTextIO.line_bufferingcCsdSrUrZrrZrZr[newlinesszTextIO.newlinescCsdSrUrZrrZrZr[rszTextIO.__enter__N)rmrjrkrrrrBrrXrrrrrr rrrZrZrZr[rFls$rFc@s eZdZgdZeZeZeZdS)io)rCrFrBN)rmrjrk__all__rCrFrBrZrZrZr[rsrz.ioc@seZdZddgZeZeZdS)rerErDN)rmrjrkrrErDrZrZrZr[r sr z.re)T)N)NNF)rZ)N)N)rbrrrkcollections.abcrfrr3r  stdlib_rerrhrrrrrr\rfror{rrrrrrr>rrrrarr rPr r rrrr rr r r^r4r6r;r=rrrrr"r!_TYPING_INTERNALS_SPECIAL_NAMESrXr\r_r`rcrorgrrqrrRrHrrlBuiltinFunctionType MethodTyperrrLrrKrJrNrOrrQrIrrrrrrrrVrrrXrG_aliasrr'r*r)r(rrr.r%rr+r rr=rr#rr!r$r"rrzrrr;dequer8rr>r rrr&rdrrer-r&r9 defaultdictr:r<r7r6rAr,rr4r2r1r0r3r/r5rrrrr?rRrrrrr@rrMrSrTrCrBrFrrmrrErDrZrZrZr[sd`          %  $8TFS&! Q  b)5  W                    #49 c#