U E_G@s ddlZddlZddlZddlZddlZddlmZddlZddlmZm 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-gZ$e p eZ%e r"e$&d.d/d0ge%r2e$'d1ej ddd2kZ(e(rZe$&d3d4d5geed6rnej)Z)nXeed7rGd8d9d9ej*dd:Z+e+dd:Z)n*Gd;d<dZ)e d?Z.e d@Z/e dAZ0ej dBddCZ1ej dDddCZ2ej dEddCZ3ej dFddGZ4eedr0ej5Z5nXeed7r^GdHdIdIej*dd:Z6e6dd:Z5n*GdJdKdKejZ7GdLddej-e7dd>Z5eedrej dddMkrej-Z-nej dddMkrGdNdOdOej8dd:Z9e9ddPdQZ-nXeed7rGdRdSdSej*dd:Z:e:dd:Z-n*GdTdUdUejZ;GdVddej-e;dd>Z-eed'rTejZ>nej dddMkrGdYdZdZej8dd:Z?e?d)d[dQZ>nXeed7rGd\d]d]ej*dd:Z@e@dd:Z>n*Gd^d_d_ejZAGd`d)d)ej-eAdd>Z>dadbZBdcd+ZCeed r,ejDZDn*ej dddedeZEGdfd d ejeEedgZDdhdiZFGdjdkdkeZGeFdlrGdmdldleje1eGejHdnZHeFdorGdpdodoeHe2eje1e4e2feGejIdnZIeFdqrGdrdqdqeje1eGejJdnZJeFdsrGdtdsdseJe1eGejKdnZKeed#r,ejLZLnLe rVGdud#d#ejMejNe.eGejMdnZLn"Gdvd#d#ejMejNe.eGejMdnZLeed!rejOZOnBeedwrGdxd!d!eje1eGejPdnZOnGdyd!d!eje1ZOeedzrejQZQe$'dznReed{r"Gd|dzdzeje1eGejRdnZQe$'dznej ddd}kr>eSd~eed$rRejTZTnTe rGdd$d$ejUejVe/e0feGejUdnZTn&Gdd$d$ejUejVe/e0feGejUdnZTeed"rejWZWnd2ej ddkrdkr$nnDe dZXGdddejZYGdd"d"ejWejZe.e[feYejWdnZWnTe rRGdd"d"ejWejZe.e[feGejWdnZWn&Gdd"d"ejWejZe.e[feGejWdnZWeedrej\Z\e$'dnjeed re rGdddej\ejVe/e0feGej\dnZ\n&Gdddej\ejVe/e0feGej\dnZ\e$'deFd r2GdddeKe1eje1e4feGej]dnZ]eed* rFej^Z^ndd*Z^eed, rbej_Z_ne`Z_eed- rzejaZandZaddZbe rddZddldddqdsdddddd!dzg ZcddZdddZeeed3 rejfZfne( r,e s,GdddeZgGdd3d3egdZfefjhdk rjefjhjie r dnddef_hn>e rjddlmZmjZjmkZkGdddejlZgGdd3d3egdZfeed5 r~ejmZmne( rdd5Zme( remZneed& rejoZone( remGdd&d&efZoej dddk rejpZpnTddZqddZrder_sddddZtdet_sGdddeZueud%evfiZpewep_xdep_heed1 rTejyZyejzZzej{Z{npe rGdddejjdd:Z{Gdd1d1ZyddZ|ddd0Zzn2e% rddZ}GdddejZ~Gdd1d1e~dZyej dddk rejZejZn"e rddlmjZjdd/Zdd.ZeedŃ rejZnej dddk rTGddDŽdej8dd:ZeddńZnej dddMk rGddDŽdej8dd:ZedddQZnheed7 rGdd̄dejZGdd΄dej*edd>Zedd:Zn&Gdd̄dejZGddńdedd>ZdS)N)GenericCallableTypeVarTuple)rr) GenericMeta TypingMetaF) _type_vars _next_in_mro _type_checkT _subs_tree) _tp_cachecCs|SNxrrB/opt/alt/python38/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)ZdctZ dict_copyZslotrrr_no_slots_copy4s  rcCsX|jstdt|t|}t|j}||krTtd||kr@dndt|||fdS)Nz%s is not a generic classz0Too %s parameters for %s; actual %s, expected %sZmanyZfew)__parameters__ TypeErrorreprlen)cls parametersZalenZelenrrr_check_generic<s r& _generic_newcOs|j|f||Sr)__new__)Zbase_clsr$argskwargsrrrr'Vs_geqv)r+)rcGsN|j}|D]>}|D],}||jkr|j|dkr:tSq qtSq dS)NT)__mro____dict__NotImplemented)CmethodsmromethodBrrr_check_methods_in_mroes   r6ClassVarFinalTypeContextManagerCounterDeque DefaultDict TypedDict SupportsIndexfinalIntVarLiteralNewTypeoverloadText 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().rUrWr$rrr__subclasscheck__sz_NoReturn.__subclasscheck__N)rrr__doc__rrYr\rrrrrRs rR_rootcs2eZdZdZd fdd ZddZddZZS) _NoReturnMetazMetaclass for NoReturnFcstj|||||dSNr^)superr()r$namebases namespacer_ __class__rrr(sz_NoReturnMeta.__new__cCs tddSrTrUrVrrrrYsz_NoReturnMeta.__instancecheck__cCs tddSrZrUr[rrrr\sz_NoReturnMeta.__subclasscheck__)F)rrrr]r(rYr\ __classcell__rrrfrr`sr`c@seZdZdZdZdS)rPrSrNrrrr]rrrrrrPs ) metaclassr_TKTVTT_co) covariantV_coVT_coT_contra)Z 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 ||_dSrrurWtpkwdsrrr__init__sz_ClassVar.__init__c CsRt|}|jdkr6|t|d|jddddStd|jdddSN{} accepts only single type.Tr^ {} cannot be further subscriptedtypervtypingr formatrr!rWitemr$rrr __getitem__s  z_ClassVar.__getitem__cCs.t|j||}||jkr|St||ddSNTr^r _eval_typervrrWglobalnslocalnsZnew_tprrrr s z_ClassVar._eval_typecs.t}|jdk r*|dt|j7}|SN[{}]rb__repr__rvrr _type_reprrWrrfrrrs  z_ClassVar.__repr__cCstt|j|jfSrhashrrrvrWrrr__hash__sz_ClassVar.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr) isinstancersr0rvrWotherrrr__eq__s    z_ClassVar.__eq__)N rrrr]rrzrrrrrrhrrrfrrss   rscs^eZdZdZdfdd ZddZdd Zd d Zd d ZfddZ ddZ ddZ Z S) _ClassVarMetazMetaclass for ClassVarNFcs(tj|||||d}|dk r$||_|Srarbr(rvr$rcrdrerxr_rWrfrrr(%sz_ClassVarMeta.__new__cCs tddS)Nz*ClassVar cannot be used with isinstance().rUrVrrrrY+sz_ClassVarMeta.__instancecheck__cCs tddS)Nz*ClassVar cannot be used with issubclass().rUr[rrrr\.sz_ClassVarMeta.__subclasscheck__cCsbt|}|jdk r*td|jddt|d|jdd}||j|jt|j |ddSNr~r}r|Trxr_ rrvr!rrrr __bases__rr/rWrr$Zparamrrrr1s   z_ClassVarMeta.__getitem__cCs@t|j||}||jkr|St||j|jt|j|jddSNTrrrrvrrrrr/rrrrr=s z_ClassVarMeta._eval_typecs.t}|jdk r*|dt|j7}|SrrrrfrrrEs  z_ClassVarMeta.__repr__cCstt|j|jfSrrrrrrrKsz_ClassVarMeta.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rr7r0rvrrrrrNs    z_ClassVarMeta.__eq__)NF rrrr]r(rYr\rrrrrrhrrrfrr"s  rc@seZdZdZdZdS)r7rtNrrrr]rvrrrrr7Us)rrc@seZdZddZddZdS) _FinalFormcCs d|jSNztyping_extensions._namerrrrrnsz_FinalForm.__repr__cCs t|d|j}t||fS)Nz{} accepts only single type)rr rr _GenericAlias)rWr%rrrrrqs z_FinalForm.__getitem__NrrrrrrrrrrlsraWA 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. ruNcKs ||_dSrrurwrrrrzsz_Final.__init__c CsRt|}|jdkr6|t|d|jddddStd|jdddSr{rrrrrrs  z_Final.__getitem__cCs.t|j||}||jkr|St||ddSrrrrrrrs z_Final._eval_typecs.t}|jdk r*|dt|j7}|Srrrrfrrrs  z_Final.__repr__cCstt|j|jfSrrrrrrrsz_Final.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rrr0rvrrrrrs    z _Final.__eq__)Nrrrrfrrs   rcs^eZdZdZdfdd ZddZdd Zd d Zd d ZfddZ ddZ ddZ Z S) _FinalMetazMetaclass for FinalNFcs(tj|||||d}|dk r$||_|Srarrrfrrr(sz_FinalMeta.__new__cCs tddS)Nz'Final cannot be used with isinstance().rUrVrrrrYsz_FinalMeta.__instancecheck__cCs tddS)Nz'Final cannot be used with issubclass().rUr[rrrr\sz_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}|Srrrrfrrrs  z_FinalMeta.__repr__cCstt|j|jfSrrrrrrrsz_FinalMeta.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rr8r0rvrrrrrs    z_FinalMeta.__eq__)NFrrrrfrrs  rc@seZdZdZdZdS)r8rNrrrrrr8scCs|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)frrrr@scCst|Sr)rrcrrrrAsc@seZdZddZddZdS) _LiteralFormcCs d|jSrrrrrrr$sz_LiteralForm.__repr__cCs t||SrrrWr%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)rWvaluesryrrrrzHsz_Literal.__init__cCsJt|}|jdkr.t|ts"|f}||ddStd|jdddS)NTr^r~r})rrrtupler!rr)rWrr$rrrrKs    z_Literal.__getitem__cCs|SrrrWrrrrrrTsz_Literal._eval_typecs6t}|jdk r2|ddttj|j7}|SNr, rbrrrjoinmaprrrrfrrrWs  z_Literal.__repr__cCstt|j|jfSrrrrrrrrrr]sz_Literal.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rrr0rrrrrr`s    z_Literal.__eq__)Nrrrrfrr8s    rcs^eZdZdZdfdd ZddZdd Zd d Zd d ZfddZ ddZ ddZ Z S) _LiteralMetazMetaclass for LiteralNFcs(tj|||||d}|dk r$||_|Sra)rbr(r)r$rcrdrerr_rWrfrrr(lsz_LiteralMeta.__new__cCs tddS)Nz)Literal cannot be used with isinstance().rUrVrrrrYrsz_LiteralMeta.__instancecheck__cCs tddS)Nz)Literal cannot be used with issubclass().rUr[rrrr\usz_LiteralMeta.__subclasscheck__cCsVt|}|jdk r*td|jddt|ts:|f}||j|jt|j |ddS)Nr~r}T)rr_) rrr!rrrrrrr/rrrrrxs    z_LiteralMeta.__getitem__cCs|Srrrrrrrsz_LiteralMeta._eval_typecs6t}|jdk r2|ddttj|j7}|Srrrrfrrrs  z_LiteralMeta.__repr__cCstt|j|jfSrrrrrrrsz_LiteralMeta.__hash__cCs,t|tstS|jdk r$|j|jkS||kSr)rrBr0rrrrrrs    z_LiteralMeta.__eq__)NFrrrrfrris  rc@seZdZdZdZdS)rBrN)rrrr]rrrrrrBs 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)ryrrr_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)funcrrrrDsCT_co)roZboundc@seZdZdZdZdS)r9aA 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. rNrirrrrr9s)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)rrLrrKr}rabc functoolsCParameterized generics cannot be used with class or instance checksFT)sys version_info __origin__ _getframe f_globalsr! __extra__rbr\__subclasshook__r0r.__subclasses__rr issubclass)rWsubclassresZsclsrfrrr\s$$      z(_ExtensionsGenericMeta.__subclasscheck__)rrrr\rhrrrfrrsr Awaitablec@seZdZdZdS)rrNrrrrrrrrr!s)rjr Coroutinec@seZdZdZdS)rrNrrrrrr's AsyncIterablec@seZdZdZdS)rrNrrrrrr.s AsyncIteratorc@seZdZdZdS)rrNrrrrrr5sc@seZdZdZddZdS)r<rcOs*t|trtj||Sttj|f||Sr)r+r< collectionsdequer'r$r)ryrrrr(Cs   Deque.__new__Nrrrrr(rrrrr<>sc@seZdZdZddZdS)r<rcOs*|jtkrtj||Sttj|f||Sr)_gorgr<rrr'rrrrr(Ms  rNrrrrrr<HsAbstractContextManagerc@seZdZdZdS)r:rNrrrrrr:Vsc@s2eZdZdZddZejddZeddZ dS) r:rcCs|Srrrrrr __enter__^szContextManager.__enter__cCsdSrr)rWexc_type exc_value tracebackrrr__exit__aszContextManager.__exit__cCs8|tkr4tdd|jDr4tdd|jDr4dStS)Ncss|]}d|jkVqdS)rNr/.0r5rrr msz2ContextManager.__subclasshook__..css|]}d|jkVqdS)rNrrrrrrnsT)r:anyr.r0)r$r1rrrres zContextManager.__subclasshook__N) rrrrrrabstractmethodr classmethodrrrrrr:[s  AsyncContextManagerAbstractAsyncContextManagerc@seZdZdZdS)rrNrrrrrrws)rrLa 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)r=rcOs*t|trtj||Sttj|f||Sr)r+r=r defaultdictr'rrrrr(s  DefaultDict.__new__Nrrrrrr=sc@seZdZdZddZdS)r=rcOs*|jtkrtj||Sttj|f||Sr)rr=rrr'rrrrr(s  rNrrrrrr=s)rrLr}_TIntcs eZdZdZfddZZS) _CounterMetazMetaclass for Countercst|tfSr)rbrint)rWrrfrrrsz_CounterMeta.__getitem__)rrrr]rrhrrrfrrsrc@seZdZdZddZdS)r;rcOs*t|trtj||Sttj|f||Srr+r;rr'rrrrr(s  Counter.__new__Nrrrrrr;sc@seZdZdZddZdS)r;rcOs*t|trtj||Sttj|f||Srrrrrrr(s  rNrrrrrr;sc@seZdZdZddZdS)r;rcOs*|jtkrtj||Sttj|f||Sr)rr;rr'rrrrr(s  rNrrrrrr;sChainMapc@seZdZdZddZdS)rrcOs*t|trtj||Sttj|f||Sr)r+rrr'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_typeszNewType..new_type)rZ __supertype__)rcrxrrrrrCscCs&t|dr|jS|jdk r"|j}q|S)@This function exists for compatibility with old typing versions.rN)rrrr$rrrr.s   rcCsHt}t|jddD],\}}t|trt|tkr|j|d}q|S)rNr})object enumerater.rrrr)r$Z next_in_mroicrrrr 9s r rIterableIteratorHashableSized Container Collection ReversiblecCsrt}|jddD]X}|jdkr$qt|di}t|jt|D] }|dsJ|dkrJ||qJq|S)Nr)rMr__annotations___abc_)__abstractmethods__r __weakref__ _is_protocol_is_runtime_protocolr/__args__r__next_in_mro__r r__orig_bases__r __tree_hash__r]rrzr(r_MutableMapping__markerr) setr.rrlistr/keys startswithadd)r$Zattrsbase annotationsattrrrr_get_protocol_attrsHs  r'cstfddtDS)Nc3s|]}tt|dVqdSr)callablerrr&rrrr\sz,_is_callable_members_only..)allr'rrrr_is_callable_members_only[sr+csZeZdZdZesd 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 s|dk r nt|}d} |D]B} | tkr.tdt| tr| jttfkr| dk rVtd| j} q| dkrl|} nht|} t| | kstdd fdd|Dt dd|Drdnd d d d| Df| }|} |dk rt |t j kr||kr|f|}td d|D}t d d|Dr>td d|D}|||dtt|j||||dd} tt| d|s~| nt||| _|rtdd|Dnd| _t| | _|dkr| | _n|dk r|j| _|j| _t| dr|rt| n tt| | _| S)N!Cannot inherit from plain GenericzACannot inherit from Generic[...] or Protocol[...] multiple times.z1Some type variables (%s) are not listed in %s[%s]rc3s|]}|krt|VqdSrstrrtgvarsetrrrsz(_ProtocolMeta.__new__..css|]}|jtkVqdSr)rrrbrrrrsrrMcss|]}t|VqdSrr.rgrrrrscss$|]}t|trt|n|VqdSr)rrrr4rrrrscss |]}t|to|tk VqdSr)rrrr4rrrrscss|]}|tk r|VqdSr)rr4rrrrs)rrTr^rcss*|]"}|tkrdn|tkrdn|VqdS).rNrrarrrrs  r)r rr!rrrrMr rrrrrABCMetarupdaterbr( __setattr__rrr rr _abc_registry _abc_cacherrrrr)r$rcrdretvarsr)originr orig_basesgvarsr$tvarsetZ initial_basesrWrfr2rr(is            z_ProtocolMeta.__new__cstj||jdds2tddjD_jrjddD]T}|tt fksF|j dkrj|j t ksFt |trz|jsFt |tr|jt ksFtd|qFdd}|_fd d }d jkr|_dS) Nrcss*|]"}|tkp t|to |jtkVqdSr)rMrr,rr4rrrrs z)_ProtocolMeta.__init__..r}collections.abc7Protocols can only inherit from other protocols, got %rc_st|jrtddSNz Protocols cannot be instantiatedrrr!rWr)r*rrr_no_inits z(_ProtocolMeta.__init__.._no_initcsjddstSt|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 classrT) r/getr0rrr!r'r.rrMappingr,rrr&r$r%rrr _proto_hooks*        z+_ProtocolMeta.__init__.._proto_hookr)rbrzr/rKrrrr.r rrr_PROTO_WHITELISTrr rrr!r)r$r)r*r$rIrNrfrrrzs8    z_ProtocolMeta.__init__csZtddrtr$tjr$dSjrJtfddtDrJdStt S)NrFTc3s8|]0}t|o.tt|d p.t|dk VqdSrrr(rr)instancerWrrrs 2_ProtocolMeta.__instancecheck__..) rr+rrgrr*r'rbrrY)rWrRrfrQrrYs  _ProtocolMeta.__instancecheck__cs|jdk r*tdjddkr&tddS|jddrf|jddsftdjddkr^dStd |jddrt|stdjddkrtt | |Std tt | |S) Nr}rrrFrrrrrBInstance and class checks can only be used with @runtime protocols.css|]}t|tVqdSrrrrZrrrr sz0Parameters to %r[...] must all be type variablesz(Parameters to %r[...] must all be uniquez'Cannot subscript already-subscripted %sr)r?r)r@rrA)rrrrr!rrrMr*r#rrr rr"r&rgrrrr/rr)rWparamsr?r)Zprependrr\rrsN    z_ProtocolMeta.__getitem__)NNNNN) rrrr] OLD_GENERICSr(rzrYr\rrrhrrrfrr,bsA /  r,c@s eZdZdZdZdZddZdS)rMaBase 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)rrMr!r`r'r rrrrrr(Js  Protocol.__new__N)rrrr]rrr(rrrrrM*s)rjzProtocol, Generic[T]z Protocol[T])rd)r r_collect_type_varscseZdZfddZZS)r,csVtddrtr$tjr$dSjrJtfddtDrJdStS)NrFTc3s8|]0}t|o.tt|d p.t|dk VqdSrrPr)r$rRrrrds rS) rr+rrgrr*r'rbrYrcrfrcrrY\s  rT)rrrrYrhrrrfrr,Yscs<eZdZdZdZdZfddZeddZdd Z Z S) rMaBase 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)rMr!rbr(rrfrrr(sracst|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 emptyrXc3s|]}t|VqdSrrYrZr\rrrsz-Protocol.__class_getitem__..css|]}t|tVqdSrr^rZrrrrsrr}zJParameters to Protocol[...] must all be type variables. Parameter {} is {}z.Parameters to Protocol[...] must all be unique) rrrr!rrrMr*rr#rr&r)r$r_r rr\r__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\dd} | _dS)Nrr-rrMzECannot inherit from Generic[...] and/or Protocol[...] multiple types.rc3s|]}|krt|VqdSrr.r0r2rrrsz-Protocol.__init_subclass__..css|]}t|VqdSrr.r6rrrrsz1Some type variables ({}) are not listed in {}[{}]rcss|]}|tkVqdSr)rMr4rrrrscsjddstStdds>tdjddkr6tStdtsftdjddkr^tStdt |t sxtd t D]t}|j D]`}||jkr|j|dkrtSqt|d i}t |t jr||krt |tr|jrqqtSqd S) NrrFr,rrrVrWrJrT)r/rKr0rrrrr!r+rrr'r.rrLr,rrMrrrrNs:         z/Protocol.__init_subclass__.._proto_hookrrDrEc_st|jrtddSrFrGrHrrrrI s z,Protocol.__init_subclass__.._no_init)r/rrrr!rbrrrrMr rrrrrKrrrr rrrOr,rz) r$r)r*r?errorrBr$Zthe_baserCZs_varsZs_argsrNrIr)r$r3r__init_subclass__sn             zProtocol.__init_subclass__) rrrr]rrr(rrdrfrhrrrfrrMks  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)rr,rr!rrrrrrOs c@s$eZdZdZejedddZdS)r?r)returncCsdSrrrrrr __index__.szSupportsIndex.__index__N)rrrrrrrrhrrrrr?*s)r c Cs>z tdjddkrtdWnttfk r8YnXdS)Nr}rrUz4TypedDict does not support instance and class checksF)rrrr!AttributeError ValueError)r$rrrr _check_fails8s  rlcOs,|s td|d|dd}}t||S)N)TypedDict.__new__(): not enough argumentsrr})r!r)r)r*_rrr _dict_newCsroz,($cls, _typename, _fields=None, /, **kwargs))totalc OsX|s td|d|dd}}|r>|d|dd}}n4d|krj|d}ddl}|jdtddntd|rz |\}Wqtk rtd t|dYqXnr(rz?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typecsi|]\}}|t|qSr)rr )rnrxr\rr sz*_TypedDictMeta.__new__..__required_keys__r__optional_keys__rs)r{rorbrxr(rrKrr!itemsr;r/r frozensetr~rrrs) r$rcrdrzrpZtp_dictr%Zown_annotationsZown_annotation_keysZ required_keysZ optional_keysr$rfr\rr({s2         z_TypedDictMeta.__new__)T)rrrr(rlrYr\rhrrrfrrxzs&rxaA 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__rrbrz)rWr@metadatarfrrrzs   z_AnnotatedAlias.__init__cCs|d}t||jS)Nr)rr)rWr_rrrr copy_withsz_AnnotatedAlias.copy_withcCs&dt|jddd|jDS)Nz#typing_extensions.Annotated[{}, {}]rcss|]}t|VqdSrr"r8rrrrsz+_AnnotatedAlias.__repr__..)rrrrrrrrrrrs z_AnnotatedAlias.__repr__cCstjt|jf|jffSr)operatorgetitemrJrrrrrr __reduce__s z_AnnotatedAlias.__reduce__cCs*t|tstS|j|jkrdS|j|jkS)NF)rrr0rrrrrrrs   z_AnnotatedAlias.__eq__cCst|j|jfSr)rrrrrrrrsz_AnnotatedAlias.__hash__) rrrr]rzrrrrrrhrrrfrrs rc@s0eZdZdZdZddZeddZddZd S) rJaAdd 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.rUr$r)r*rrrr(szAnnotated.__new__cCsLt|trt|dkrtdd}t|d|}t|dd}t||S)Nr,zUAnnotated[...] 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$r_r]r@rrrrrds zAnnotated.__class_getitem__cOstd|jdS)NzCannot subclass {}.Annotated)r!rrrrrrrf&s zAnnotated.__init_subclass__N) rrrr]rr(rrdrfrrrrrJs   cCs\t|trt|jSt|tjrXtdd|jD}||jkrB|S||}|j |_ |S|S)z2Strips the annotations from a given type. css|]}t|VqdSr_strip_annotationsr8rrrr1sz%_strip_annotations..) rrrrrrrrrZ_special)r1Z stripped_argsrrrrr+s     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)rkr1rrrr}[sz"get_type_hints..)rrIr)rXrrZinclude_extrasZhintrrrrI9scCs t|dko|do|dS)z3Returns True if name is a __dunder_variable_name__.__)r#r"endswithrrrr _is_dunder_srcseZdZdZfddZeddZddZdfd d Zd d Z e fd dZ ddZ ddZ fddZddZddZZS) AnnotatedMetazMetaclass for Annotatedc s8tdd|Dr"tdtttj||||f|S)Ncss|]}|tk VqdSr)r r4rrrrksz(AnnotatedMeta.__new__..zCannot subclass )rr!r/rJrbr()r$rcrdrer*rfrrr(jszAnnotatedMeta.__new__cCs |dS)Nr,r rrrrroszAnnotatedMeta.__metadata__cCsP|\}}}t|ts t|}n|d|}ddd|D}d|||fS)Nrrcss|]}t|VqdSrr)rargrrrrysz+AnnotatedMeta._tree_repr..z %s[%s, %s])rrrr _tree_reprr)rWtreer$r@rZtp_reprZmetadata_reprsrrrrss    zAnnotatedMeta._tree_reprNcsh|tkr tStj||d}t|dtrd|ddtkrd|dd}|dd}t|||dfS|S)N)r?r)r}rr,)rJrbrrr)rWr?r)rZsub_tpZ sub_annotrfrrr|s  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!rrrrJ)rWrrrr _get_conss   zAnnotatedMeta._get_conscst|ts|f}|jdk r&t|St|trrlro__text_signature__r{rxrrrrJrIrrrrrHrGrrrrrrrrs        '           5 3   4 3   / -                 &                   I'  &   ,) )6 $b"