U a@sLddlZddlZddlZddlZddlZddlmZddlZddlmZm Z m Z m Z ej dddkZ e rteZZnddlmZmZdZzddlmZmZmZWnek rdZYnXzdd lmZdZWnek rdZYnXzdd lmZWnek rd d ZYnXzdd lmZmZWn2ek r^GdddZGdddZYnXddZddZeedrejZnddZeedrddlmZdZ ndZdZ ej dddkrddl!Z!e!j"Z#nddZ#ddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1gZ$e peZ%e r*e$&d2d3d4ge%r:e$'d5ej ddd6kZ(e(rbe$&d7d8d9geed:rvej)Z)nXeed;rGdZ+e+dd>Z)n*Gd?d@d@ejZ,GdAd:d:ej-e,ddBZ)e dCZ.e dDZ/e dEZ0ej dFddGZ1ej dHddGZ2ej dIddGZ3ej dJddKZ4eedr8ej5Z5nXeed;rfGdLdMdMej*dd>Z6e6dd>Z5n*GdNdOdOejZ7GdPddej-e7ddBZ5eed rej dddQkrej-Z-nej dddQkrGdRdSdSej8dd>Z9e9d dTdUZ-nXeed;rGdVdWdWej*dd>Z:e:dd>Z-n*GdXdYdYejZ;GdZd d ej-e;ddBZ-eed)r\ejZ>nej dddQkrGd]d^d^ej8dd>Z?e?d+d_dUZ>nXeed;rGd`dadaej*dd>Z@e@dd>Z>n*GdbdcdcejZAGddd+d+ej-eAddBZ>dedfZBdgd-ZCeed"r4ejDZDn*ej dhdediZEGdjd"d"ejeEedkZDdldmZFGdndodoeZGeFdprGdqdpdpeje1eGejHdrZHeFdsrGdtdsdseHe2eje1e4e2feGejIdrZIeFdurGdvdudueje1eGejJdrZJeFdwr GdxdwdweJe1eGejKdrZKeed%r4ejLZLnLe r^Gdyd%d%ejMejNe.eGejMdrZLn"Gdzd%d%ejMejNe.eGejMdrZLeed#rejOZOnBeed{rGd|d#d#eje1eGejPdrZOnGd}d#d#eje1ZOeed~rejQZQe$'d~nReedr*Gdd~d~eje1eGejRdrZQe$'d~nej dddkrFeSdeed&rZejTZTnTe rGdd&d&ejUejVe/e0feGejUdrZTn&Gdd&d&ejUejVe/e0feGejUdrZTeedrejWZWndej ddkrdkrnneXejWe/e0fZWnTe r*GdddejWejVe/e0feGejWdrZWn&GdddejWejVe/e0feGejWdrZWeed$rdejYZYnd6ej ddkrdkrnnNe stZe dZ[GdddejZ\Gdd$d$ejYej]e.e^fe\ejYdrZYnTe rGdd$d$ejYej]e.e^feGejYdrZYn&Gdd$d$ejYej]e.e^feGejYdrZYeed rJej_Z_e$'dnjeed re rGdddej_ejVe/e0feGej_drZ_n&Gdddej_ejVe/e0feGej_drZ_e$'deFd rGdddeKe1eje1e4feGej`drZ`eed, rejaZandd,Zaeed. rejbZbnecZbeed1 r.ejdZdndZdddZee rHddZddpdddudwdddddd#d~g ZfddZgddZheed7 rejiZine( re sddZjGdddeZkGdd7d7ekdZieijldk r.eijljme rdnddei_lnFe r.ddlmZmnZnmoZoddZjGdddejpZkGdd7d7ekdZieed9 rBejqZqne( rPdd9Zqe( rZeqZreed( rnejsZsne( reqGdd(d(eiZsej dk rejtZtnTddZuddZvdev_wddddZxdex_wGdddeZyeydezfiZte{et_|det_leed5 rej}Z}ej~Z~ejZnpe rNGddĄdejndd>ZGdd5d5Z}ddDŽZddd4Z~n2e% rddʄZGdd̄dejZGdd5d5edZ}ej dddk rejZejZnze rddlmnZnzddlmZWnek renZYnXzddlmZWnek r enZYnXdd3Zdd2Zeed/ r0ejZnej dddk rhGddքdej8dd>Zedd/Znej dddQk rGddքdej8dd>Zed/ddUZnheed; rGddۄdejZGdd݄dej*eddBZedd>Zn&GddۄdejZGdd/d/eddBZeedr"ejZejZn.GdddZGdddeZGdddeZeed!rdejZnGdd!d!eZGdddeZeddZeedrejZejZnej dddkreddZnej dddQkrGdddej8dd>ZedddUZnheed;rFGdddejZGdddej*eddBZedd>Zn&GdddejZGdddeddBZeed0rejZnej dddkrGdddej8dd>Zedd0Znej dddQkrGdddej8dd>Zed0ddUZnXeed;rGdddej*dd>Zedd>Zn*GdddejZGdd0d0ej-eddBZdS(N)GenericCallableTypeVarTuple)rr) GenericMeta TypingMetaF) _type_vars _next_in_mro _type_checkT _subs_tree) _tp_cachecCs|SNxrr/Users/jalaguru/Documents/Proserv/artifacts/aws_dms_cdk_automation/aws-dms-cdk-automation/venv/lib/python3.8/site-packages/typing_extensions.pyr$sr_TypingEllipsis _TypingEmptyc@s eZdZdS)rN__name__ __module__ __qualname__rrrrr)src@s eZdZdS)rNrrrrrr,srcCs.t|}d|kr*|dD]}||dq|S)N __slots__)dictpop)dctZ dict_copyZslotrrr_no_slots_copy4s  r cCsX|jstdt|t|}t|j}||krTtd||kr@dndt|||fdS)Nz%s is not a generic classz0Too %s parameters for %s; actual %s, expected %smanyfew)__parameters__ TypeErrorreprlen)cls parametersalenelenrrr_check_generic<s r+ _generic_newcOs|j|f||Sr)__new__)Zbase_clsr'argskwargsrrrr,Vs_geqv)r0)rcGsN|j}|D]>}|D],}||jkr|j|dkr:tSq qtSq dS)NT)__mro____dict__NotImplemented)CmethodsmromethodBrrr_check_methods_in_mroes   r;ClassVar ConcatenateFinal ParamSpecTypeContextManagerCounterDeque DefaultDictZOrderedDictTypedDict SupportsIndexfinalIntVarLiteralNewTypeoverloadText TypeAlias TypeGuard TYPE_CHECKINGget_args get_originget_type_hints AnnotatedrrProtocolruntimeruntime_checkableNoReturn_FinalTypingBasec@s$eZdZdZdZddZddZdS) _NoReturn7Special 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. rcCs tddSNz*NoReturn cannot be used with isinstance().r$selfobjrrr__instancecheck__sz_NoReturn.__instancecheck__cCs tddSNz*NoReturn cannot be used with issubclass().r]r_r'rrr__subclasscheck__sz_NoReturn.__subclasscheck__N)rrr__doc__rrardrrrrrZs rZ_rootcs2eZdZdZd fdd ZddZddZZS) _NoReturnMetazMetaclass for NoReturnFcstj|||||dSNrf)superr-)r'namebases namespacerg __class__rrr-sz_NoReturnMeta.__new__cCs tddSr\r]r^rrrrasz_NoReturnMeta.__instancecheck__cCs tddSrbr]rcrrrrdsz_NoReturnMeta.__subclasscheck__)F)rrrrer-rard __classcell__rrrnrrhsrhc@seZdZdZdZdS)rXr[rNrrrrerrrrrrXs ) metaclassrgTKTVTT_co) covariantV_coVT_coT_contra) contravariantcsNeZdZdZdZdddZddZdd Zfd d Zd d Z ddZ Z S) _ClassVar[Special type construct to mark class variables. An annotation wrapped in ClassVar indicates that a given attribute is intended to be used as a class variable and should not be set on instances of that class. Usage:: class Starship: stats: ClassVar[Dict[str, int]] = {} # class variable damage: int = 10 # instance variable ClassVar accepts only types and cannot be further subscribed. Note that ClassVar is not a class itself, and should not be used with isinstance() or issubclass(). __type__NcKs ||_dSrr~r_tpkwdsrrr__init__sz_ClassVar.__init__c CsRt|}|jdkr6|t|d|jddddStd|jdddSN{} accepts only single type.Trf {} cannot be further subscriptedtypertypingr formatrr$r_itemr'rrr __getitem__s  z_ClassVar.__getitem__cCs.t|j||}||jkr|St||ddSNTrfr _eval_typerrr_globalnslocalnsZnew_tprrrrs z_ClassVar._eval_typecs.t}|jdk r*|dt|j7}|SN[{}]rj__repr__rrr _type_reprr_rrnrrrs  z_ClassVar.__repr__cCstt|j|jfSrhashrrrr_rrr__hash__sz_ClassVar.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr) isinstancer|r5rr_otherrrr__eq__s    z_ClassVar.__eq__)N rrrrerrrrrrrrprrrnrr|s   r|cs^eZdZdZdfdd ZddZdd Zd d Zd d ZfddZ ddZ ddZ Z S) _ClassVarMetazMetaclass for ClassVarNFcs(tj|||||d}|dk r$||_|Srirjr-rr'rkrlrmrrgr_rnrrr-*sz_ClassVarMeta.__new__cCs tddS)Nz*ClassVar cannot be used with isinstance().r]r^rrrra0sz_ClassVarMeta.__instancecheck__cCs tddS)Nz*ClassVar cannot be used with issubclass().r]rcrrrrd3sz_ClassVarMeta.__subclasscheck__cCsbt|}|jdk r*td|jddt|d|jdd}||j|jt|j |ddSNrrrTrrg rrr$rrrr __bases__rr4r_rr'paramrrrr6s   z_ClassVarMeta.__getitem__cCs@t|j||}||jkr|St||j|jt|j|jddSNTrrrrrrrrr4rrrrrBs z_ClassVarMeta._eval_typecs.t}|jdk r*|dt|j7}|SrrrrnrrrJs  z_ClassVarMeta.__repr__cCstt|j|jfSrrrrrrrPsz_ClassVarMeta.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rr<r5rrrrrrSs    z_ClassVarMeta.__eq__)NF rrrrer-rardrrrrrrprrrnrr's  rc@seZdZdZdZdS)r<r}Nrrrrerrrrrr<Zs)rrc@seZdZddZddZdS) _FinalFormcCs d|jSNztyping_extensions._namerrrrrssz_FinalForm.__repr__cCs t|d|j}t||fS)Nz{} accepts only single typerr rr _GenericAliasr_r(rrrrrvs z_FinalForm.__getitem__NrrrrrrrrrrqsraWA 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)_FinalA 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. r~NcKs ||_dSrr~rrrrrsz_Final.__init__c CsRt|}|jdkr6|t|d|jddddStd|jdddSrrrrrrrs  z_Final.__getitem__cCs.t|j||}||jkr|St||ddSrrrrrrrs z_Final._eval_typecs.t}|jdk r*|dt|j7}|Srrrrnrrrs  z_Final.__repr__cCstt|j|jfSrrrrrrrsz_Final.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rrr5rrrrrrs    z _Final.__eq__)Nrrrrnrrs   rcs^eZdZdZdfdd ZddZdd Zd d Zd d ZfddZ ddZ ddZ Z S) _FinalMetazMetaclass for FinalNFcs(tj|||||d}|dk r$||_|Srirrrnrrr-sz_FinalMeta.__new__cCs tddS)Nz'Final cannot be used with isinstance().r]r^rrrrasz_FinalMeta.__instancecheck__cCs tddS)Nz'Final cannot be used with issubclass().r]rcrrrrdsz_FinalMeta.__subclasscheck__cCsbt|}|jdk r*td|jddt|d|jdd}||j|jt|j |ddSrrrrrrrs   z_FinalMeta.__getitem__cCs@t|j||}||jkr|St||j|jt|j|jddSrrrrrrrs z_FinalMeta._eval_typecs.t}|jdk r*|dt|j7}|Srrrrnrrrs  z_FinalMeta.__repr__cCstt|j|jfSrrrrrrrsz_FinalMeta.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rr>r5rrrrrrs    z_FinalMeta.__eq__)NFrrrrnrrs  rc@seZdZdZdZdS)r>rNrrrrrr>scCs|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)frrrrF scCst|Sr)rrkrrrrG sc@seZdZddZddZdS) _LiteralFormcCs d|jSrrrrrrr)sz_LiteralForm.__repr__cCs t||Srrr_r(rrrr,sz_LiteralForm.__getitem__Nrrrrrr'sraoA 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)_LiteralA 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 ||_dSrr)r_valuesrrrrrMsz_Literal.__init__cCsJt|}|jdkr.t|ts"|f}||ddStd|jdddS)NTrfrr)rrrtupler$rr)r_rr'rrrrPs    z_Literal.__getitem__cCs|Srrr_rrrrrrYsz_Literal._eval_typecs6t}|jdk r2|ddttj|j7}|SNr, rjrrrjoinmaprrrrnrrr\s  z_Literal.__repr__cCstt|j|jfSrrrrrrrrrrbsz_Literal.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rrr5rrrrrres    z_Literal.__eq__)Nrrrrnrr=s    rcs^eZdZdZdfdd ZddZdd Zd d Zd d ZfddZ ddZ ddZ Z S) _LiteralMetazMetaclass for LiteralNFcs(tj|||||d}|dk r$||_|Sri)rjr-r)r'rkrlrmrrgr_rnrrr-qsz_LiteralMeta.__new__cCs tddS)Nz)Literal cannot be used with isinstance().r]r^rrrrawsz_LiteralMeta.__instancecheck__cCs tddS)Nz)Literal cannot be used with issubclass().r]rcrrrrdzsz_LiteralMeta.__subclasscheck__cCsVt|}|jdk r*td|jddt|ts:|f}||j|jt|j |ddS)NrrT)rrg) rrr$rrrrrrr4rrrrr}s    z_LiteralMeta.__getitem__cCs|Srrrrrrrsz_LiteralMeta._eval_typecs6t}|jdk r2|ddttj|j7}|Srrrrnrrrs  z_LiteralMeta.__repr__cCstt|j|jfSrrrrrrrsz_LiteralMeta.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rrHr5rrrrrrs    z_LiteralMeta.__eq__)NFrrrrnrrns  rc@seZdZdZdZdS)rHrN)rrrrerrrrrrHs cOs tddS)z*Helper for @overload to raise when called.zYou should not call an overloaded function. A series of @overload-decorated functions outside a stub module should always be followed by an implementation that is not @overload-ed.N)NotImplementedError)r.rrrr_overload_dummysrcCstS)a Decorator for overloaded functions/methods. In a stub file, place two or more stub definitions for the same function in a row, each decorated with @overload. For example: @overload def utf8(value: None) -> None: ... @overload def utf8(value: bytes) -> bytes: ... @overload def utf8(value: str) -> bytes: ... In a non-stub file (i.e. a regular .py file), do the same but follow it with an implementation. The implementation should *not* be decorated with @overload. For example: @overload def utf8(value: None) -> None: ... @overload def utf8(value: bytes) -> bytes: ... @overload def utf8(value: str) -> bytes: ... def utf8(value): # implementation goes here )r)funcrrrrJsCT_co)rwboundc@seZdZdZdZdS)r@aA 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. rNrqrrrrr@s)extracCsHtt|r(t|tt|t|<dStt|r@t|dSdSdS)z Returns True if the given type isn't defined in typing but is defined in collections_abc. Adds the type to __all__ if the collection is found in either typing or collection_abc. FTN)hasattrr__all__appendgetattrglobalscollections_abc)Z type_namerrr _define_guards    rcseZdZfddZZS)_ExtensionsGenericMetacstjdddks$tjdddkrN|jdk rNtdjddkrJtdd S|js`t|S|j |}|t k rx|S|j|j krd S|j D] }t |trqt||rd Sqd S) 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. Nr)rrTrrSrrabc functoolsCParameterized generics cannot be used with class or instance checksFT)sys version_info __origin__ _getframe f_globalsr$ __extra__rjrd__subclasshook__r5r3__subclasses__rr issubclass)r_subclassresZsclsrnrrrd s$$      z(_ExtensionsGenericMeta.__subclasscheck__)rrrrdrprrrnrr sr Awaitablec@seZdZdZdS)rrNrrrrrrrrr&s)rrr Coroutinec@seZdZdZdS)rrNrrrrrr,s AsyncIterablec@seZdZdZdS)rrNrrrrrr3s AsyncIteratorc@seZdZdZdS)rrNrrrrrr:sc@seZdZdZddZdS)rCrcOs*t|trtj||Sttj|f||Sr)r0rC collectionsdequer,r'r.rrrrr-Hs   Deque.__new__Nrrrrr-rrrrrCCsc@seZdZdZddZdS)rCrcOs*|jtkrtj||Sttj|f||Sr)_gorgrCrrr,rrrrr-Rs  rNrrrrrrCMsAbstractContextManagerc@seZdZdZdS)rArNrrrrrrA[sc@s2eZdZdZddZejddZeddZ dS) rArcCs|Srrrrrr __enter__cszContextManager.__enter__cCsdSrr)r_exc_type exc_value tracebackrrr__exit__fszContextManager.__exit__cCs8|tkr4tdd|jDr4tdd|jDr4dStS)Ncss|]}d|jkVqdS)rNr4.0r:rrr rsz2ContextManager.__subclasshook__..css|]}d|jkVqdS)rNrrrrrrssT)rAanyr3r5)r'r6rrrrjs zContextManager.__subclasshook__N) rrrrrrabstractmethodr classmethodrrrrrrA`s  AsyncContextManagerAbstractAsyncContextManagerc@seZdZdZdS)rrNrrrrrr|s)rrTa class AsyncContextManager(typing.Generic[T_co]): __slots__ = () async def __aenter__(self): return self @abc.abstractmethod async def __aexit__(self, exc_type, exc_value, traceback): return None @classmethod def __subclasshook__(cls, C): if cls is AsyncContextManager: return _check_methods_in_mro(C, "__aenter__", "__aexit__") return NotImplemented __all__.append('AsyncContextManager') c@seZdZdZddZdS)rDrcOs*t|trtj||Sttj|f||Sr)r0rDr defaultdictr,rrrrr-s  DefaultDict.__new__NrrrrrrDsc@seZdZdZddZdS)rDrcOs*|jtkrtj||Sttj|f||Sr)rrDrrr,rrrrr-s  r NrrrrrrDs OrderedDict)rrr1c@seZdZdZddZdS)r rcOs*t|trtj||Sttj|f||Sr)r0r rr,rrrrr-s  OrderedDict.__new__Nrrrrrr sc@seZdZdZddZdS)r rcOs*|jtkrtj||Sttj|f||Sr)rr rr,rrrrr-s  r Nrrrrrr s)rrTr_TIntcs eZdZdZfddZZS) _CounterMetazMetaclass for Countercst|tfSr)rjrint)r_rrnrrrsz_CounterMeta.__getitem__)rrrrerrprrrnrr sr c@seZdZdZddZdS)rBrcOs*t|trtj||Sttj|f||Srr0rBrr,rrrrr-s  Counter.__new__NrrrrrrBsc@seZdZdZddZdS)rBrcOs*t|trtj||Sttj|f||Srrrrrrr-s  rNrrrrrrBsc@seZdZdZddZdS)rBrcOs*|jtkrtj||Sttj|f||Sr)rrBrr,rrrrr-s  rNrrrrrrBsChainMapc@seZdZdZddZdS)rrcOs*t|trtj||Sttj|f||Sr)r0rrr,rrrrr- s  ChainMap.__new__Nrrrrrrsc@seZdZdZddZdS)rrcOs*|jtkrtj||Sttj|f||Sr)rrrr,rrrrr-s  rNrrrrrrsAsyncGeneratorc@seZdZdZdS)rrNrrrrrrscCsdd}||_||_|S)aQNewType creates simple unique types with almost zero runtime overhead. NewType(name, tp) is considered a subtype of tp by static type checkers. At runtime, NewType(name, tp) returns a dummy function that simply returns its argument. Usage:: UserId = NewType('UserId', int) def name_by_id(user_id: UserId) -> str: ... UserId('user') # Fails type check name_by_id(42) # Fails type check name_by_id(UserId(42)) # OK num = UserId(5) + 1 # type: int cSs|Srrrrrrnew_type:szNewType..new_type)r __supertype__)rkrrrrrrI'scCs4t|tstt|dr|jS|jdk r0|j}q|S)@This function exists for compatibility with old typing versions.rN)rrAssertionErrorrrrr'rrrrOs   rcCsHt}t|jddD],\}}t|trt|tkr|j|d}q|S)rNr)object enumerater3rrrr)r'Z next_in_mroicrrrr Zs r rIterableIteratorHashableSized Container Collection ReversiblecCsrt}|jddD]X}|jdkr$qt|di}t|jt|D] }|dsJ|dkrJ||qJq|S)Nr)rUr__annotations___abc_)__abstractmethods__r% __weakref__ _is_protocol_is_runtime_protocolr4__args__r__next_in_mro__r#r__orig_bases__r __tree_hash__rerrr-r_MutableMapping__markerr) setr3rrlistr4keys startswithadd)r'attrsbase annotationsattrrrr_get_protocol_attrsis  r9cstfddtDS)Nc3s|]}tt|dVqdSr)callablerrr8rrrr}sz,_is_callable_members_only..)allr9rrrr_is_callable_members_only|sr=cOst|jrtddSNz Protocols cannot be instantiatedrr)r$r_r.r/rrr_no_inits rAcsZeZdZdZesd fdd ZfddZfddZfd d ZesRe d d Z Z S) _ProtocolMetazInternal metaclass for Protocol. This exists so Protocol classes can be generic without deriving from Generic. Nc sH|dks t|dk r<|dk s ttdd|Ds:t|nt|}d} |D]B} | tkr`tdt| trL| jttfkrL| dk rtd| j } qL| dkr|} njt |} t | | kstdd fdd|Dt dd|Drd nd d d d| Df| }|} |dk r:t |tjkr:||kr:|f|}td d|D}t d d|Drrtdd|D}|||dtt|j||||dd} tt| d|s| nt||| _ |rtdd|Dnd| _t| | _|dkr| | _n|dk r|j| _|j| _t| drD|r4t| n tt| | _ | S)Ncss|]}t|tVqdSrrrrtrrrrsz(_ProtocolMeta.__new__..!Cannot inherit from plain GenericzACannot inherit from Generic[...] or Protocol[...] multiple times.z1Some type variables (%s) are not listed in %s[%s]rc3s|]}|krt|VqdSrstrrDgvarsetrrrscss|]}|jtkVqdSr)rrrbrrrrsrrUcss|]}t|VqdSrrGrgrrrrscss$|]}t|trt|n|VqdSr)rrrrKrrrrscss |]}t|to|tk VqdSr)rrrrKrrrrscss|]}|tk r|VqdSr)rrKrrrrs)rrTrfrcss*|]"}|tkrdn|tkrdn|VqdS).rNrrarrrrs  r)!rr<r rr$rrrrUr#r0rrrrABCMetarupdaterjr- __setattr__rr+r r,r- _abc_registry _abc_cacherrrrr.)r'rkrlrmtvarsr.originr orig_basesgvarsr6tvarsetZ initial_basesr_rnrIrr-s               z_ProtocolMeta.__new__cstj||jdds2tddjD_jrjddD]T}|tt fksF|j dkrj|j t ksFt |trz|jsFt |tr|jt ksFtd|qFt_fdd}d jkr|_dS) Nr)css*|]"}|tkp t|to |jtkVqdSr)rUrrBrrKrrrrs z)_ProtocolMeta.__init__..rcollections.abc7Protocols can only inherit from other protocols, got %rcsjddstSt|ts$tdtD]t}|jD]`}||jkrb|j|dkr^tSq,t|di}t|t j r6||kr6t|t r6|j r6q,q6tSq,dS)Nr)"issubclass() arg 1 must be a classr%T) r4getr5rrr$r9r3rrMappingrBr)rr8r6r7rrr _proto_hooks*        z+_ProtocolMeta.__init__.._proto_hookr)rjrr4r^rrr)r3rrrr_PROTO_WHITELISTrr rrr$rAr)r'r.r/r6rarnrrrs6    z_ProtocolMeta.__init__csZtddrtr$tjr$dSjrJtfddtDrJdStt S)Nr)FTc3s8|]0}t|o.tt|d p.t|dk VqdSrrr:rr;instancer_rrrs 2_ProtocolMeta.__instancecheck__..) rr=rror)r<r9rjrra)r_rernrdrras  _ProtocolMeta.__instancecheck__cs|jdk r*tdjddkr&tddS|jddrf|jddsftdjddkr^dStd |jddrt|stdjddkrtt | |Std tt | |S) NrrrrFr)r*rrrBInstance and class checks can only be used with @runtime protocols.css|]}t|tVqdSrrCrmrrrr0sz0Parameters to %r[...] must all be type variablesz(Parameters to %r[...] must all be uniquez'Cannot subscript already-subscripted %sr)rVr.rWrrX)rrrrr$rrrUr<r&r0rr rr%r+rorrr r4rr-)r_paramsrVr.prependrrorr$sN    z_ProtocolMeta.__getitem__)NNNNN) rrrre OLD_GENERICSr-rrardrrrprrrnrrBsA ,  rBc@s eZdZdZdZdZddZdS)rUaBase 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({bases}): def meth(self) -> T: ... rTcOsBt|tkrtdtr.tt||f||St|j|f||S)NzIType Protocol cannot be instantiated; it can be used only as a base class)rrUr$rsr,r r,rrrrr-ms  Protocol.__new__N)rrrrerr)r-rrrrrUMs)rrzProtocol, Generic[T]z Protocol[T])rl)r r_collect_type_varscOst|jrtddSr>r?r@rrrrA|s cseZdZfddZZS)rBcsVtddrtr$tjr$dSjrJtfddtDrJdStS)Nr)FTc3s8|]0}t|o.tt|d p.t|dk VqdSrrcr;r'rerrrs rf) rr=rror)r<r9rjrarvrnrvrras  rg)rrrrarprrrnrrBscs<eZdZdZdZdZfddZeddZdd Z Z S) rUaBase 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: ... rTcs|tkrtdt|S)NzIType Protocol cannot be instantiated; it can only be used as a base class)rUr$rjr-rrnrrr-srtcst|ts|f}|s,|tk r,td|jdtfdd|D}|tkrtdd|Dsd}t||tr||d7}qdtd|d||t t |t |krtd n t ||t ||S) Nz)Parameter list to {}[...] cannot be emptyrkc3s|]}t|VqdSrrlrmrorrrsz-Protocol.__class_getitem__..css|]}t|tVqdSrrCrmrrrrsrrzJParameters to Protocol[...] must all be type variables. Parameter {} is {}z.Parameters to Protocol[...] must all be unique) rrrr$rrrUr<rr&r0r+r)r'rqrrror__class_getitem__s2     zProtocol.__class_getitem__c sg}djkrtjk}n tjk}|r0tddjkrtj}d}jD]D}t|trN|jtt fkrN|jtkrxdnd}|dk rtd|j }qN|dkr|}nZt |}t ||ksd fdd|D} d d d|D} td | || |}t|_ jd ds,td djD_fd d} djkrJ| _jsVdSjD]L}|ttfks\|jdkr|jtks\t|tr|js\td|q\t_dS)Nr-rFrrUzECannot inherit from Generic[...] and/or Protocol[...] multiple types.rc3s|]}|krt|VqdSrrGrDrIrrrsz-Protocol.__init_subclass__..css|]}t|VqdSrrGrMrrrrsz1Some type variables ({}) are not listed in {}[{}]r)css|]}|tkVqdSr)rUrKrrrrscsjddstStdds>tdjddkr6tStdtsftdjddkr^tStdt |t sxtd t D]t}|j D]`}||jkr|j|dkrtSqt|d i}t |t jr||krt |tr|jrqqtSqd S) Nr)r*Fr1rrrirjr]r%T)r4r^r5rrrrr$r=rrr9r3rr_rBr)r`rrrras:         z/Protocol.__init_subclass__.._proto_hookrr[r\)r4rr-rr$rurrrrUr#r0rrrr^rr)rrrrrbrBrAr) r'r.r/rVerrorrYr6Zthe_baserZs_varss_argsrar)r'rJr__init_subclass__sl             zProtocol.__init_subclass__) rrrrerr)r-rrwr{rprrrnrrUs  cCs&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. zB@runtime_checkable can be only applied to protocol classes, got %rT)rrBr)r$r*rrrrrW6s c@s$eZdZdZejedddZdS)rEr)returncCsdSrrrrrr __index__QszSupportsIndex.__index__N)rrrrrrrr}rrrrrEMs)r r1c Cs>z tdjddkrtdWnttfk r8YnXdS)Nrrrhz4TypedDict does not support instance and class checksF)rrrr$AttributeError ValueError)r'rrrr _check_fails]s  rcOs,|s td|d|dd}}t||S)N)TypedDict.__new__(): not enough argumentsrr)r$r)r.r/_rrr _dict_newhsrz,($cls, _typename, _fields=None, /, **kwargs)totalc OsZ|s td|d|dd}}|r>|d|dd}}n4d|krj|d}ddl}|jdtddntd|rz |\}Wqtk rtd t|dYqXnsz*_TypedDictMeta.__new__..__required_keys__r__optional_keys__ __total__)rrrjrr-rr^r0r2itemsrRr4r% frozensetrrrr) r'rkrlrrtp_dictr7Zown_annotationsZown_annotation_keysZ required_keysZ optional_keysr6rnrorr-s2         z_TypedDictMeta.__new__)T)T) rrrrr-rrardrprrrnrrs&rraA 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+ 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||||_dSr)rr __metadata__rrjr)r_rWmetadatarnrrrs   z_AnnotatedAlias.__init__cCs$t|dkst|d}t||jS)Nrr)r&rrr)r_rqrrrr copy_withsz_AnnotatedAlias.copy_withcCs&dt|jddd|jDS)Nz#typing_extensions.Annotated[{}, {}]rcss|]}t|VqdSrr%rOrrrr sz+_AnnotatedAlias.__repr__..)rrrrrrrrrrr s z_AnnotatedAlias.__repr__cCstjt|jf|jffSr)operatorgetitemrRrrrrrr __reduce__s z_AnnotatedAlias.__reduce__cCs*t|tstS|j|jkrdS|j|jkS)NF)rrr5rrrrrrrs   z_AnnotatedAlias.__eq__cCst|j|jfSr)rrrrrrrrsz_AnnotatedAlias.__hash__) rrrrerrrrrrrprrrnrrs rc@s0eZdZdZdZddZeddZddZd S) rRaAdd 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()] rcOs tddS)Nz&Type Annotated cannot be instantiated.r]r'r.r/rrrr-BszAnnotated.__new__cCsLt|trt|dkrtdd}t|d|}t|dd}t||S)Nr1zUAnnotated[...] should be used with at least two arguments (a type and an annotation).$Annotated[t, ...]: t must be a type.rr)rrr&r$rr r)r'rqrprWrrrrrwEs zAnnotated.__class_getitem__cOstd|jdS)NzCannot subclass {}.Annotated)r$rrrrrrr{Ps zAnnotated.__init_subclass__N) rrrrerr-rrwr{rrrrrRs   cCs\t|trt|jSt|tjrXtdd|jD}||jkrB|S||}|j |_ |S|S)z2Strips the annotations from a given type. css|]}t|VqdSr_strip_annotationsrOrrrr[sz%_strip_annotations..) rrrrrrrr+r_special)rEZ stripped_argsrrrrrUs     rcCs*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|qSrr)rkrErrrrsz"get_type_hints..)rrQr)r`rrZinclude_extrashintrrrrQcscCs t|dko|do|dS)z3Returns True if name is a __dunder_variable_name__.__)r&r3endswithrrrr _is_dundersrcseZdZdZfddZeddZddZdfd d Zd d Z e fd dZ ddZ ddZ fddZddZddZZS) AnnotatedMetazMetaclass for Annotatedc s8tdd|Dr"tdtttj||||f|S)Ncss|]}|tk VqdSr)rrKrrrrsz(AnnotatedMeta.__new__..zCannot subclass )rr$rHrRrjr-)r'rkrlrmr/rnrrr-szAnnotatedMeta.__new__cCs |dS)Nr1r rrrrrszAnnotatedMeta.__metadata__cCsP|\}}}t|ts t|}n|d|}ddd|D}d|||fS)Nrrcss|]}t|VqdSrrrargrrrrsz+AnnotatedMeta._tree_repr..z %s[%s, %s])rrrr _tree_reprr)r_treer'rWrZtp_reprZmetadata_reprsrrrrs    zAnnotatedMeta._tree_reprNcsh|tkr tStj||d}t|dtrd|ddtkrd|dd}|dd}t|||dfS|S)N)rVr.rrr1)rRrjrrr)r_rVr.rZsub_tpZ sub_annotrnrrrs  zAnnotatedMeta._subs_treecCsT|jdkrtd|}t|tr:|dtkr:|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.rr)rr$rrrrR)r_rrrr _get_conss   zAnnotatedMeta._get_conscst|ts|f}|jdk r&t|St|tr 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|Sr)rrrrrr. szParamSpec.argscCst|Sr)rrrrrr/ szParamSpec.kwargsNF)rrwr{c st|g||_t||_t||_|r.)rWr.)rrrrrr+rrrrrY s z!_ConcatenateGenericAlias.__repr__cCst|j|jfSr)rrr+rrrrr_ sz!_ConcatenateGenericAlias.__hash__)rrrrrrrprrrnrrS s rcsZ|dkrtdt|ts |f}t|dts6tddtfdd|D}t||S)Nrz&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|VqdSrrrmrorrrl sz'_concatenate_getitem..)r$rrr?rrrror_concatenate_getitemb s 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. rrrrrr=t s c@seZdZddZddZdS)_ConcatenateFormcCs d|jSrrrrrrr sz_ConcatenateForm.__repr__cCs t||Srrrrrrr sz_ConcatenateForm.__getitem__Nrrrrrr srrc@seZdZdZddZdS)_ConcatenateAliasMetaMetaclass for Concatenate.cCsdSNztyping_extensions.Concatenaterrrrrr sz_ConcatenateAliasMeta.__repr__Nrrrrrr src@s4eZdZdZdZddZddZddZd d Zd S) _ConcatenateAliasBaserrcCs tddS)Nz-Concatenate cannot be used with isinstance().r]r^rrrra sz'_ConcatenateAliasBase.__instancecheck__cCs tddS)Nz-Concatenate cannot be used with issubclass().r]rcrrrrd sz'_ConcatenateAliasBase.__subclasscheck__cCsdSrrrrrrr sz_ConcatenateAliasBase.__repr__cCs t||Srrrrrrr sz!_ConcatenateAliasBase.__getitem__N) rrrrerrardrrrrrrr s  rc@s0eZdZdZddZddZddZdd Zd S) rrcCs tddSrr]r^rrrra sz'_ConcatenateAliasMeta.__instancecheck__cCs tddSrr]rcrrrrd sz'_ConcatenateAliasMeta.__subclasscheck__cOs tddSrr]r@rrrr sz_ConcatenateAliasMeta.__call__cCs t||Srrrrrrr sz!_ConcatenateAliasMeta.__getitem__N)rrrrerardrrrrrrr s c@seZdZdZdZdS)r=rrNrqrrrrr= s c@seZdZddZdS)_TypeGuardFormcCs d|jSrrrrrrr s_TypeGuardForm.__repr__Nrrrrrr srcCst|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). r)rr rrrrrrrM s,c@seZdZddZddZdS)rcCs d|jSrrrrrrr srcCs t|d|j}t||fS)Nz{} accepts only a single typerrrrrr s z_TypeGuardForm.__getitem__Nrrrrrr srcsNeZdZdZdZdddZddZdd Zfd d Zd d Z ddZ Z S) _TypeGuardrr~NcKs ||_dSrr~rrrrrs sz_TypeGuard.__init__c CsRt|}|jdkr6|t|d|jddddStd|jdddS)Nz{} accepts only a single type.rTrfrrrrrrrv s  z_TypeGuard.__getitem__cCs.t|j||}||jkr|St||ddSrrrrrrr s z_TypeGuard._eval_typecs.t}|jdk r*|dt|j7}|Srrrrnrrr s  z_TypeGuard.__repr__cCstt|j|jfSrrrrrrr sz_TypeGuard.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rrr5rrrrrr s    z_TypeGuard.__eq__)NrrrrnrrE s+   rcs^eZdZdZdfdd ZddZdd Zd d Zd d ZfddZ ddZ ddZ Z S)_TypeGuardMetazMetaclass for TypeGuardNFcs(tj|||||d}|dk r$||_|Srirrrnrrr- sz_TypeGuardMeta.__new__cCs tddS)Nz+TypeGuard cannot be used with isinstance().r]r^rrrra sz _TypeGuardMeta.__instancecheck__cCs tddS)Nz+TypeGuard cannot be used with issubclass().r]rcrrrrd sz _TypeGuardMeta.__subclasscheck__cCsbt|}|jdk r*td|jddt|d|jdd}||j|jt|j |ddSrrrrrrr s   z_TypeGuardMeta.__getitem__cCs@t|j||}||jkr|St||j|jt|j|jddSrrrrrrr s z_TypeGuardMeta._eval_typecs.t}|jdk r*|dt|j7}|Srrrrnrrr s  z_TypeGuardMeta.__repr__cCstt|j|jfSrrrrrrr sz_TypeGuardMeta.__hash__cCs,t|dstS|jdk r$|j|jkS||kS)Nr)rr5rrrrrr s    z_TypeGuardMeta.__eq__)NFrrrrnrr s  rc@seZdZdZdZdS)rMrNrrrrrrM s*)NNF)rr contextlibrrcollections.abcrrrrrrrZPEP_560rrr rsr r r ImportErrorrZ SUBS_TREErrrr r+rr,r0Z _geqv_defined_collections_abc_check_methodsr;rZHAVE_ANNOTATEDextendrZHAVE_PROTOCOLSrXrYrZrhr>rsrtrurvrxryrzr<r|r _SpecialFormrrrrFrGrHrrrrrJr@rrrrrrrrCrMutableSequencerArrrexecrDrMutableMappingr _aliasrBrr r DictrrrrIrKrHrNrrbr9r=rUrArBrerrrurQrWrVrErrr__text_signature__rrrrrrRrQrrrrrPrOrrrLrrrrrrr?r1rrr=rrrrMrrrrrrrs.        ,           5 3   4 3   / -                 &  &                    F'  "    ,. )6 $b$           f      . , P 3