o 7]hmT@sn ddlZddlZddlZddlZddlZddlZejdddkZer&eZ nddlm Z m Z ddZ ddZ gd Z erCe gd eed rLejZnGd d d ejddZeddZedZedZedZejdddZejdddZejZeedrejdddkrejZn+ejdddkrGdddejddZedddZnGdddejddZeddZeed rejZnd!d Zd"d#Zeed$rej Z n+ejdddkrGd%d&d&ejddZ!e!d$d'dZ nGd(d)d)ejddZ"e"ddZ ej#Z#ej$Z$ej%Z%Gd*d+d+e Z&ej'Z'ej(Z(ej)Z)ej*Z*eed,r%ej+Z+nGd-d,d,ej,ej-ee&ej,d.Z+ej.Z.eed/rCej/Z/ndd0l0m1Z2Gd1d/d/ej3eZ/ej4Z4eed2raej5Z5n0dejddkrrd3kr~nn e6ej5eefZ5nGd4d2d2ej5ej7eefe&ej5d.Z5eed5rej8Z8nGd6d5d5ej8ej9ee:fe&ej8d.Z8eed7rej;Z;need7rGd8d7d7ej;ej7eefe&ej;d.Z;eed9rejZ>ej?Z?d;d<Z@gd=ZAd>d?ZBd@dAZCeedBrejDZDn=er3ddClmEZEdDdEZFGdFdGdGejGZHGdHdBdBeHdIZDnddJlmIZImJZJdKdEZFGdLdGdGe ZHGdMdBdBeHdIZDeedNrZejKZKndOdNZKeKZLeedPrjejMZMn eKGdQdPdPeDZMejdRkr~ejNZNn*dSdTZOdUdVZPdWeP_QddXdYdZZRd[eR_QGd\d]d]eZSeSd^eTfiZNeUeN_Vd_eN_Weed`rejXZXejYZYejZZZn5erGdadbdbej[ddZZGdcd`d`ZXdddeZ\ddgdhZYndidjZ]Gdkdldlej Z^Gdmd`d`e^dIZXejdddnkrej_Z_ej`Z`n7er5zddolmaZaWn ebyej[ZaYnwzddplmcZcWn eby,ej[ZcYnwdqdrZ_dsdtZ`eedur?ejdZdnRejdddvkr[GdwdxdxejddZeeedyduZdn6ejdddkrwGdzdxdxejddZeeedud{dZdnGd|d}d}ejfZgGd~ddejegddZhehddZdeedrejiZiejjZjnGdddZkGdddekZiGdddekZjeedrejlZlnGdddemZleedsGdddemZnejoddZpeedrejqZqejnZnnGejdddvkreeddZqn6ejdddkrGdddejddZrerdddZqnGdddejfZsGdddejesddZtetddZqeedr:ejuZunHejdddvkrVGdddejddZvevddZun,ejdddkrrGdddejddZvevdddZunGdddejddZwewddZueedrejxZxn,ejdddkrGdddejddZeddZxnGdddejddZyeyddZxeedrejzZzej{Z{dSejdddvkrGdddejddZ|e|ddZze|ddZ{dSejdddkr GdddejddZ}e}dddZze}dddZ{dSGdddejddZ~Gddde~ddZGddde~ddZeddZzeddZ{dS)N)rr) GenericMeta _type_varscCs.t|}d|vr|dD]}||dq |S)N __slots__)dictpop)dct dict_copyslotr ?/usr/lib/python3/dist-packages/pip/_vendor/typing_extensions.py_no_slots_copys  rc Cs^|js t|dt|}t|j}||kr-td||krdndd|d|d|dS)Nz is not a generic classzToo manyfewz arguments for z ; actual z , expected )__parameters__ TypeErrorlen)cls parametersalenelenr r r _check_generics r)!ClassVar ConcatenateFinal ParamSpecSelfType Awaitable AsyncIterator AsyncIterable CoroutineAsyncGeneratorAsyncContextManagerChainMapContextManagerCounterDeque DefaultDict OrderedDict TypedDict SupportsIndex AnnotatedfinalIntVarLiteralNewTypeoverloadProtocolruntimeruntime_checkableText TypeAlias TypeGuard TYPE_CHECKING)get_args get_originget_type_hintsNoReturnc@$eZdZdZdZddZddZdS) _NoReturna7Special 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. r cCtd)Nz*NoReturn cannot be used with isinstance().rselfobjr r r __instancecheck__mz_NoReturn.__instancecheck__cCr@)Nz*NoReturn cannot be used with issubclass().rArCrr r r __subclasscheck__prFz_NoReturn.__subclasscheck__N__name__ __module__ __qualname____doc__rrErHr r r r r?_s   r?T_rootTKTVTT_co) covariantT_contra) contravariantr)rrc@eZdZddZddZdS) _FinalFormcC d|jSNztyping_extensions._namerCr r r __repr__ z_FinalForm.__repr__cC"t||jd}t||fS)N accepts only single typetyping _type_checkr] _GenericAliasrCritemr r r __getitem__ z_FinalForm.__getitem__NrJrKrLr_rir r r r rY rYaWA special typing construct to indicate that a 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.)doccNeZdZdZdZdddZddZdd Zfd d Zd d Z ddZ Z S)_FinalaA special typing construct to indicate that a 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. __type__NcK ||_dSNrprCtpkwdsr r r __init__r`z_Final.__init__cCNt|}|jdur|t||jdddddSt|jddd)N accepts only single type.TrN cannot be further subscriptedtyperqrdrerJrrCrhrr r r ri z_Final.__getitem__cC.t|j||}||jkr|St||ddSNTrNrd _eval_typerqr}rCglobalnslocalnsnew_tpr r r r z_Final._eval_typec0t}|jdur|dt|jd7}|SN[]superr_rqrd _type_reprrCr __class__r r r_  z_Final.__repr__cCtt|j|jfSrshashr}rJrqr^r r r __hash__z_Final.__hash__cC,t|tstS|jdur|j|jkS||uSrs) isinstanceroNotImplementedrqrCotherr r r __eq__   z _Final.__eq__rs rJrKrLrMrrwrirr_rr __classcell__r r rr ros  ror.cC|S)auThis decorator can be used to indicate to type checkers that the decorated method cannot be overridden, and decorated class cannot be subclassed. For example: class Base: @final def done(self) -> None: ... class Sub(Base): def done(self) -> None: # Error reported by type checker ... @final class Leaf: ... class Other(Leaf): # Error reported by type checker ... There is no runtime checking of these properties. r )fr r r r.scC t|Srs)rdTypeVarnamer r r r/r`r/r0c@rX) _LiteralFormcCrZr[r\r^r r r r_r`z_LiteralForm.__repr__cCs t||Srs)rdrfrCrr r r ri z_LiteralForm.__getitem__Nrkr r r r rrlraoA type that can be used to indicate to type checkers that the corresponding value has a value literally equivalent to the provided parameter. For example: var: Literal[4] = 4 The type checker understands that 'var' is literally equal to the value 4 and no other value. Literal[...] cannot be subclassed. There is no runtime checking verifying that the parameter is actually a value instead of a type.crn)_LiteralaA type that can be used to indicate to type checkers that the corresponding value has a value literally equivalent to the provided parameter. For example: var: Literal[4] = 4 The type checker understands that 'var' is literally equal to the value 4 and no other value. Literal[...] cannot be subclassed. There is no runtime checking verifying that the parameter is actually a value instead of a type.  __values__NcKrrrsr)rCvaluesrvr r r rw!r`z_Literal.__init__cCsFt|}|jdurt|ts|f}||ddSt|jddd)NTrNryr{)r}rrtuplerrJ)rCrrr r r ri$s    z_Literal.__getitem__cCrrsr )rCrrr r r r,z_Literal._eval_typecs8t}|jdur|ddttj|jd7}|S)Nr, r)rr_rjoinmaprdrrrr r r_/s   z_Literal.__repr__cCrrs)rr}rJrr^r r r r5rz_Literal.__hash__cCrrs)rrrrrr r r r8rz_Literal.__eq__rsrr r rr rs  rceZdZfddZZS)_ExtensionsGenericMetacs|jdurtdjddvrtddS|jst|S|j|}|t ur*|S|j|j vr2dS|j D]}t |t r?q7t||rGdSq7dS)a*This mimics a more modern GenericMeta.__subclasscheck__() logic (that does not have problems with recursion) to work around interactions between collections, typing, and typing_extensions on older versions of Python, see https://github.com/python/typing/issues/501. NryrJabc functoolsCParameterized generics cannot be used with class or instance checksFT) __origin__sys _getframe f_globalsr __extra__rrH__subclasshook__r__mro____subclasses__rr issubclass)rCsubclassressclsrr r rHNs$      z(_ExtensionsGenericMeta.__subclasscheck__)rJrKrLrHrr r rr rMsrr(c@eZdZdZddZdS)r(r cOs6|jtur tj|i|Stjtj|g|Ri|Srs)_gorgr( collectionsdequerd _generic_newrargsrvr r r __new__w z Deque.__new__NrJrKrLrrr r r r r(rs ) metaclassextrar$)_check_methodsc@s2eZdZdZddZejddZeddZ dS) r$r cs|Srsr r^r r r __aenter__szAsyncContextManager.__aenter__csdSrsr )rCexc_type exc_value tracebackr r r __aexit__szAsyncContextManager.__aexit__cCs|tur t|ddStS)Nrr)r$_check_methods_in_mror)rCr r r rs z$AsyncContextManager.__subclasshook__N) rJrKrLrrrabstractmethodr classmethodrr r r r r$s r*)rrrWc@r)r*r cO6|jtur tj|i|Stjtj|g|Ri|Srs)rr*rrdrrr r r rrzOrderedDict.__new__Nrr r r r r* r'c@r)r'r cOrrs)rr'rrdrrr r r rrzCounter.__new__Nrr r r r r'rr%c@r)r%r cOrrs)rr%rrdrrr r r rrzChainMap.__new__Nrr r r r r%rr#c@eZdZdZdS)r#r N)rJrKrLrr r r r r#scCs<t|tsJt|dr|jS|jdur|j}|jdus|S)z@This function exists for compatibility with old typing versions.rN)rrhasattrrrrr r r rs   r) CallablerIterableIteratorr!r HashableSized Container Collection Reversibler&r$cCsrt}|jddD],}|jdvrq t|di}t|jt|D]}|ds5|dvr5||q%q |S)N)r3Generic__annotations___abc_)__abstractmethods__r __weakref__ _is_protocol_is_runtime_protocol__dict____args__r__next_in_mro__rr__orig_bases__r __tree_hash__rMrrwrrK_MutableMapping__markerr) setrrJgetattrlistrkeys startswithadd)rattrsbase annotationsattrr r r _get_protocol_attrss    rcstfddtDS)Nc3s |] }tt|dVqdSrs)callabler.0rrr r z,_is_callable_members_only..)allrrr rr _is_callable_members_onlysr r3)_collect_type_varscOt|jr tddSNz Protocols cannot be instantiatedr}rrrCrkwargsr r r _no_init rcr) _ProtocolMetacsVtddr trtjrdSjr%tfddtDr%dStS)NrFTc3s:|]}t|ott|d pt|duVqdSrsrrrrrinstancer r r   2_ProtocolMeta.__instancecheck__..) rr rrrrrrrErrrr rE s   _ProtocolMeta.__instancecheck__)rJrKrLrErr r rr r srcs>eZdZdZdZdZfddZejddZ dd Z Z S) r3aBase class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing_extensions.runtime act as simple-minded runtime protocol that checks only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... r Tcs|turtdt|S)NzIType Protocol cannot be instantiated; it can only be used as a base class)r3rrrrrr r r>s Protocol.__new__cst|ts|f}|s|tjurtd|jddtfdd|D}|turetdd|DsVd}t||tjrH|d7}t||tjs.cs|] }t|tjVqdSrsrrdrrr r r rOr#rryzBParameters to Protocol[...] must all be type variables. Parameter z is z.Parameters to Protocol[...] must all be unique) rrrdTuplerrLr3rrrrrrf)rparamsir r!r __class_getitem__Ds8    zProtocol.__class_getitem__c sg}djvrtjjv}ntjjv}|rtddjvrtj}d}jD]}t|tjrH|j tjt fvrH|j j }|durEtd|j }q)|durP|}n2t |}t ||ksdfdd|D} ddd|D} td| d |d | d |}t|_ jd dstd djD_fdd} djvr| _jsdSjD]$}|ttjfvs|jdkr|j tvst|tr|jstdt|qt_dS)Nr!Cannot inherit from plain GenericzECannot inherit from Generic[...] and/or Protocol[...] multiple types.rc3 |] }|vrt|VqdSrsstrrtgvarsetr r r~rz-Protocol.__init_subclass__..cs|]}t|VqdSrsr,rgr r r rSome type variables () are not listed in rrrcss|]}|tuVqdSrs)r3rbr r r rr5csjdds tStddstdjddvrtStdts3tdjddvr/tStdt |t s._proto_hookrcollections.abc5Protocols can only inherit from other protocols, got )rrdrr __bases__rr rrfrr3rJrrrrr=anyrrobjectrK_PROTO_WHITELISTrreprrrw) rrrtvarserrorgvarsrthe_basetvarsets_varss_argsr@r )rr1r __init_subclass__^sj               zProtocol.__init_subclass__) rJrKrLrMrrrrd _tp_cacher)rOrr r rr r3s  )r) _next_in_mrorecOr r r rr r r rrcsVeZdZdZ d fdd ZfddZfddZfd d Zej d d Z Z S)rzInternal metaclass for Protocol. This exists so Protocol classes can be generic without deriving from Generic. Nc sT|dusJ|dur|dusJtdd|DsJ|nrt|}d} |D]#} | tjur1tdt| trI| jtjtfvrI| durFtd| j } q&| durQ|} n?t |} t | | ksd fdd|D} d dd| D} t dd|Dr~d nd }td | d |d | d| }|}|durt |tjur||vr|f|}tdd|D}t dd|Drtdd|D}|||dtt|j||||dd}tt|d|s|nt|||_ |rtdd|Dnd|_t||_|dur||_n |dur|j|_|j|_t|dr(|r t|ntt||_ |S)Ncsr$rsr%r.r r r rr#z(_ProtocolMeta.__new__..r*zACannot inherit from Generic[...] or Protocol[...] multiple times.rc3r+rsr,r.r0r r rrcsr2rsr,r3r r r rr5css|] }|jtjuVqdSrs)rrdrr8r r r rsrr3r6r7rrcss&|]}t|tr t|n|VqdSrs)rrrr8r r r rscss$|] }t|to |tjuVqdSrs)rrrdrr8r r r rs"css|] }|tjur|VqdSrs)rdrr8r r r rs)rrTrNrcss0|]}|tjur dn|tjurdn|VqdS).r N)rd_TypingEllipsis _TypingEmptyrar r r rs _subs_tree)!rrrdrrrrrr3rrrrDr}rABCMetarupdaterr __setattr__rrrQrr _abc_registry _abc_cacherrrVrr)rrbases namespacerHroriginr orig_basesrJrrLrMrNcls_name initial_basesrCrr0r rs               z_ProtocolMeta.__new__cstj|i|jddstddjD_jrYjddD]0}|tt j fvsU|j dkr8|j t vsUt|t jrA|jsUt|trL|jt j usUtdt|q%t_fdd}d jvri|_dSdS) Nrcss,|]}|tupt|to|jtuVqdSrs)r3rrrr8r r r r s  z)_ProtocolMeta.__init__..ryrArBcsjdds tSt|tstdtD]:}|jD]0}||jvr1|j|dur/tSnt|di}t|t j rK||vrKt|t rK|j rKnqtSqdS)Nrr<rT) rr=rrr}rrrrrdr>rrr?rr r r@s,       z+_ProtocolMeta.__init__.._proto_hookr)rrwrr=rDrCrrrErdrrKrJrFr TypingMetarrrrGrr)rrrrr@rrr rws4        z_ProtocolMeta.__init__csZtddr trtjrdSjr%tfddtDr%dStt S)NrFTc3s:|]}t|ott|d pt|duVqdSrsrrrrCr r r;rr) rr rrrrrrrrE)rCrrrcr rE3s  rcs|jdurtdjddvrtddS|jddr3|jdds3tdjddvr/dStd |jddrTt|sTtdjddvrPtt | |Std tt | |S) NryrJrrFrrrrrdr:r;) rrrrrrr=r rrrHrGrr r rHBs"  z_ProtocolMeta.__subclasscheck__c sJt|ts|f}|st|tjurtd|jddtfdd|D}|tjtfvrZt dd|DsAtdt |dt t |t |krUtdt |d |}|}n+|tjtj fvrit|}|}n|jtjtfvrztd t |t||t|}|}|jdur|fnd }|j|j||jt|j||||j|jd S) Nrrrc3s|]}t|VqdSrs)rerr!r r rdsz,_ProtocolMeta.__getitem__..csr$rsr%rr r r rfr#zParameters to z [...] must all be type variablesz[...] must all be uniquez%Cannot subscript already-subscripted r )rHrr^rr_)rrrrdr&rrLrr3rrGrrrrrrrrJrCrrrr)rCr'rHrprependr r!r riZsJ   z_ProtocolMeta.__getitem__)NNNNN) rJrKrLrMrrwrErHrdrPrirr r rr rs @ , c@s eZdZdZdZdZddZdS)r3aBase class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing_extensions.runtime act as simple-minded runtime protocol that checks only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... r TcOs0t|tur tdtj|j|g|Ri|S)NzIType Protocol cannot be instantiated; it can be used only as a base class)rr3rrdrrrr r r rs rN)rJrKrLrMrrrr r r r r3s  r5cCs(t|tr|jstd|d|_|S)a4Mark a protocol class as a runtime protocol, so that it can be used with isinstance() and issubclass(). Raise TypeError if applied to a non-protocol class. This allows a simple-minded structural check very similar to the one-offs in collections.abc such as Hashable. z@@runtime_checkable can be only applied to protocol classes, got T)rrrrrrr r r r5s r,c@s$eZdZdZejdefddZdS)r,r returncCdSrsr r^r r r __index__szSupportsIndex.__index__N)rJrKrLrrrintrhr r r r r,s)r rWc Cs<ztdjddvrtdWdSttfyYdSw)NryrJrdz4TypedDict does not support instance and class checksF)rrrrAttributeError ValueError)rrr r r _check_failssrmcOs0|std|d|dd}}t|i|S)N)TypedDict.__new__(): not enough argumentsrry)rr)rr_r r r _dict_newsrpz,($cls, _typename, _fields=None, /, **kwargs)totalc OsN|std|d|dd}}|r|d|dd}}nd|vr5|d}ddl}|jdtddntd|rTz|\}Wn1tyStd t|dd wd |vrpt|dkrp|d }ddl}|jd tddnd}|dury|}n|rtd dt|i}zt dj dd|d<Wn t tfyYnwt |d||dS)Nrnrry _typenamez5Passing '_typename' as keyword argument is deprecatedrW) stacklevelzGTypedDict.__new__() missing 1 required positional argument: '_typename'z?TypedDict.__new__() takes from 2 to 3 positional arguments but z were given_fieldsz3Passing '_fields' as keyword argument is deprecatedz@TypedDict takes either a dict or keyword arguments, but not bothrrJ__main__rKr rq)rrwarningswarnDeprecationWarningrlrrrrrr=rk_TypedDictMeta)rrrrrotypenamerwfieldsnsr r r _typeddict_newsL       r~z;($cls, _typename, _fields=None, /, *, total=True, **kwargs)cs4eZdZdfdd Zdfdd ZeZZZS)rzTcst|||dSrs)rrw)rrr\r}rrrr r rwrz_TypedDictMeta.__init__c s|dkrtnt|d<t||tf|}i}|di}t|}dfdd|D}t} t} |D] } | | j di| | j dd| | j d dq7| ||re| |n| |||_ t | |_ t | |_t|d s||_|S) Nr+rrz?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typecsi|] \}}|t|qSr r)rnrur!r r *sz*_TypedDictMeta.__new__..__required_keys__r __optional_keys__ __total__)r~rprrrr=rritemsrXrr frozensetrrrr) rrr\r}rrtp_dictrown_annotationsown_annotation_keys required_keys optional_keysrrr!r rs2         z_TypedDictMeta.__new__)T) rJrKrLrwrrmrErHrr r rr rzs&rzr+aA simple typed name space. At runtime it is equivalent to a plain dict. TypedDict creates a dictionary type that expects all of its instances to have a certain set of keys, with each key associated with a value of a consistent type. This expectation is not checked at runtime but is only enforced by type checkers. Usage:: class Point2D(TypedDict): x: int y: int label: str a: Point2D = {'x': 1, 'y': 2, 'label': 'good'} # OK b: Point2D = {'z': 3, 'label': 'bad'} # Fails type check assert Point2D(x=1, y=2, label='first') == dict(x=1, y=2, label='first') The type info can be accessed via the Point2D.__annotations__ dict, and the Point2D.__required_keys__ and Point2D.__optional_keys__ frozensets. TypedDict supports two additional equivalent forms:: Point2D = TypedDict('Point2D', x=int, y=int, label=str) Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str}) The class syntax is only supported in Python 3.6+, while two other syntax forms work for Python 2.7 and 3.2+ r-csHeZdZdZfddZddZddZdd Zd d Zd d Z Z S)_AnnotatedAliasaKRuntime representation of an annotated type. At its core 'Annotated[t, dec1, dec2, ...]' is an alias for the type 't' with extra annotations. The alias behaves like a normal typing alias, instantiating is the same as instantiating the underlying type, binding it to types is also the same. cs2t|tr |j|}|j}t||||_dSrs)rr __metadata__rrrw)rCr^metadatarr r rwvs   z_AnnotatedAlias.__init__cCs$t|dksJ|d}t||jS)Nryr)rrr)rCr'new_typer r r copy_with}s z_AnnotatedAlias.copy_withcCs,dt|jdddd|jDdS)Nztyping_extensions.Annotated[rcsr2rsrGrTr r r rr5z+_AnnotatedAlias.__repr__..r)rdrrrrr^r r r r_sz_AnnotatedAlias.__repr__cCstjt|jf|jffSrs)operatorgetitemr-rrr^r r r __reduce__sz_AnnotatedAlias.__reduce__cCs*t|tstS|j|jkrdS|j|jkS)NF)rrrrrrr r r rs   z_AnnotatedAlias.__eq__cCt|j|jfSrs)rrrr^r r r rz_AnnotatedAlias.__hash__) rJrKrLrMrwrr_rrrrr r rr rns rc@s2eZdZdZdZddZejddZddZ d S) r-aAdd context specific metadata to a type. Example: Annotated[int, runtime_check.Unsigned] indicates to the hypothetical runtime_check module that this type is an unsigned int. Every other consumer of this type can ignore this metadata and treat this type as int. The first argument to Annotated must be a valid type (and will be in the __origin__ field), the remaining arguments are kept as a tuple in the __extra__ field. Details: - It's an error to call `Annotated` with less than two arguments. - Nested Annotated are flattened:: Annotated[Annotated[T, Ann1, Ann2], Ann3] == Annotated[T, Ann1, Ann2, Ann3] - Instantiating an annotated type is equivalent to instantiating the underlying type:: Annotated[C, Ann1](5) == C(5) - Annotated can be used as a generic type alias:: Optimized = Annotated[T, runtime.Optimize()] Optimized[int] == Annotated[int, runtime.Optimize()] OptimizedList = Annotated[List[T], runtime.Optimize()] OptimizedList[int] == Annotated[List[int], runtime.Optimize()] r cOr@)Nz&Type Annotated cannot be instantiated.rArrrr r r rrFzAnnotated.__new__cCsLt|tr t|dkrtdd}t|d|}t|dd}t||S)NrWzUAnnotated[...] should be used with at least two arguments (a type and an annotation).$Annotated[t, ...]: t must be a type.rry)rrrrrdrer)rr'r"r^rr r r r)s  zAnnotated.__class_getitem__cOstd|jd)NCannot subclass z .Annotated)rrKrr r r rOs zAnnotated.__init_subclass__N) rJrKrLrMrrrdrPr)rOr r r r r-s   cCs\t|tr t|jSt|tjr,tdd|jD}||jkr!|S||}|j |_ |S|S)z2Strips the annotations from a given type. csr2rs_strip_annotationsrTr r r rr5z%_strip_annotations..) rrrrrdrfrrr_special)r/ stripped_argsrr r r rs     rFcCs*tj|||d}|r |Sdd|DS)a]Return type hints for an object. This is often the same as obj.__annotations__, but it handles forward references encoded as string literals, adds Optional[t] if a default value equal to None is set and recursively replaces all 'Annotated[T, ...]' with 'T' (unless 'include_extras=True'). The argument may be a module, class, method, or function. The annotations are returned as a dictionary. For classes, annotations include also inherited members. TypeError is raised if the argument is not of a type that can contain annotations, and an empty dictionary is returned if no annotations are present. BEWARE -- the behavior of globalns and localns is counterintuitive (unless you are familiar with how eval() and exec() work). The search order is locals first, then globals. - If no dict arguments are passed, an attempt is made to use the globals from obj (or the respective module's globals for classes), and these are also used as the locals. If the object does not appear to have globals, an empty dictionary is used. - If one dict argument is passed, it is used for both globals and locals. - If two dict arguments are passed, they specify globals and locals, respectively. )rrcSsi|] \}}|t|qSr r)rkr/r r r rsz"get_type_hints..)rdr<r)rDrrinclude_extrashintr r r r<sr<cCs t|dko|do|dS)z3Returns True if name is a __dunder_variable_name__.__)rrendswithrr r r _is_dunders rcseZdZdZfddZeddZddZdfd d Zd d Z e j fd dZ ddZ ddZfddZddZddZZS) AnnotatedMetazMetaclass for Annotatedc s<tdd|Drtdtttj||||fi|S)Ncss|]}|tuVqdSrs)rEr8r r r r r5z(AnnotatedMeta.__new__..r)rDrr-r-rr)rrr\r]rrr r r szAnnotatedMeta.__new__cCs |dS)NrW)rVr^r r r r zAnnotatedMeta.__metadata__cCsX|\}}}t|tst|}n|d|}ddd|D}|d|d|dS)Nrrcsr2rsrrargr r r rr5z+AnnotatedMeta._tree_repr..rr)rrrdr _tree_reprr)rCtreerr^rtp_reprmetadata_reprsr r r rs   zAnnotatedMeta._tree_reprNcsh|turtStj||d}t|dtr2|ddtur2|dd}|dd}t|||dfS|S)N)rHrryrrW)r-rrVrr)rCrHrrsub_tp sub_annotrr r rVs  zAnnotatedMeta._subs_treecCsd|jdur td|}t|tr'|dtur'|d}t|tr'|dtust|tr0|dS|S)z6Return the class used to create instance of this type.NzCCannot get the underlying type of a non-specialized Annotated type.rry)rrrVrrr-)rCrr r r _get_cons's  zAnnotatedMeta._get_conscst|ts|f}|jdurt|St|trt|dkr"tdd}t|d|}t|dd}|j |j |j t |j t|f||f|dS)NrWz]Annotated[...] should be instantiated with at least two arguments (a type and an annotation).rrry)rHrr^)rrrrrirrrdrerrJrCrrr)rCr'r"rurrr r ri4s"   zAnnotatedMeta.__getitem__cOs8|}||i|}z||_W|StyY|Swrs)r__orig_class__rk)rCrrconsresultr r r __call__Ls zAnnotatedMeta.__call__cCs(|jdurt|st||St|rs)rrrrrk)rCrr r r __getattr__UszAnnotatedMeta.__getattr__csJt|s |drt||dS|jdurt|t|||dS)Nr)rrrrYrrksetattrr)rCrvaluerr r rY[s  zAnnotatedMeta.__setattr__cCr@)Nz+Annotated cannot be used with isinstance().rArBr r r rEcrFzAnnotatedMeta.__instancecheck__cCr@)Nz+Annotated cannot be used with issubclass().rArGr r r rHfrFzAnnotatedMeta.__subclasscheck__)NN)rJrKrLrMrpropertyrrrVrrdrPrirrrYrErHrr r rr rs      rc@r)r-avAdd context specific metadata to a type. Example: Annotated[int, runtime_check.Unsigned] indicates to the hypothetical runtime_check module that this type is an unsigned int. Every other consumer of this type can ignore this metadata and treat this type as int. The first argument to Annotated must be a valid type, the remaining arguments are kept as a tuple in the __metadata__ field. Details: - It's an error to call `Annotated` with less than two arguments. - Nested Annotated are flattened:: Annotated[Annotated[T, Ann1, Ann2], Ann3] == Annotated[T, Ann1, Ann2, Ann3] - Instantiating an annotated type is equivalent to instantiating the underlying type:: Annotated[C, Ann1](5) == C(5) - Annotated can be used as a generic type alias:: Optimized = Annotated[T, runtime.Optimize()] Optimized[int] == Annotated[int, runtime.Optimize()] OptimizedList = Annotated[List[T], runtime.Optimize()] OptimizedList[int] == Annotated[List[int], runtime.Optimize()] NrJrKrLrMr r r r r-i)r )_BaseGenericAlias) GenericAliascCs>t|trtSt|tjttttfr|j S|tj urtj SdS)a6Get the unsubscripted version of a type. This supports generic types, Callable, Tuple, Union, Literal, Final, ClassVar and Annotated. Return None for unsupported types. Examples:: get_origin(Literal[42]) is Literal get_origin(int) is None get_origin(ClassVar[int]) is ClassVar get_origin(Generic) is Generic get_origin(Generic[T]) is Generic get_origin(Union[T, int]) is Union get_origin(List[Tuple[T, T]][int]) == list get_origin(P.args) is P N) rrr-rdrfrr ParamSpecArgsParamSpecKwargsrr)rur r r r;s   r;cCszt|tr |jf|jSt|tjtfr;t|ddrdS|j}t |t j j ur9|dt ur9t|dd|df}|SdS)aGet type arguments with all substitutions performed. For unions, basic simplifications used by Union constructor are performed. Examples:: get_args(Dict[str, int]) == (str, int) get_args(int) == () get_args(Union[int, Union[T, int], str][int]) == (int, str) get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) get_args(Callable[[], T][int]) == ([], int) rFr rNr)rrrrrdrfrrrr;rrrEllipsisr)rurr r r r:s  r:r7)rrjc@eZdZddZdS)_TypeAliasFormcCrZr[r\r^r r r r_r`_TypeAliasForm.__repr__NrJrKrLr_r r r r r rcCt|d)&Special marker indicating that an assignment should be recognized as a proper type alias definition by type checkers. For example:: Predicate: TypeAlias = Callable[..., bool] It's invalid when used anywhere except as in the example above.  is not subscriptablerArr r r r7s c@r)rcCrZr[r\r^r r r r_r`rNrr r r r rraSpecial marker indicating that an assignment should be recognized as a proper type alias definition by type checkers. For example:: Predicate: TypeAlias = Callable[..., bool] It's invalid when used anywhere except as in the example above.c@r)_TypeAliasMetazMetaclass for TypeAliascCdSNztyping_extensions.TypeAliasr r^r r r r_rz_TypeAliasMeta.__repr__NrJrKrLrMr_r r r r r rc@s,eZdZdZdZddZddZddZd S) _TypeAliasBaserr cCr@)Nz+TypeAlias cannot be used with isinstance().rArBr r r rErFz _TypeAliasBase.__instancecheck__cCr@)Nz+TypeAlias cannot be used with issubclass().rArGr r r rH rFz _TypeAliasBase.__subclasscheck__cCrrr r^r r r r_ rz_TypeAliasBase.__repr__N)rJrKrLrMrrErHr_r r r r rs   r)rrOrc@r>) _Immutablez3Mixin to indicate that object should not be copied.r cCrrsr r^r r r __copy__rz_Immutable.__copy__cCrrsr )rCmemor r r __deepcopy__ rz_Immutable.__deepcopy__N)rJrKrLrMrrrr r r r rs  rc@ eZdZdZddZddZdS)raQThe args for a ParamSpec object. Given a ParamSpec object P, P.args is an instance of ParamSpecArgs. ParamSpecArgs objects have a reference back to their ParamSpec: P.args.__origin__ is P This type is meant for runtime introspection and has no special meaning to static type checkers. cCrrrsrrCr^r r r rw/r`zParamSpecArgs.__init__cC|jjdS)Nz.argsrrJr^r r r r_2zParamSpecArgs.__repr__NrJrKrLrMrwr_r r r r r# c@r)ra[The kwargs for a ParamSpec object. Given a ParamSpec object P, P.kwargs is an instance of ParamSpecKwargs. ParamSpecKwargs objects have a reference back to their ParamSpec: P.kwargs.__origin__ is P This type is meant for runtime introspection and has no special meaning to static type checkers. cCrrrsrrr r r rwAr`zParamSpecKwargs.__init__cCr)Nz.kwargsrr^r r r r_DrzParamSpecKwargs.__repr__Nrr r r r r5rrrcseZdZdZejZeddZeddZ ddddfd d Z d d Z d dZ ddZ ddZddZes>ddZZSZS)ra'Parameter specification variable. Usage:: P = ParamSpec('P') Parameter specification variables exist primarily for the benefit of static type checkers. They are used to forward the parameter types of one callable to another callable, a pattern commonly found in higher order functions and decorators. They are only valid when used in ``Concatenate``, or s the first argument to ``Callable``. In Python 3.10 and higher, they are also supported in user-defined Generics at runtime. See class Generic for more information on generic types. An example for annotating a decorator:: T = TypeVar('T') P = ParamSpec('P') def add_logging(f: Callable[P, T]) -> Callable[P, T]: '''A type-safe decorator to add logging to a function.''' def inner(*args: P.args, **kwargs: P.kwargs) -> T: logging.info(f'{f.__name__} was called') return f(*args, **kwargs) return inner @add_logging def add_two(x: float, y: float) -> float: '''Add two numbers together.''' return x + y Parameter specification variables defined with covariant=True or contravariant=True can be used to declare covariant or contravariant generic types. These keyword arguments are valid, but their actual semantics are yet to be decided. See PEP 612 for details. Parameter specification variables can be introspected. e.g.: P.__name__ == 'T' P.__bound__ == None P.__covariant__ == False P.__contravariant__ == False Note that only parameter specification variables defined in global scope can be pickled. cCt|Srs)rr^r r r rzParamSpec.argscCrrs)rr^r r r rrzParamSpec.kwargsNF)boundrTrVc st|g||_t||_t||_|rt|d|_nd|_z t dj dd}Wn t tfy:d}Ynw|dkrD||_dSdS)NzBound must be a type.ryrJrvtyping_extensions)rrwrJbool __covariant____contravariant__rdre __bound__rrrr=rkrlrK)rCrrrTrVdef_modrr r rws   zParamSpec.__init__cCs&|jrd}n|jr d}nd}||jS)N+-~)rrrJ)rCprefixr r r r_s  zParamSpec.__repr__cCrrs)rErr^r r r rr`zParamSpec.__hash__cCs||uSrsr rr r r rrFzParamSpec.__eq__cC|jSrs)rJr^r r r rzParamSpec.__reduce__cOrgrsr rr r r rrzParamSpec.__call__cCs||vr ||dSdSrs)appendrCrHr r r _get_type_varsszParamSpec._get_type_vars)rJrKrLrMrdrrrrrrwr_rrrrPEP_560rrr r rr rNs /   rcspeZdZer ejZnejZdZej Z fddZ ddZ ddZ dd Zed d Zes4d d ZZSZS)_ConcatenateGenericAliasFcst|||_||_dSrs)rrwrr)rCr^rrr r rws  z!_ConcatenateGenericAlias.__init__cs2tj|jddfdd|jDdS)Nrrc3s|]}|VqdSrsr rrr r rr5z4_ConcatenateGenericAlias.__repr__..r)rdrrrrr^r rr r_s z!_ConcatenateGenericAlias.__repr__cCrrs)rrrr^r r r rrz!_ConcatenateGenericAlias.__hash__cOrgrsr rr r r rrz!_ConcatenateGenericAlias.__call__cCstdd|jDS)Ncss$|] }t|tjtfr|VqdSrs)rrdrr)rrur r r rs  z:_ConcatenateGenericAlias.__parameters__..)rrr^r r r rsz'_ConcatenateGenericAlias.__parameters__cCs&|jr|jrt|j|dSdSdSrs)rrrdrrr r r rs z'_ConcatenateGenericAlias._get_type_vars)rJrKrLrrdrfr _TypingBaserrrrwr_rrrrrrr r rr rs  rcsZ|dkrtdt|ts|f}t|dtstddtfdd|D}t||S)Nr z&Cannot take a Concatenate of no types.rzAThe last parameter to Concatenate should be a ParamSpec variable.z/Concatenate[arg, ...]: each arg must be a type.c3rrsrrr!r r rr#z'_concatenate_getitem..)rrrrrrr r!r _concatenate_getitems  rcC t||S)&Used in conjunction with ``ParamSpec`` and ``Callable`` to represent a higher order function which adds, removes or transforms parameters of a callable. For example:: Callable[Concatenate[int, P], int] See PEP 612 for detailed information. rrr r r rs c@rX)_ConcatenateFormcCrZr[r\r^r r r r_ r`z_ConcatenateForm.__repr__cCrrsrrr r r ri r`z_ConcatenateForm.__getitem__Nrkr r r r r  rrc@r)_ConcatenateAliasMetazMetaclass for Concatenate.cCrNztyping_extensions.Concatenater r^r r r r_!rz_ConcatenateAliasMeta.__repr__Nrr r r r rrrc@s4eZdZdZdZddZddZddZd d Zd S) _ConcatenateAliasBaserr cCr@)Nz-Concatenate cannot be used with isinstance().rArBr r r rE3rFz'_ConcatenateAliasBase.__instancecheck__cCr@)Nz-Concatenate cannot be used with issubclass().rArGr r r rH6rFz'_ConcatenateAliasBase.__subclasscheck__cCrrr r^r r r r_9rz_ConcatenateAliasBase.__repr__cCrrsrrr r r ri<r`z!_ConcatenateAliasBase.__getitem__N) rJrKrLrMrrErHr_rir r r r r$s  rr8c@r)_TypeGuardFormcCrZr[r\r^r r r r_Gr`_TypeGuardForm.__repr__Nrr r r r rFrrcCs t||d}t||fS) Special typing form used to annotate the return type of a user-defined type guard function. ``TypeGuard`` only accepts a single type argument. At runtime, functions marked this way should return a boolean. ``TypeGuard`` aims to benefit *type narrowing* -- a technique used by static type checkers to determine a more precise type of an expression within a program's code flow. Usually type narrowing is done by analyzing conditional code flow and applying the narrowing to a block of code. The conditional expression here is sometimes referred to as a "type guard". Sometimes it would be convenient to use a user-defined boolean function as a type guard. Such a function should use ``TypeGuard[...]`` as its return type to alert static type checkers to this intention. Using ``-> TypeGuard`` tells the static type checker that for a given function: 1. The return value is a boolean. 2. If the return value is ``True``, the type of its argument is the type inside ``TypeGuard``. For example:: def is_str(val: Union[str, float]): # "isinstance" type guard if isinstance(val, str): # Type of ``val`` is narrowed to ``str`` ... else: # Else, type of ``val`` is narrowed to ``float``. ... Strict type narrowing is not enforced -- ``TypeB`` need not be a narrower form of ``TypeA`` (it can even be a wider form) and this may lead to type-unsafe results. The main reason is to allow for things like narrowing ``List[object]`` to ``List[str]`` even though the latter is not a subtype of the former, since ``List`` is invariant. The responsibility of writing type-safe type guards is left to the user. ``TypeGuard`` also works with type variables. For more information, see PEP 647 (User-Defined Type Guards). rz)rdrerfrgr r r r8Js,c@rX)rcCrZr[r\r^r r r r_|r`rcCra)Nz accepts only a single typercrgr r r rirjz_TypeGuardForm.__getitem__Nrkr r r r rzrlrcrn) _TypeGuardrrpNcKrrrsrprtr r r rwr`z_TypeGuard.__init__cCrx)Nryz accepts only a single type.TrNr{r|r~r r r rirz_TypeGuard.__getitem__cCrrrrr r r rrz_TypeGuard._eval_typecrrrrrr r r_rz_TypeGuard.__repr__cCrrsrr^r r r rrz_TypeGuard.__hash__cCrrs)rrrrqrr r r rrz_TypeGuard.__eq__rsrr r rr rs+  rrc@sneZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ejddZdS) _SpecialForm)r]rM_getitemcCs||_|j|_|j|_dSrs)rrJr]rM)rCrr r r rw s z_SpecialForm.__init__cCs|dvr|jSt|)N>rJrL)r]rk)rCrhr r r rsz_SpecialForm.__getattr__cCtd|)NrrA)rCr\r r r __mro_entries__rz_SpecialForm.__mro_entries__cCs d|jSr[r\r^r r r r_rz_SpecialForm.__repr__cCrrsr\r^r r r rrz_SpecialForm.__reduce__cOr)NzCannot instantiate rA)rCrrvr r r rrz_SpecialForm.__call__cCstj||fSrsrdUnionrr r r __or__!rz_SpecialForm.__or__cCstj||fSrsrrr r r __ror__$rz_SpecialForm.__ror__cCr)Nz! cannot be used with isinstance()rArBr r r rE'rz_SpecialForm.__instancecheck__cCr)Nz! cannot be used with issubclass()rArGr r r rH*rz_SpecialForm.__subclasscheck__cCs |||Srs)rrr r r ri-rz_SpecialForm.__getitem__N)rJrKrLrrwrrr_rrrrrErHrdrPrir r r r rsrcCr)Used to spell the type of "self" in classes. Example:: from typing import Self class ReturnsSelf: def parse(self, data: bytes) -> Self: ... return self rrA)rCr'r r r r1sc@r>)_Selfrr cCr)Nz" cannot be used with isinstance().rArBr r r rERrz_Self.__instancecheck__cCr)Nz" cannot be used with issubclass().rArGr r r rHUrz_Self.__subclasscheck__NrIr r r r rBs   rRequiredc@r)_ExtensionsSpecialFormcCrZr[r\r^r r r r_`r`z_ExtensionsSpecialForm.__repr__Nrr r r r r_rrcCra)A special typing construct to mark a key of a total=False TypedDict as required. For example: class Movie(TypedDict, total=False): title: Required[str] year: int m = Movie( title='The Matrix', # typechecker error if key is omitted year=1999, ) There is no runtime checking that a required key is actually provided when instantiating a related TypedDict. rbrcrgr r r rcscCra)`A special typing construct to mark a key of a TypedDict as potentially missing. For example: class Movie(TypedDict): title: str year: NotRequired[int] m = Movie( title='The Matrix', # typechecker error if key is omitted year=1999, ) rbrcrgr r r NotRequiredwsr c@rX) _RequiredFormcCrZr[r\r^r r r r_r`z_RequiredForm.__repr__cCs"t|d|j}t||fS)Nz{} accepts only single type)rdreformatr]rfrgr r r rirjz_RequiredForm.__getitem__Nrkr r r r r rr rr csJeZdZdZdddZddZddZfd d Zd d Zd dZ Z S)_MaybeRequiredrpNcKrrrsrprtr r r rwr`z_MaybeRequired.__init__c CsNt|}|jdur|t|d|jddddStd|jdd)Nz{} accepts only single type.ryTrNz {} cannot be further subscripted)r}rqrdrer rJrr~r r r ris z_MaybeRequired.__getitem__cCrrrrr r r rrz_MaybeRequired._eval_typecs.t}|jdur|dt|j7}|S)Nz[{}])rr_rqr rdrrrr r r_s  z_MaybeRequired.__repr__cCrrsrr^r r r rrz_MaybeRequired.__hash__cCs0t|t|s tS|jdur|j|jkS||uSrs)rr}rrqrr r r rs   z_MaybeRequired.__eq__rs) rJrKrLrrwrirr_rrrr r rr r s  r c@r) _RequiredrNrr r r r rrrc@r) _NotRequiredr Nrr r r r rrr)NNF)rrcollections.abcrrrd version_inforr}rrrr__all__extendrr=_FinalTypingBaser?rrPrQrRrSrUrrrrYror.r/r0rr_overload_dummyr2rrrr"r!r r(rMutableSequencer&r$_collections_abcrrrr)r*_aliasMutableMappingr'Dictrir%r#r1r6r9rrFrr r3r rrWrrQrer5r4r,r+rmrp__text_signature__r~rzrrJrKrMr-r<rrfrrrr;r:r ImportErrorrr7rrbrrrrrrrrrPrrrrrr8rrrrrr rr r rrr r r r s -       3   .    &        !B (   ,, '6 &b#           j,       . . O *       %