a oemT@st ddlZddlZddlZddlZddlZddlZejdddkZerLeZ nddlm Z m Z ddZ ddZ gd Z ere gd eed rejZn Gd d d ejddZeddZedZedZedZejdddZejdddZejZeedr ejdddkr ejZnXejdddkrXGdddejddZedddZn GdddejddZeddZeed rejZnd!d Zd"d#Zeed$rej Z nXejdddkrGd%d&d&ejddZ!e!d$d'dZ n Gd(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,rVej+Z+n"Gd-d,d,ej,ej-ee&ej,d.Z+ej.Z.eed/rej/Z/n"dd0l0m1Z2Gd1d/d/ej3eZ/ej4Z4eed2rej5Z5n`dejddkrd3krnne6ej5eefZ5n&Gd4d2d2ej5ej7eefe&ej5d.Z5eed5rBej8Z8n&Gd6d5d5ej8ej9ee:fe&ej8d.Z8eed7r|ej;Z;n2eed7rGd8d7d7ej;ej7eefe&ej;d.Z;eed9rejZ>ej?Z?d;d<Z@gd=ZAd>d?ZBd@dAZCeedBr2ejDZDnzerrddClmEZEdDdEZFGdFdGdGejGZHGdHdBdBeHdIZDn:ddJlmIZImJZJdKdEZFGdLdGdGe ZHGdMdBdBeHdIZDeedNrejKZKndOdNZKeKZLeedPrejMZMneKGdQdPdPeDZMejdRkrejNZNnTdSdTZOdUdVZPdWeP_QddXdYdZZRd[eR_QGd\d]d]eZSeSd^eTfiZNeUeN_Vd_eN_Weed`r|ejXZXejYZYejZZZnjerGdadbdbej[ddZZGdcd`d`ZXdddeZ\ddgdhZYn,didjZ]Gdkdldlej Z^Gdmd`d`e^dIZXejdddnkrej_Z_ej`Z`nnervzddolmaZaWneby8ej[ZaYn0zddplmcZcWnebydej[ZcYn0dqdrZ_dsdtZ`eedurejdZdnejdddvkrGdwdxdxejddZeeedyduZdnlejdddkrGdzdxdxejddZeeedud{dZdn4Gd|d}d}ejfZgGd~ddejegddZhehddZdeedrHejiZiejjZjn.GdddZkGdddekZiGdddekZjeedrejlZlnGdddemZleedsGdddemZnejoddZpeedrejqZqejnZnnejdddvkreeddZqnlejdddkr8GdddejddZrerdddZqn4GdddejfZsGdddejesddZtetddZqeedrejuZunejdddvkrGdddejddZvevddZunXejdddkrGdddejddZvevdddZun GdddejddZwewddZueed r$ejxZxnXejdddk r\GdddejddZeddZxn GdddejddZyeyddZxeed rejzZzej{Z{nejdddvk rGdddejddZ|e|ddZze|ddZ{nejdddk rGdddejddZ}e}dddZze}dddZ{nRGdddejddZ~Gddde~ddZGddde~ddZeddZzeddZ{dS)N)rr) GenericMeta _type_varscCs.t|}d|vr*|dD]}||dq|S)N __slots__)dictpop)ZdctZ dict_copyZslotr EC:\Program Files\Certbot\pkgs\setuptools\_vendor\typing_extensions.py_no_slots_copys  r c Cs^|jst|dt|}t|j}||krZtd||kr>dndd|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@s$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 cCs tddS)Nz*NoReturn cannot be used with isinstance().rselfobjr r r __instancecheck__msz_NoReturn.__instancecheck__cCs tddS)Nz*NoReturn cannot be used with issubclass().r<r>rr r r __subclasscheck__psz_NoReturn.__subclasscheck__N__name__ __module__ __qualname____doc__rr@rBr r r r r;_s r;T_rootTKTVTT_co) covariantT_contra) contravariantr)rrc@seZdZddZddZdS) _FinalFormcCs d|jSNztyping_extensions._namer>r r r __repr__sz_FinalForm.__repr__cCs"t||jd}t||fS)N accepts only single typetyping _type_checkrU _GenericAliasr>ritemr r r __getitem__s z_FinalForm.__getitem__NrDrErFrWr_r r r r rRsrRaWA 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.)doccsNeZdZdZdZdddZddZdd 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__NcKs ||_dSNrcr>tpkwdsr r r __init__sz_Final.__init__cCsRt|}|jdur6|t||jdddddSt|jddddS)N accepts only single type.TrH cannot be further subscriptedtyperdrZr[rDrr>r^rr r r r_s z_Final.__getitem__cCs.t|j||}||jkr|St||ddSNTrHrZ _eval_typerdrnr>globalnslocalnsZnew_tpr r r rrs z_Final._eval_typecs0t}|jdur,|dt|jd7}|SN[]superrWrdrZ _type_reprr>r __class__r r rWs  z_Final.__repr__cCstt|j|jfSrehashrnrDrdrVr r r __hash__sz_Final.__hash__cCs,t|tstS|jdur$|j|jkS||uSre) isinstancerbNotImplementedrdr>otherr r r __eq__s    z _Final.__eq__)N rDrErFrGrrir_rrrWrr __classcell__r r r~r rbs  rbr+cCs|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+scCs t|Sre)rZTypeVarnamer r r r,sr,r-c@seZdZddZddZdS) _LiteralFormcCs d|jSrSrTrVr r r rWsz_LiteralForm.__repr__cCs t||Sre)rZr\r>rr r r r_sz_LiteralForm.__getitem__Nr`r r r r rsraoA 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.csNeZdZdZdZdddZddZdd Zfd d Zd d Z ddZ Z S)_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__NcKs ||_dSrer)r>valuesrhr r r ri!sz_Literal.__init__cCsJt|}|jdur.t|ts"|f}||ddSt|jddddS)NTrHrjrl)rnrrtuplerrD)r>rrr r r r_$s    z_Literal.__getitem__cCs|Srer )r>rtrur r r rr,sz_Literal._eval_typecs8t}|jdur4|ddttj|jd7}|S)Nrw, rx)rzrWrjoinmaprZr{r|r~r r rW/s   z_Literal.__repr__cCstt|j|jfSre)rrnrDrrVr r r r5sz_Literal.__hash__cCs,t|tstS|jdur$|j|jkS||uSre)rrrrrr r r r8s    z_Literal.__eq__)Nrr r r~r rs   rcseZdZfddZZS)_ExtensionsGenericMetacs|jdur*tdjddvr&tddS|jssubclassresZsclsr~r r rBNs"      z(_ExtensionsGenericMeta.__subclasscheck__)rDrErFrBrr r r~r rMsrr%c@seZdZdZddZdS)r%r cOs6|jturtj|i|Stjtj|g|Ri|Sre)_gorgr% collectionsdequerZ _generic_newrargsrhr r r __new__ws z Deque.__new__NrDrErFrrr r r r r%rs) metaclassextrar!)_check_methodsc@s2eZdZdZddZejddZeddZ dS) r!r cs|Srer rVr r r __aenter__szAsyncContextManager.__aenter__csdSrer )r>exc_type exc_value tracebackr r r __aexit__szAsyncContextManager.__aexit__cCs|turt|ddStS)Nrr)r!_check_methods_in_mror)rCr r r rs z$AsyncContextManager.__subclasshook__N) rDrErFrrrabstractmethodr classmethodrr r r r r!s  r')rrrQc@seZdZdZddZdS)r'r cOs6|jturtj|i|Stjtj|g|Ri|Sre)rr'rrZrrr r r rs zOrderedDict.__new__Nrr r r r r'sr$c@seZdZdZddZdS)r$r cOs6|jturtj|i|Stjtj|g|Ri|Sre)rr$rrZrrr r r rs zCounter.__new__Nrr r r r r$sr"c@seZdZdZddZdS)r"r cOs6|jturtj|i|Stjtj|g|Ri|Sre)rr"rrZrrr r r rs zChainMap.__new__Nrr r r r r"sr c@seZdZdZdS)r r N)rDrErFrr r r r r scCs4t|tsJt|dr|jS|jdur0|j}q|S)z@This function exists for compatibility with old typing versions.rN)rrhasattrrrrr r r rs   r) CallablerIterableIteratorrrHashableSized Container Collection Reversibler#r!cCsrt}|jddD]X}|jdvr$qt|di}t|jt|D] }|dsJ|dvrJ||qJq|S)N)r0Generic__annotations___abc_)__abstractmethods__r __weakref__ _is_protocol_is_runtime_protocol__dict____args__r__next_in_mro__rr__orig_bases__r __tree_hash__rGrrirrE_MutableMapping__markerr) setrrDgetattrlistrkeys startswithadd)rattrsbase annotationsattrr r r _get_protocol_attrss  rcstfddtDS)Nc3s|]}tt|dVqdSre)callabler.0rrr r z,_is_callable_members_only..)allrrr rr _is_callable_members_onlysrr0)_collect_type_varscOst|jrtddSNz Protocols cannot be instantiatedrnrrr>rkwargsr r r _no_inits rcseZdZfddZZS) _ProtocolMetacsVtddrtr$tjr$dSjrJtfddtDrJdStS)NrFTc3s8|]0}t|o.tt|d p.t|duVqdSrerrrrrinstancer r rs 2_ProtocolMeta.__instancecheck__..) rrrrrrrrzr@rr~rr r@ s  _ProtocolMeta.__instancecheck__)rDrErFr@rr r r~r r srcs>eZdZdZdZdZfddZejddZ dd Z Z S) r0aBase 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)r0rrzrrr~r r r>sProtocol.__new__cst|ts|f}|s0|tjur0td|jddtfdd|D}|turtdd|Dsd}t||tjr|d7}qhtd |dd ||t t |t |krtd n t ||t ||S) NParameter list to [...] cannot be empty*Parameters to generic types must be types.c3s|]}t|VqdSrerZr[rpmsgr r rLrz-Protocol.__class_getitem__..css|]}t|tjVqdSrerrZrrr r r rOrrrjzBParameters to Protocol[...] must all be type variables. Parameter z is z.Parameters to Protocol[...] must all be unique) rrrZTuplerrFr0rrrrrr\)rparamsir rr __class_getitem__Ds4    zProtocol.__class_getitem__c sg}djvrtjjv}n tjjv}|r4tddjvrtj}d}jD]>}t|tjrT|j tjt fvrT|j j }|durtd|j }qT|dur|}nft |}t ||ksdfdd|D} ddd|D} td| d |d | d |}t|_ jd ds8td djD_fdd} djvrV| _jsbdSjD]T}|ttjfvsh|jdkr|j tvsht|tr|jshtdt|qht_dS)Nr!Cannot inherit from plain GenericzECannot inherit from Generic[...] and/or Protocol[...] multiple types.rc3s|]}|vrt|VqdSrestrrtgvarsetr r r~rz-Protocol.__init_subclass__..css|]}t|VqdSrerrgr r r rrSome type variables () are not listed in rwrxrcss|]}|tuVqdSre)r0rbr r r rrcsjddstStdds>tdjddvr6tStdtsftdjddvr^tStdt |t sxtd t D]t}|j D]`}||jvr|j|durtSqt|d i}t |t jr||vrt |tr|jrqqtSqd S) NrrFrQrDrBInstance and class checks can only be used with @runtime protocols._proto_hookrcollections.abc5Protocols can only inherit from other protocols, got )rrZrr __bases__rrrr\rr0rDrrrrranyrrobjectrE_PROTO_WHITELISTrreprrri) rrrtvarserrorgvarsrZthe_basetvarsets_varss_argsrr )rrr __init_subclass__^sl              zProtocol.__init_subclass__) rDrErFrGrrrrZ _tp_cacherr!rr r r~r r0s  )r) _next_in_mror[cOst|jrtddSrrrr r r rs csTeZdZdZd 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 sb|dus J|dur<|dus Jtdd|Ds:J|nt|}d} |D]F} | tjurbtdt| trL| jtjtfvrL| durtd| j } qL| dur|} nt |} t | | ksd fdd|D} d dd| D} t dd|Drd nd }td | d |d | d| }|}|durTt |tjurT||vrT|f|}tdd|D}t dd|Drtdd|D}|||dtt|j||||dd}tt|d|s|nt|||_ |rtdd|Dnd|_t||_|dur||_n|dur0|j|_|j|_t|dr^|rNt|n tt||_ |S)Ncss|]}t|tjVqdSrerrr r r rrz(_ProtocolMeta.__new__..rzACannot inherit from Generic[...] or Protocol[...] multiple times.rc3s|]}|vrt|VqdSrerrrr r rrcss|]}t|VqdSrerrr r r rrcss|]}|jtjuVqdSre)rrZrr r r r rsrr0r r rwrxcss$|]}t|trt|n|VqdSre)rrrr r r r rscss"|]}t|to|tjuVqdSre)rrrZrr r r r rrcss|]}|tjur|VqdSre)rZrr r r r rr)rrTrHrcss.|]&}|tjurdn|tjur"dn|VqdS).r N)rZ_TypingEllipsis _TypingEmptyrar r r rs _subs_tree)!rrrZrrrrrr0rrrrrnrABCMetarupdaterzr __setattr__rrr#rr _abc_registry _abc_cacherrr(rr)rrbases namespacerroriginr orig_basesrrrrr cls_nameZ initial_basesr>r~rr rs                 z_ProtocolMeta.__new__cstj|i|jdds6tddjD_jrjddD]`}|tt j fvsJ|j dkrp|j t vsJt|t jr|jsJt|tr|jt j usJtdt|qJt_fdd}d jvr|_dS) Nrcss*|]"}|tup t|to |jtuVqdSre)r0rrrr r r r r s z)_ProtocolMeta.__init__..rjrrcsjddstSt|ts$tdtD]t}|jD]`}||jvrb|j|dur^tSq,t|di}t|t j r6||vr6t|t r6|j r6q,q6tSq,dS)NrrrT) rrrrrnrrrrrZrrrrrr r rs*        z+_ProtocolMeta.__init__.._proto_hookr)rzrirrrrrrrrZrrErDrr TypingMetarrrrrr)rrrrrr~rr ris6      z_ProtocolMeta.__init__csZtddrtr$tjr$dSjrJtfddtDrJdStt S)NrFTc3s8|]0}t|o.tt|d p.t|duVqdSrerrrr>r r r;s r) rrrrrrrrzrr@)r>rr~r4r r@3s  rcs|jdur*tdjddvr&tddS|jddrf|jddsftdjddvr^dStd |jddrt|stdjddvrtt | |Std tt | |S) NrjrDrrFrrrrrZr r) rrrrrrrrrzrrBrAr~r r rBBs"  z_ProtocolMeta.__subclasscheck__c sNt|ts|f}|s4t|tjur4td|jddtfdd|D}|tjtfvrt dd|Dstdt |dt t |t |krtdt |d |}|}nX|tjtj fvrt|}|}n:|jtjtfvrtd t |nt||t|}|}|jdur|fnd }|j|j||jt|j||||j|jd S) Nrrrc3s|]}t|VqdSre)r[rrr r rdrz,_ProtocolMeta.__getitem__..css|]}t|tjVqdSrerrr r r rfrzParameters to z [...] must all be type variablesz[...] must all be uniquez%Cannot subscript already-subscripted r )rrr0rr1)rrrrZrrrFrr0rrrrrrrrrrDrr rrr)r>rrrZprependr rr r_ZsJ   z_ProtocolMeta.__getitem__)NNNNN) rDrErFrGrrir@rBrZr"r_rr r r~r rs@ ,  c@s eZdZdZdZdZddZdS)r0aBase 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|turtdtj|j|g|Ri|S)NzIType Protocol cannot be instantiated; it can be used only as a base class)rr0rrZrrrr r r rs rN)rDrErFrGrrrr r r r r0sr2cCs(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 r2s r)c@s$eZdZdZejedddZdS)r)r )returncCsdSrer rVr r r __index__szSupportsIndex.__index__N)rDrErFrrrintr7r r r r r)s)r rQc Cs<z tdjddvrtdWnttfy6Yn0dS)NrjrDr5z4TypedDict does not support instance and class checksF)rrrrAttributeError ValueError)rrr r r _check_failss  r<cOs0|s td|d|dd}}t|i|S)N)TypedDict.__new__(): not enough argumentsrrj)rr)rr_r r r _dict_newsr?z,($cls, _typename, _fields=None, /, **kwargs)totalc OsX|s td|d|dd}}|r>|d|dd}}n4d|vrj|d}ddl}|jdtddntd|rz |\}Wqtytd t|dd Yq0ntypenamerEfieldsnsr r r _typeddict_newsH      rLz;($cls, _typename, _fields=None, /, *, total=True, **kwargs)cs4eZdZdfdd Zdfdd ZeZZZS)rHTcst|||dSre)rzri)rrr.rKrAr~r r risz_TypedDictMeta.__init__c s|dkr tnt|d<t||tf|}i}|di}t|}dfdd|D}t} t} |D]@} | | j di| | j dd| | j d dqn| ||r| |n | |||_ t | |_ t | |_t|d s||_|S) Nr(rrz?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typecsi|]\}}|t|qSr r)rnrgrr r *sz*_TypedDictMeta.__new__..__required_keys__r __optional_keys__ __total__)rLr?rzrrrrritemsr*rr frozensetrOrPrrQ) rrr.rKrAtp_dictrown_annotationsown_annotation_keys required_keys optional_keysrr~rr rs2         z_TypedDictMeta.__new__)T)T) rDrErFrirr<r@rBrr r r~r rHs&rHr(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||||_dSre)rrY __metadata__rrzri)r>r0metadatar~r r rivs   z_AnnotatedAlias.__init__cCs$t|dksJ|d}t||jS)Nrjr)rrYrZ)r>rnew_typer r r copy_with}sz_AnnotatedAlias.copy_withcCs,dt|jdddd|jDdS)Nztyping_extensions.Annotated[rcss|]}t|VqdSrerr&r r r rrz+_AnnotatedAlias.__repr__..rx)rZr{rrrZrVr r r rWsz_AnnotatedAlias.__repr__cCstjt|jf|jffSre)operatorgetitemr*rrZrVr r r __reduce__sz_AnnotatedAlias.__reduce__cCs*t|tstS|j|jkrdS|j|jkS)NF)rrYrrrZrr r r rs   z_AnnotatedAlias.__eq__cCst|j|jfSre)rrrZrVr r r rsz_AnnotatedAlias.__hash__) rDrErFrGrir]rWrarrrr r r~r rYns rYc@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 cOs tddS)Nz&Type Annotated cannot be instantiated.r<rrrr r r rszAnnotated.__new__cCsLt|trt|dkrtdd}t|d|}t|dd}t||S)NrQzUAnnotated[...] should be used with at least two arguments (a type and an annotation).$Annotated[t, ...]: t must be a type.rrj)rrrrrZr[rY)rrrr0r[r r r rs zAnnotated.__class_getitem__cOstd|jddS)NCannot subclass z .Annotated)rrErbr r r r!s zAnnotated.__init_subclass__N) rDrErFrGrrrZr"rr!r r r r r*s   cCs\t|trt|jSt|tjrXtdd|jD}||jkrB|S||}|j |_ |S|S)z2Strips the annotations from a given type. css|]}t|VqdSre_strip_annotationsr&r r r rrz%_strip_annotations..) rrYrfrrZr\rrr]_special)r stripped_argsrr r r rfs     rfFcCs*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. )rtrucSsi|]\}}|t|qSr re)rkrr r r rNrz"get_type_hints..)rZr9rR)r?rtruinclude_extrashintr r r r9sr9cCs t|dko|do|dS)z3Returns True if name is a __dunder_variable_name__.__)rrendswithrr r r _is_dundersrocseZdZdZfddZeddZddZdfd d Zd d Z e j fd dZ ddZ ddZfddZddZddZZS) AnnotatedMetazMetaclass for Annotatedc s<tdd|Dr"tdtttj||||fi|S)Ncss|]}|tuVqdSre)rr r r r r rz(AnnotatedMeta.__new__..rd)rrrr*rzr)rrr.r/rr~r r r szAnnotatedMeta.__new__cCs |dS)NrQ)r(rVr r r rZszAnnotatedMeta.__metadata__cCsX|\}}}t|ts t|}n|d|}ddd|D}|d|d|dS)Nrrcss|]}t|VqdSrer^rargr r r rrz+AnnotatedMeta._tree_repr..rwrx)rrrZr{ _tree_reprr)r>treerr0r[Ztp_reprZmetadata_reprsr r r rss    zAnnotatedMeta._tree_reprNcsh|tur tStj||d}t|dtrd|ddturd|dd}|dd}t|||dfS|S)N)rrrjrrQ)r*rzr(rr)r>rrrZsub_tpZ sub_annotr~r r r(s  zAnnotatedMeta._subs_treecCsT|jdurtd|}t|tr:|dtur:|d}qt|trL|dS|SdS)z6Return the class used to create instance of this type.NzCCannot get the underlying type of a non-specialized Annotated type.rrj)rrr(rrr*)r>rtr r r _get_cons's   zAnnotatedMeta._get_conscst|ts|f}|jdur&t|St|trrrrgr[r~r r r_4s"    zAnnotatedMeta.__getitem__cOs8|}||i|}z ||_Wnty2Yn0|Sre)ru__orig_class__r:)r>rrZconsresultr r r __call__Ls  zAnnotatedMeta.__call__cCs,|jdur t|s t||St|dSre)rrorrur:)r>rr r r __getattr__UszAnnotatedMeta.__getattr__csJt|s|dr"t||n$|jdur6t|nt|||dS)Nr)rorrzr+rr:setattrru)r>rvaluer~r r r+[s   zAnnotatedMeta.__setattr__cCs tddS)Nz+Annotated cannot be used with isinstance().r<r=r r r r@cszAnnotatedMeta.__instancecheck__cCs tddS)Nz+Annotated cannot be used with issubclass().r<rAr r r rBfszAnnotatedMeta.__subclasscheck__)NN)rDrErFrGrpropertyrZrsr(rurZr"r_rxryr+r@rBrr r r~r rps       rpc@seZdZdZdS)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()] NrDrErFrGr r r r r*is)r )_BaseGenericAlias) GenericAliascCs>t|trtSt|tjttttfr*|j S|tj ur:tj 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) rrYr*rZr\rr ParamSpecArgsParamSpecKwargsrr)rgr r r r8s   r8cCszt|tr|jf|jSt|tjtfrvt|ddr8dS|j}t |t j j urr|dt urrt|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) rgFr rNr)rrYrrZrZr\rrrr8rrrEllipsisr)rgrr r r r7s  r7r4)rr9c@seZdZddZdS)_TypeAliasFormcCs d|jSrSrTrVr r r rWs_TypeAliasForm.__repr__NrDrErFrWr r r r rsrcCst|ddS)&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 subscriptableNr<rr r r r4s c@seZdZddZdS)rcCs d|jSrSrTrVr r r rWsrNrr r r r rsaSpecial 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@seZdZdZddZdS)_TypeAliasMetazMetaclass for TypeAliascCsdSNztyping_extensions.TypeAliasr rVr r r rWsz_TypeAliasMeta.__repr__NrDrErFrGrWr r r r rsrc@s,eZdZdZdZddZddZddZd S) _TypeAliasBaserr cCs tddS)Nz+TypeAlias cannot be used with isinstance().r<r=r r r r@sz _TypeAliasBase.__instancecheck__cCs tddS)Nz+TypeAlias cannot be used with issubclass().r<rAr r r rB sz _TypeAliasBase.__subclasscheck__cCsdSrr rVr r r rW sz_TypeAliasBase.__repr__N)rDrErFrGrr@rBrWr r r r rs  r)rrIrc@s$eZdZdZdZddZddZdS) _Immutablez3Mixin to indicate that object should not be copied.r cCs|Srer rVr r r __copy__sz_Immutable.__copy__cCs|Srer )r>memor r r __deepcopy__ sz_Immutable.__deepcopy__N)rDrErFrGrrrr r r r rsrc@s 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. cCs ||_dSrerr>r0r r r ri/szParamSpecArgs.__init__cCs|jjdS)Nz.argsrrDrVr r r rW2szParamSpecArgs.__repr__NrDrErFrGrirWr r r r r#s c@s eZdZdZddZddZdS)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. cCs ||_dSrerrr r r riAszParamSpecKwargs.__init__cCs|jjdS)Nz.kwargsrrVr r r rWDszParamSpecKwargs.__repr__Nrr r r r r5s rrcs|eZdZdZejZeddZeddZ ddddfd d Z d d Z d dZ ddZ ddZddZestddZZS)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. cCst|Sre)rrVr r r rszParamSpec.argscCst|Sre)rrVr r r rszParamSpec.kwargsNF)boundrNrPc st|g||_t||_t||_|rrrrNrPdef_modr~r r ris   zParamSpec.__init__cCs&|jr d}n|jrd}nd}||jS)N+-~)rrrD)r>prefixr r r rWs zParamSpec.__repr__cCs t|Sre)rrrVr r r rszParamSpec.__hash__cCs||uSrer rr r r rszParamSpec.__eq__cCs|jSre)rDrVr r r raszParamSpec.__reduce__cOsdSrer rr r r rxszParamSpec.__call__cCs||vr||dSre)appendr>rr r r _get_type_varsszParamSpec._get_type_vars)rDrErFrGrZrrr|rrrirWrrrarxPEP_560rrr r r~r rNs/   rcsheZdZerejZnejZdZej Z fddZ ddZ ddZ dd Zed d Zes`d d ZZS)_ConcatenateGenericAliasFcst|||_||_dSre)rzrirr)r>r0rr~r r ris z!_ConcatenateGenericAlias.__init__cs2tj|jddfdd|jDdS)Nrwrc3s|]}|VqdSrer rqr{r r rrz4_ConcatenateGenericAlias.__repr__..rx)rZr{rrrrVr rr rWs z!_ConcatenateGenericAlias.__repr__cCst|j|jfSre)rrrrVr r r rsz!_ConcatenateGenericAlias.__hash__cOsdSrer rr r r rxsz!_ConcatenateGenericAlias.__call__cCstdd|jDS)Ncss"|]}t|tjtfr|VqdSre)rrZrr)rrgr r r rsz:_ConcatenateGenericAlias.__parameters__..)rrrVr r r rsz'_ConcatenateGenericAlias.__parameters__cCs|jr|jrt|j|dSre)rrrZrrr r r rs z'_ConcatenateGenericAlias._get_type_vars)rDrErFrrZr\rZ _TypingBasergrrrirWrrxr|rrrr r r~r rs  rcsZ|dkrtdt|ts |f}t|dts6tddtfdd|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.c3s|]}t|VqdSrerrrr r rrz'_concatenate_getitem..)rrrrrrr rr _concatenate_getitems rcCs 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@seZdZddZddZdS)_ConcatenateFormcCs d|jSrSrTrVr r r rW sz_ConcatenateForm.__repr__cCs t||Srerrr r r r_ sz_ConcatenateForm.__getitem__Nr`r r r r r srrc@seZdZdZddZdS)_ConcatenateAliasMetazMetaclass for Concatenate.cCsdSNztyping_extensions.Concatenater rVr r r rW!sz_ConcatenateAliasMeta.__repr__Nrr r r r rsrc@s4eZdZdZdZddZddZddZd d Zd S) _ConcatenateAliasBaserr cCs tddS)Nz-Concatenate cannot be used with isinstance().r<r=r r r r@3sz'_ConcatenateAliasBase.__instancecheck__cCs tddS)Nz-Concatenate cannot be used with issubclass().r<rAr r r rB6sz'_ConcatenateAliasBase.__subclasscheck__cCsdSrr rVr r r rW9sz_ConcatenateAliasBase.__repr__cCs t||Srerrr r r r_<sz!_ConcatenateAliasBase.__getitem__N) rDrErFrGrr@rBrWr_r r r r r$s  rr5c@seZdZddZdS)_TypeGuardFormcCs d|jSrSrTrVr r r rWGs_TypeGuardForm.__repr__Nrr r r r rFsrcCs 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). rk)rZr[r\r]r r r r5Js,c@seZdZddZddZdS)rcCs d|jSrSrTrVr r r rW|srcCs"t||jd}t||fS)Nz accepts only a single typerYr]r r r r_s z_TypeGuardForm.__getitem__Nr`r r r r rzsrcsNeZdZdZdZdddZddZdd Zfd d Zd d Z ddZ Z S) _TypeGuardrrcNcKs ||_dSrercrfr r r risz_TypeGuard.__init__cCsRt|}|jdur6|t||jdddddSt|jddddS)Nrjz accepts only a single type.TrHrlrmror r r r_s z_TypeGuard.__getitem__cCs.t|j||}||jkr|St||ddSrprqrsr r r rrs z_TypeGuard._eval_typecs0t}|jdur,|dt|jd7}|Srvryr|r~r r rWs  z_TypeGuard.__repr__cCstt|j|jfSrerrVr r r rsz_TypeGuard.__hash__cCs,t|tstS|jdur$|j|jkS||uSre)rrrrdrr r r rs    z_TypeGuard.__eq__)Nrr r r~r rs+  rrc@sneZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ejddZdS) _SpecialForm)rUrG_getitemcCs||_|j|_|j|_dSre)rrDrUrG)r>r`r r r ri sz_SpecialForm.__init__cCs|dvr|jSt|dS)N>rDrF)rUr:)r>r^r r r rysz_SpecialForm.__getattr__cCstd|dS)Nrdr<)r>r.r r r __mro_entries__sz_SpecialForm.__mro_entries__cCs d|jSrSrTrVr r r rWsz_SpecialForm.__repr__cCs|jSrerTrVr r r rasz_SpecialForm.__reduce__cOstd|dS)NzCannot instantiate r<)r>rrhr r r rxsz_SpecialForm.__call__cCstj||fSrerZUnionrr r r __or__!sz_SpecialForm.__or__cCstj||fSrerrr r r __ror__$sz_SpecialForm.__ror__cCst|ddS)Nz! cannot be used with isinstance()r<r=r r r r@'sz_SpecialForm.__instancecheck__cCst|ddS)Nz! cannot be used with issubclass()r<rAr r r rB*sz_SpecialForm.__subclasscheck__cCs |||Sre)rrr r r r_-sz_SpecialForm.__getitem__N)rDrErFrriryrrWrarxrrr@rBrZr"r_r r r r rsrcCst|ddS)Used to spell the type of "self" in classes. Example:: from typing import Self class ReturnsSelf: def parse(self, data: bytes) -> Self: ... return self rNr<)r>rr r r r1sc@s$eZdZdZdZddZddZdS)_Selfrr cCst|ddS)Nz" cannot be used with isinstance().r<r=r r r r@Rsz_Self.__instancecheck__cCst|ddS)Nz" cannot be used with issubclass().r<rAr r r rBUsz_Self.__subclasscheck__NrCr r r r rBs rRequiredc@seZdZddZdS)_ExtensionsSpecialFormcCs d|jSrSrTrVr r r rW`sz_ExtensionsSpecialForm.__repr__Nrr r r r r_srcCs"t||jd}t||fS)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. rXrYr]r r r rcscCs"t||jd}t||fS)`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, ) rXrYr]r r r NotRequiredwsrc@seZdZddZddZdS) _RequiredFormcCs d|jSrSrTrVr r r rWsz_RequiredForm.__repr__cCs"t|d|j}t||fS)Nz{} accepts only single type)rZr[formatrUr\r]r r r r_s z_RequiredForm.__getitem__Nr`r r r r rsrrrcsJeZdZdZdddZddZddZfd d Zd d Zd dZ Z S)_MaybeRequiredrcNcKs ||_dSrercrfr r r risz_MaybeRequired.__init__c CsRt|}|jdur6|t|d|jddddStd|jdddS)Nz{} accepts only single type.rjTrHz {} cannot be further subscripted)rnrdrZr[rrDrror r r r_s  z_MaybeRequired.__getitem__cCs.t|j||}||jkr|St||ddSrprqrsr r r rrs z_MaybeRequired._eval_typecs.t}|jdur*|dt|j7}|S)Nz[{}])rzrWrdrrZr{r|r~r r rWs  z_MaybeRequired.__repr__cCstt|j|jfSrerrVr r r rsz_MaybeRequired.__hash__cCs0t|t|stS|jdur(|j|jkS||uSre)rrnrrdrr r r rs   z_MaybeRequired.__eq__)N) rDrErFrrir_rrrWrrrr r r~r rs   rc@seZdZdZdS) _RequiredrNr}r r r r rsrc@seZdZdZdS) _NotRequiredrNr}r r r r rsr)NNF)rrcollections.abcr_rrZ version_inforrnrrr r__all__extendrr:Z_FinalTypingBaser;rrJrKrLrMrOrrrrRrbr+r,r-rr_overload_dummyr/rrrrrrr%rMutableSequencer#r!_collections_abcrrrr&r'_aliasMutableMappingr$Dictr8r"r r.r3r6rrrrr0rrr)rr#r[r2r1r)r(r<r?__text_signature__rLrHrrDrErGr*r9rYr\rfrorpr8r7r ImportErrorrr4rr3rrrrrrrrr"rrrrrr5rrrrrrrrrrrr r r r s -       3   .      &        !B(    ,, '6 &b#         j ,      . .O  *      %