U e5db G@sddlmZmZddlZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl m Z m Z mZdddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJgGZddLdMZdNdOZdPdQZdRdSZdTdUZdVdWZgZdXdYZdZd[ZGd\d]d]ZGd^d_d_ZGd`dadaeedKdbZeddcddZedFdeddZeddfddZeddgddZeddhddZ ed diddZ!ed djddZ"GdkddedKdbZ#GdlddeedKdbZ$d6d d4d8d9d3d5dddm Z%dndoZ&GdpdqdqedKdbZ'Gdrdsdse'dKdbZ(Gdtd d Z)GdudvdvZ*GdwdxdxZ+dydzd{d|d}gZ,d~dddddddddg Z-e,e-dgZ.ddZ/ddZ0ddZ1ddZ2dd"ddd$dd dd&d)g ddgdZ3GdddeZ4Gdd d e)e4dZ5ddHZ6dd>Z7ddZ8e j9e j:e j;e jddAZ?dd@Z@ddDZAddEZBddZCddGZDdd?ZEe$dZFe$dZGe$dZHe$ddKdZIe$ddKdZJe$ddKdZKe$ddKdZLe$ddKeMdZNe$d=eOePZQdddZReRejjSdZSeRejjTeIZTeRejjUeIeLeJfZUeRejjVeIZVeRejjWeIZWeRejjXeIZXeRejjYeIZYeRejjZeIZZeRejj[dZ[eRejj\eIZ\eRejj]eIZ]e(ejj^ddKdZ^de^__eRejj`eIZaeRejjbeFZbeRejjceGeKfZceRejjdeGeHfZdeRejjeeIZeeRejjfeFZfeRejjgdZge(ehdddKdZidei__eRejeFddZkeRejleFZmeReneFddZ`eReoeIddZpeRejjqeIZqeRejjreGZreRejjseGeKfZseRejjteKZteRejueIZveRejweIZxeReyeGeHfddZzeRej{eGeHfZ|eRej}eGeHfZ}eRej~eFZ~eRejeGeHfZeRejjeIeLeJfZeRejjeIeLfZeReMeNddZde__e6Gdd/d/e5Ze6Gdd-d-e5Ze6Gdd,d,e5Ze6Gdd+d+e5Ze6Gdd.d.e5Ze6Gdd*d*e5eIZe6Gdd0d0e5eIZdd„ZdZdZGddƄdeMZGdd:d:edZddɄZddKdʜdd̄Zdd΄ZGddЄdeMZGdd;d;eyedZddCZePZdZGddԄde)eQZGddքdeeOZGdd؄deePZGddڄdڃZede_ee jej<eRe jeQZeRe jeQZGdd݄d݃Zede_ee jej<dS))abstractmethodABCMetaN)WrapperDescriptorTypeMethodWrapperTypeMethodDescriptorTypeAnyCallableClassVarFinal 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 GeneratorAnyStrcastfinalget_args get_originget_type_hintsNewType no_type_checkno_type_check_decoratorNoReturnoverloadruntime_checkableText TYPE_CHECKINGTcCsttf}|r|ttf}|dkr(tdSt|tr:t|St|tr\|j |kr\t |dt|t rr|t t fks~|ttfkrt d|dt|tttfr|St|st |d|dd|S)Nz is not valid as type argumentzPlain z Got z.100.)r rr r type isinstancestrr _GenericAlias __origin__ TypeError _SpecialFormrrIrcallable)argmsg is_argumentZinvalid_generic_formsrZ/usr/lib64/python3.8/typing.py _type_checkxs(     r\cCsRt|tr,|jdkr|jS|jd|jS|dkr8dSt|tjrJ|jSt|S)NbuiltinsrN.z...)rPrO __module__ __qualname__types FunctionType__name__repr)objrZrZr[ _type_reprs   recs\g|D]J}t|tr(|kr(|t|tr|jsfdd|jDqtS)Ncsg|]}|kr|qSrZrZ.0ttvarsrZr[ sz&_collect_type_vars..)rPrappendrR_specialextend__parameters__tuple)r`rhrZrir[_collect_type_varss rqcCst|ts|St|j}t|jD]J\}}t|tr\t|D]\}}||kr<||||<qdndd|d|d|dS)Nz is not a generic classzToo ZmanyZfewz parameters for z ; actual z , expected )rorTlen)cls parametersZalenZelenrZrZr[_check_generics  r~cCsg}|D]f}t|tr.|jtkr.||jqt|trdt|dkrd|dtkrd||ddq||qt |}t|t|krg}|D] }||kr||| |q|}t|S)Nr) rPrRrSrrnrtrpr{rlsetremove)r}paramspZ all_paramsZ new_paramsrhrZrZr[_remove_dups_flattens "   rcs4ttjtfdd}|S)Ncs,z ||WStk r YnX||SrrrTargskwdscachedfuncrZr[inners  z_tp_cache..inner) functools lru_cache _cleanupsrl cache_clearwraps)rrrZrr[ _tp_caches   rcsbt|tr|St|tr^tfdd|jD}||jkrH|S||}|j|_|S|S)Nc3s|]}t|VqdSrr) _eval_typergryglobalnslocalnsrZr[ sz_eval_type..)rPr _evaluaterRrprtrwrm)rhrrZev_argsresrZrr[r s     rc@seZdZdZddZdS)_Final) __weakref__cOsd|krtddS)N_rootz&Cannot subclass special typing classesrselfrrrZrZr[__init_subclass__sz_Final.__init_subclass__N)rbr^r_ __slots__rrZrZrZr[rsrc@seZdZddZddZdS) _ImmutablecCs|SrrrZrrZrZr[__copy__%sz_Immutable.__copy__cCs|SrrrZ)rZmemorZrZr[ __deepcopy__(sz_Immutable.__deepcopy__N)rbr^r_rrrZrZrZr[r"srcsleZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ e ddZZS)rU_nameZ_doccsBt|dkr6t|dtr6t|dtr6td|t|S)NrrzCannot subclass )r{rPrQrprTsuper__new__)r|rr __class__rZr[r3s   z_SpecialForm.__new__cCs||_||_dSrrr)rnamedocrZrZr[__init__@sz_SpecialForm.__init__cCst|tstS|j|jkSrr)rPrUNotImplementedrrotherrZrZr[__eq__Ds z_SpecialForm.__eq__cCs t|jfSrr)hashrrrZrZr[__hash__Isz_SpecialForm.__hash__cCs d|jS)Ntyping.rrrZrZr[__repr__Lsz_SpecialForm.__repr__cCs|jSrrrrrZrZr[ __reduce__Osz_SpecialForm.__reduce__cOstd|dS)NzCannot instantiate rrrZrZr[__call__Rsz_SpecialForm.__call__cCst|ddS)Nz! cannot be used with isinstance()rrrdrZrZr[__instancecheck__Usz_SpecialForm.__instancecheck__cCst|ddS)Nz! cannot be used with issubclass()rrr|rZrZr[__subclasscheck__Xsz_SpecialForm.__subclasscheck__cs|jdkr(t||jd}t||fS|jdkr|dkrBtdt|tsR|f}dtfdd|D}t|}t|d kr|d St||S|jd krt|d }t|t dfS|jd krt||St|ddS)N)r r z accepts only single type.rrZz Cannot take a Union of no types.z)Union[arg, ...]: each arg must be a type.c3s|]}t|VqdSrrr\rgrrXrZr[rfsz+_SpecialForm.__getitem__..rrrz#Optional[t] requires a single type.r z is not subscriptable) rr\rRrTrPrprr{rrO)rr}itemrWrZrr[ __getitem__[s(          z_SpecialForm.__getitem__)rbr^r_rrrrrrrrrrrr __classcell__rZrZrr[rU,s rU)ra`Special type indicating an unconstrained type. - Any is compatible with every type. - Any assumed to have all methods. - All values assumed to be instances of Any. Note that all the above statements are true from the point of view of static type checkers. At runtime, Any should not be used with instance or class checks. )raSpecial type indicating functions that never return. Example:: from typing import NoReturn def stop() -> NoReturn: raise Exception('no way') This type is invalid in other positions, e.g., ``List[NoReturn]`` will fail in static type checkers. 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(). aSpecial typing construct to indicate final names to type checkers. A final name cannot be re-assigned or overridden in a subclass. For example: MAX_SIZE: Final = 9000 MAX_SIZE += 1 # Error reported by type checker class Connection: TIMEOUT: Final[int] = 10 class FastConnector(Connection): TIMEOUT = 1 # Error reported by type checker There is no runtime checking of these properties. 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] - You cannot subclass or instantiate a union. - You can use Optional[X] as a shorthand for Union[X, None]. zEOptional type. Optional[X] is equivalent to Union[X, None]. aSpecial typing form to define literal types (a.k.a. value types). This form can be used to indicate to type checkers that the corresponding variable or function parameter has a value equivalent to the provided literal (or one of several literals): def validate_simple(data: Any) -> Literal[True]: # always returns True ... MODE = Literal['r', 'rb', 'w', 'wb'] def open_helper(file: str, mode: MODE) -> str: ... open_helper('/some/path', 'r') # Passes type check open_helper('/other/path', 'typo') # Error in type checker Literal[...] cannot be subclassed. At runtime, an arbitrary value is allowed as type argument to Literal[...], but type checkers may impose restrictions. c@s:eZdZdZdddZddZddZd d Zd d Zd S)r )__forward_arg____forward_code____forward_evaluated____forward_value____forward_is_argument__TcCsnt|tstd|zt|dd}Wn"tk rJtd|YnX||_||_d|_d|_||_ dS)Nz*Forward reference must be a string -- got zevalz/Forward reference must be an expression -- got F) rPrQrTcompile SyntaxErrorrrrrr)rrWrYcoderZrZr[rs zForwardRef.__init__cCsj|jr||k rd|dkr(|dkr(i}}n|dkr6|}n |dkrB|}tt|j||d|jd|_d|_|jS)Nz*Forward references must evaluate to types.rYT)rr\rrrr)rrrrZrZr[rs  zForwardRef._evaluatecCs>t|tstS|jr2|jr2|j|jko0|j|jkS|j|jkSrr)rPr rrrrrrZrZr[r s    zForwardRef.__eq__cCs t|jSrr)rrrrZrZr[rszForwardRef.__hash__cCsd|jdS)Nz ForwardRef())rrrZrZr[rszForwardRef.__repr__N)T) rbr^r_rrrrrrrZrZrZr[r s  c@s2eZdZdZddddddZddZd d ZdS) r)rb __bound____constraints__ __covariant____contravariant__NF)bound covariant contravariantc s||_|r|rtdt||_t||_|r>|dk r>td|rVt|dkrVtddtfdd|D|_|rt |d|_ nd|_ zt dj d d }Wnttfk rd}YnX|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|VqdSrrrrfrrZr[rVsz#TypeVar.__init__..zBound must be a type.rb__main__typing)rb ValueErrorboolrrrTr{rprr\rsys _getframe f_globalsgetAttributeErrorr^)rrrrrZ constraintsZdef_modrZrr[rJs(    zTypeVar.__init__cCs&|jr d}n|jrd}nd}||jS)N+-~)rrrb)rprefixrZrZr[rbs zTypeVar.__repr__cCs|jSrr)rbrrZrZr[rkszTypeVar.__reduce__)rbr^r_rrrrrZrZrZr[rs,  ) rsrpdictr frozensetdeque defaultdictrOr;cCs|do|dS)N__) startswithendswith)attrrZrZr[ _is_dundersrcseZdZddddddZeddZd d Zd d Zd dZddZ ddZ ddZ ddZ fddZ ddZddZddZZS)rRTFN)instspecialrcCsz||_||_|r*|dkr*|j}t||}||_t|ts@|f}||_tdd|D|_ t ||_ d|_ |sv|j |_ dS)Ncss*|]"}|tkrdn|tkrdn|VqdS).rZN)_TypingEllipsis _TypingEmptyrrZrZr[rs  z)_GenericAlias.__init__..)_instrmrb_normalize_aliasrrrPrprSrtrqrorr^)roriginrrrrZ orig_namerZrZr[rs      z_GenericAlias.__init__cs^|jttfkrtd|t|ts,|f}dtfdd|D}t||t||j|S)Nz%Cannot subscript already-subscripted *Parameters to generic types must be types.c3s|]}t|VqdSrrrrrrZr[rsz,_GenericAlias.__getitem__..) rSr rrTrPrpr~rvrorrrZrr[rs  z_GenericAlias.__getitem__cCst|j||j|jdS)N)rr)rRrSrrrrZrZr[rwsz_GenericAlias.copy_withcCs|jdks&t|jdkrx|jdtkrx|jr8d|j}n t|j}|jshdddd|jDd }nd }||S|jrd Sd dd d|jddDdt|jdd S)Nrrr[, cSsg|] }t|qSrZrerrZrZr[rksz*_GenericAlias.__repr__..]ztyping.Callableztyping.Callable[[cSsg|] }t|qSrZrrrZrZr[rksz], )rr{rtEllipsisrerSrmjoin)rrrrZrZr[rs       z_GenericAlias.__repr__cCsRt|tstS|j|jkrdS|jtkrF|jtkrFt|jt|jkS|j|jkS)NF)rPrRrrSrrrtrrZrZr[rs  z_GenericAlias.__eq__cCs,|jtkrttt|jfSt|j|jfSrr)rSrrrrtrrZrZr[rs z_GenericAlias.__hash__cOsT|js$td|jd|jd|j||}z ||_Wntk rNYnX|S)NType z cannot be instantiated; use z () instead)rrTrlowerrS__orig_class__r)rrkwargsresultrZrZr[rs  z_GenericAlias.__call__cCs|jrZg}|j|kr ||j||}tdd||ddDsR|tt|S|jtkrt|krpdS||}||ddD]}t|t r||k rdSq|jfS)Ncss"|]}t|tpt|tVqdSrr)rPrR issubclassr rgbrZrZr[rsz0_GenericAlias.__mro_entries__..rrZ) rrSrlindexanyr rprrPrR)rbasesrrzrrZrZr[__mro_entries__s$      z_GenericAlias.__mro_entries__cCs*d|jkrt|st|j|St|dS)NrS)__dict__rgetattrrSr)rrrZrZr[ __getattr__s z_GenericAlias.__getattr__cs2t|s|dkr t||nt|j||dS)N)rrrm)rr __setattr__setattrrS)rrvalrrZr[rsz_GenericAlias.__setattr__cCs|t|Srr)rrOrrZrZr[rsz_GenericAlias.__instancecheck__cCs<|jr0t|tst||jS|jr0t|j|jStddS)NzBSubscripted generics cannot be used with class and instance checks)rmrPrRrrSrTrrZrZr[rs   z_GenericAlias.__subclasscheck__cCs|jr |jS|jr t|j}n|j}|tkrht|jdkrJ|jdtksht|jdd|jdf}n*t |j}t|dkrt |dt s|\}t j ||ffS)Nrrrr) rmrglobalsrSrr{rtrrsrprPoperatorgetitem)rrrrZrZr[r s   z_GenericAlias.__reduce__)rbr^r_rrrrwrrrrr r rrrrrrZrZrr[rRs      rRcs(eZdZddZefddZZS)_VariadicGenericAliascCs|jdks|js||St|tr0t|dkr8td|\}}|tkrRt|f}n$t|tsjtd|t||f}||S)Nrrz6Callable must be used as Callable[[arg, ...], result].z1Callable[args, result]: args must be a list. Got ) rrm__getitem_inner__rPrpr{rTrrs)rrrrrZrZr[r"s    z!_VariadicGenericAlias.__getitem__cs |jtkr|jr|dkr$|tfSt|ts4|f}t|dkrl|ddkrldt|d}||tfSdtfdd |D}||S|jt j j kr|jr|\}}d t|}|t kr|t|fSd tfd d |D}||f}||St |S) NrZrr.z Tuple[t, ...]: t must be a type.rz*Tuple[t0, t1, ...]: each t must be a type.c3s|]}t|VqdSrrrrrrZr[r>sz:_VariadicGenericAlias.__getitem_inner__..z.Callable[args, result]: result must be a type.z6Callable[[arg, ...], result]: each arg must be a type.c3s|]}t|VqdSrrr)rgrWrrZr[rGs)rSrprmrwrrPr{r\r collectionsabcrrrr)rrrrrrrr[r2s.      z'_VariadicGenericAlias.__getitem_inner__)rbr^r_rrrrrZrZrr[rsrcs<eZdZdZdZfddZeddZfddZZ S) r rZFcs^|ttfkrtd|jdtjtjkrF|jtjk rFt|}ntj|f||}|S)Nrz< cannot be instantiated; it can be used only as a base class)r rrTrbrrobjectr)r|rrrdrrZr[rds  zGeneric.__new__cst|ts|f}|s.|tk r.td|jddtfdd|D}|ttfkrtdd|Dsxtd|jdt t |t |krtd|jd n t ||t ||S) NzParameter list to z[...] cannot be emptyrc3s|]}t|VqdSrrrrrrZr[rvsz,Generic.__class_getitem__..css|]}t|tVqdSrr)rPrrrZrZr[ryszParameters to z [...] must all be type variablesz[...] must all be unique) rPrprrTr_r rallrbr{rr~rR)r|rrZrr[__class_getitem__ns&       zGeneric.__class_getitem__c s tj||g}d|jkr(t|jk}nt|jko:|jdk}|rHtdd|jkrt|j}d}|jD].}t |t rf|j tkrf|dk rtd|j }qf|dk rt |}t ||ksdfdd|D}ddd|D} td |d | d |}t||_ dS) N__orig_bases__rz!Cannot inherit from plain Genericz0Cannot inherit from Generic[...] multiple types.rc3s|]}|krt|VqdSrrrQrfZgvarsetrZr[rsz,Generic.__init_subclass__..css|]}t|VqdSrrr)rggrZrZr[rszSome type variables (z) are not listed in Generic[r)rrr r r __bases__rbrTrqrPrRrSrorrrp) r|rrrjerrorZgvarsbaseZtvarsetZs_varsZs_argsrrr[rs8      zGeneric.__init_subclass__) rbr^r_r _is_protocolrrrrrrZrZrr[r Ms   c@s eZdZdS)rNrbr^r_rZrZrZr[rsrc@s eZdZdS)rNr#rZrZrZr[rsrrorrr"_is_runtime_protocol__abstractmethods____annotations__r __doc__rr^rr__subclasshook__r_MutableMapping__markercCsrt}|jddD]X}|jdkr$qt|di}t|jt|D] }|dsJ|tkrJ| |qJq|S)Nr)rr r&Z_abc_) r__mro__rbr rsr keysrEXCLUDED_ATTRIBUTESadd)r|attrsr! annotationsrrZrZr[_get_protocol_attrss  r0cstfddtDS)Nc3s|]}tt|dVqdSrr)rVr rgrr|rZr[rsz,_is_callable_members_only..)rr0r2rZr2r[_is_callable_members_onlysr3cOst|jrtddS)Nz Protocols cannot be instantiated)rOr"rT)rrrrZrZr[_no_inits r4c Cs6ztdjddkWSttfk r0YdSXdS)Nrrb)rrT)rrrrrrZrZrZr[_allow_reckless_class_chekssr5AbstractContextManagerAbstractAsyncContextManager)zcollections.abc contextlibcseZdZfddZZS) _ProtocolMetacsVtddrtr$tjr$dSjrJtfddtDrJdStS)Nr"FTc3s8|]0}t|o.tt|d p.t|dk VqdSrr)hasattrrVr r1r|instancerZr[rs z2_ProtocolMeta.__instancecheck__..) r r3rrr"rr0rrr;rr;r[rs  z_ProtocolMeta.__instancecheck__)rbr^r_rrrZrZrr[r9sr9cs(eZdZdZdZdZfddZZS)rrZTFcstj||jdds2tddjD_fdd}djkrN|_jsXdSjD]F}|tt fks^|j t kr|j t |j ks^t |t r|js^td|q^t_dS) Nr"Fcss|]}|tkVqdSrr)rrrZrZr[r)sz-Protocol.__init_subclass__..csjddstStdds0tr(tStdtsJtrBtStdt|ts\tdt D]v}|j D]b}||jkr|j|dkrtSqdt|di}t|t j j rn||krnt|trn|jrnqdqntSqddS) Nr"Fr$zLInstance and class checks can only be used with @runtime_checkable protocolsz._proto_hookr(z7Protocols can only inherit from other protocols, got %r)rrr rrrr"r(rr r^_PROTO_WHITELISTrbrrTr4r)r|rrr=r!rr2r[r$s, &   zProtocol.__init_subclass__)rbr^r_rr"r$rrrZrZrr[rs) metaclasscCs&t|tr|jstd|d|_|S)NzB@runtime_checkable can be only applied to protocol classes, got %rT)rr r"rTr$r2rZrZr[rKds cCs|SrrrZ)typrrZrZr[rA}sc Csz |j}Wntk r"iYSX|j}|j}|d|}|jpDd}|j}|rXt|ni}|t|}t||d|D]\}} | ||<qz|S)NrZ) __code__r co_argcount co_varnames __defaults____kwdefaults__rr{zip) rrZ pos_countZ arg_namesdefaultsZ kwdefaultsrZ pos_offsetrvaluerZrZr[ _get_defaultss      rIc Cst|ddriSt|tri}t|jD]z}|dkrDtj|jj}n|}|j di}| D]B\}}|dkrvtd}t|t rt |dd}t |||}|||<q^q(|S|dkrt|tjr|j}n"|} t| dr| j} qt| di}|dkr|}n|dkr|}t|dd}|dkr6t|tr(iStd|t|} t|}| D]d\}}|dkrhtd}t|t r|t |}t |||}|| kr| |dkrt|}|||<qN|S)N__no_type_check__r&Fr __wrapped__ __globals__z1{!r} is not a module, class, method, or function.)r rPrOreversedr*rmodulesr^r ritemsrQr rr` ModuleTyper:rK_allowed_typesrTformatrIrr) rdrrZhintsr!Z base_globalsannrrHZnsobjrGrZrZr[rEs^                 cCs t|tr|jS|tkrtSdSrr)rPrRrSr )rxrZrZr[rDs  cCsRt|trN|jsN|j}t|tjjkrJ|dtk rJt |dd|df}|SdS)NrrrZ) rPrRrmrtrDrrrrrs)rxrrZrZr[rC s cCst|trt|j}|jD]"\}}||j|fkr||q|D](}t|tj r`d|_ t|trJt |qJz d|_ Wnt k rYnX|S)NT) rPrOr copyrOrpopvaluesr`rarJrGrT)rWZ arg_attrsrrrdrZrZr[rGs        cstfdd}|S)Ncs||}t|}|Srr)rG)rrr decoratorrZr[wrapped_decorator@s z2no_type_check_decorator..wrapped_decorator)rr)rXrYrZrWr[rH9scOs 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_dummyIsr[cCstSrr)r[)rrZrZr[rJRscCs|SrrrZ)frZrZr[rBosTKTVTT_co)rV_coVT_coT_contra)rCT_co)rrcCst||d|dS)NT)rr)rR)rrrrZrZr[_aliassrerZ)raCallable 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. F)rra@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, ...]. )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)r2rZreturncCsdSrrrZrrZrZr[__int__szSupportsInt.__int__N)rbr^r_rrintrhrZrZrZr[r2sc@s"eZdZdZeedddZdS)r0rZrfcCsdSrrrZrrZrZr[ __float__szSupportsFloat.__float__N)rbr^r_rrfloatrjrZrZrZr[r0sc@s"eZdZdZeedddZdS)r/rZrfcCsdSrrrZrrZrZr[ __complex__ szSupportsComplex.__complex__N)rbr^r_rrcomplexrlrZrZrZr[r/sc@s"eZdZdZeedddZdS)r.rZrfcCsdSrrrZrrZrZr[ __bytes__szSupportsBytes.__bytes__N)rbr^r_rrbytesrnrZrZrZr[r.sc@s"eZdZdZeedddZdS)r1rZrfcCsdSrrrZrrZrZr[ __index__szSupportsIndex.__index__N)rbr^r_rrrirprZrZrZr[r1sc@s"eZdZdZeedddZdS)r-rZrfcCsdSrrrZrrZrZr[__abs__(szSupportsAbs.__abs__N)rbr^r_rrr`rqrZrZrZr[r-#sc@s&eZdZdZedeedddZdS)r3rZr)ndigitsrgcCsdSrrrZ)rrrrZrZr[ __round__2szSupportsRound.__round__N)r)rbr^r_rrrir`rsrZrZrZr[r3-sc stdfdd|D}t|dd|D}t||_|_ztdjdd|_ Wnt t fk rnYnX|S)NzDNamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a typecsg|]\}}|t|fqSrZrrgnrhrrZr[rk9sz!_make_nmtuple..cSsg|] \}}|qSrZrZrtrZrZr[rk:srrbr) r namedtuplerr& _field_typesrrrrr^rr)rr`nm_tplrZrr[ _make_nmtuple7sry) rrr__getnewargs___fields_field_defaultsrw_make_replace_asdictZ_source)r^rbr&cseZdZfddZZS)NamedTupleMetac s|ddrt||||S|di}t||}g}i}|D]H}||krl||} || | ||<qD|rDtdj|d| dqDt ||j_ t ||j_ ||_|D]<} | tkrtd| q| tkr| |jkrt|| || q|S)NrFr&zXNon-default namedtuple field {field_name} cannot follow default field(s) {default_names}r) field_nameZ default_namesz&Cannot overwrite NamedTuple attribute )rrrryrOrlrTrRrr+rr&rprDr| _prohibitedrrmr{r) r|typenamer nsr`rxrGZ defaults_dictrZ default_valuekeyrrZr[rOs2       zNamedTupleMeta.__new__)rbr^r_rrrZrZrr[rMsrc@seZdZdZddZde_dS)r=TcOs|s td|^}}|r"|^}}n4d|krN|d}ddl}|jdtddntd|rz |\}Wqtk rtdt|dd dYqXnrr&z?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typecsi|]\}}|t|qSrZr)rgrurxrrZr[ sz*_TypedDictMeta.__new__..r) rrrrrrrrOupdater r&r:r)r|rr rrZtp_dictZannsr!rrr[rs   z_TypedDictMeta.__new__)T)rbr^r_rrrrrrZrZrr[rsrc@s eZdZdS)r>Nr#rZrZrZr[r>scCsdd}||_||_|S)NcSs|SrrrZ)xrZrZr[new_typeszNewType..new_type)rbZ __supertype__)rrxrrZrZr[rF sc@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);IOrZrfcCsdSrrrZrrZrZr[mode=szIO.modecCsdSrrrZrrZrZr[rBszIO.nameNcCsdSrrrZrrZrZr[closeGszIO.closecCsdSrrrZrrZrZr[closedKsz IO.closedcCsdSrrrZrrZrZr[filenoPsz IO.filenocCsdSrrrZrrZrZr[flushTszIO.flushcCsdSrrrZrrZrZr[isattyXsz IO.isattyr)rurgcCsdSrrrZ)rrurZrZr[read\szIO.readcCsdSrrrZrrZrZr[readable`sz IO.readable)limitrgcCsdSrrrZ)rrrZrZr[readlinedsz IO.readline)hintrgcCsdSrrrZ)rrrZrZr[ readlineshsz IO.readlinesr)offsetwhencergcCsdSrrrZ)rrrrZrZr[seeklszIO.seekcCsdSrrrZrrZrZr[seekablepsz IO.seekablecCsdSrrrZrrZrZr[telltszIO.tell)sizergcCsdSrrrZ)rrrZrZr[truncatexsz IO.truncatecCsdSrrrZrrZrZr[writable|sz IO.writablesrgcCsdSrrrZrrrZrZr[writeszIO.write)linesrgcCsdSrrrZ)rrrZrZr[ writelinessz IO.writelinesz IO[AnyStr]cCsdSrrrZrrZrZr[ __enter__sz IO.__enter__cCsdSrrrZ)rrOrH tracebackrZrZr[__exit__sz IO.__exit__)r)r)r)r)N)rbr^r_rpropertyrrQrrrrrrirrrr@rrrr9rrrrrrrrrrrZrZrZr[r.sX rc@s>eZdZdZeeeefedddZ eddddZ dS) BinaryIOrZrcCsdSrrrZrrZrZr[rszBinaryIO.writerfcCsdSrrrZrrZrZr[rszBinaryIO.__enter__N) rbr^r_rrrro bytearrayrirrrZrZrZr[rs rc@seZdZdZeeedddZeeedddZ eee edddZ eee dd d Z eeedd d Zeddd dZdS)TextIOrZrfcCsdSrrrZrrZrZr[buffersz TextIO.buffercCsdSrrrZrrZrZr[encodingszTextIO.encodingcCsdSrrrZrrZrZr[errorssz TextIO.errorscCsdSrrrZrrZrZr[line_bufferingszTextIO.line_bufferingcCsdSrrrZrrZrZr[newlinesszTextIO.newlinescCsdSrrrZrrZrZr[rszTextIO.__enter__N)rbr^r_rrrrrrQrrrrrrrrrZrZrZr[rs$rc@s"eZdZdddgZeZeZeZdS)iorrrN)rbr^r___all__rrrrZrZrZr[rs rz.ioc@seZdZddgZeZeZdS)rePatternMatchN)rbr^r_rrrrZrZrZr[rsrz.re)T)NN)T)N)rrrrZcollections.abcr8rrrZ stdlib_rerr`rrrrr\rerqrvr~rrrrrrrUrrIr r rrr r rrrrRrr rrZ_TYPING_INTERNALSZ_SPECIAL_NAMESr,r0r3r4r5r>r9rrKrArIraBuiltinFunctionType MethodTyperPrQrErDrCrGrHr[rJrBr]r^r_r`rarbrcrOrdrorQr@rerr%r(r'r&rrr,r#rr)rr'r;rr!rrr"r rrprrsr9rr6rrr<rrrr$r6rr7r+rr7rr8r:r5r4r?r*rr2r0r/r.r1r-r3ryrrmrr=rrrrr>rFrLrMrrrrrbrNrrrZrZrZr[s&X !   I  2a /[ b  V                    @+c#