U ʗRe&5@s2 ddlZddlZddlZddlZddlZddlZddlZddlZdddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6g5Z d7Z e Z e Zefd8d9Zejd:krd;d<Znejd=krd>d<Znd?d<Zdd@dAZejZedBZedCZedDZejdEd7dFZejdGd7dHZejZeedrpejddIdJkrpejZn"GdKdLdLejd7dMZeddNdOZejdPkrejZndQd"ZdRd&Z eed(rej!Z!n"GdSdTdTejd7dMZ"e"d(dUdOZ!ej#Z#eed!rej$Z$ej%Z%ej&Z&n,e'e(ej'e)Z*dVd*Z$dWd!Z%dXdZ&ej+Z+ej,Z,ej-Z-ej.Z.ej/Z/ej0Z0ej1Z1ej2Z2ej3Z3eedrej4Z4ne5ej4eefZ4ej6Z6ej7Z7ej8Z8ej9Z9ej:Z:ej;Z;dYd dZd[ddd\d]d^d_d`ddg ZdedfZ?eed+rej@Z@n,dgdhZAGdidjdjejBZCGdkd+d+eCdlZ@eed.rHejDZDndmd.ZDeDZEeedrhejFZFneDGdndde@ZFeed5rejGZGejHZHejIZInzdodpZJdqdrZKdseK_Ld7dtdudvZMdweM_LGdxdydye ZHeHde)fiZGeNeG_OdzeG_PeedyrejHeHfZQneHfZQd{d'ZIeedr*ejRZRnd|dZReed5rFejSZSn"ddlZddlZd}d~ZTddd%ZSeedrejUZUejVZVn$GdddejWd7dMZVGdddZUejddId:krejXZXejYZYnlzddlmZZZWne[k rejWZZYnXzddlm\Z]Wne[k r"ejWZ]YnXdd$ZXdd#ZYeed0rHej^Z^nZejddId=krGdddejd7dMZ_e_dd0Z^n"Gdddejd7dMZ_e_d0ddOZ^eedrej`Z`ejaZan.GdddZbGdddebZ`GdddebZaeedrejcZcnGdddedZceeds*GdddedZeejfddZgeedrRejhZhejeZenDejddId=krte_ddZhn"Gdddejd7dMZieidddOZheed1rejjZjnZejddId=krGdddejd7dMZkekdd1Zjn"Gdddejd7dMZkekd1ddOZjGdddejld7dMZeedr.ejmZmn eddZmeed rNejnZnn edd Zneed3rnejoZon edd3Zoeed5rejpZpejqZqnrejddId=krGdddejd7dMZrerdd5Zperdd6Zqn.Gdddejd7dMZsesd5ddOZpesd6ddOZqeed rejtZtnejddId=krpGdddejd7dMZuGdddejWd7dMZveudd ZtddZwn@GdddejWd7dMZvGdddejd7dMZxexd ddOZtddZweed rejyZynGdd d Zyeed,rejzZzneeddd,Zzeed r ej{Z{neoeodddZ{eed  r.ej|Z|nZd7dddde}e}e}ej~ejej+ejejdejffdfejejegefddd Z|eed  see_ee_ejdPk rejZnzddÄZdddńZejZedddhZGddʄde ZdddZejjPe_Pe eddiZejdk r de_LddτZee_dS)NClassVar ConcatenateFinal LiteralString ParamSpec ParamSpecArgsParamSpecKwargsSelfType TypeVarTupleUnpack Awaitable AsyncIterator AsyncIterable CoroutineAsyncGeneratorAsyncContextManagerChainMapContextManagerCounterDeque DefaultDict NamedTuple OrderedDict TypedDict SupportsIndex Annotated assert_never assert_typeclear_overloadsdataclass_transform get_overloadsfinalget_args get_originget_type_hintsIntVar is_typeddictLiteralNewTypeoverloadProtocol reveal_typeruntimeruntime_checkableText TypeAlias TypeGuard TYPE_CHECKINGNeverNoReturnRequired NotRequiredTc Cs|st|d|tkrBt|dr*|js8t|dt|j}t|}||krt|drdd|jD}tdd|D}|dkr|||krdStd ||krd nd d |d |d|dS)zCheck correct count for parameters of a generic cls (internal helper). This gives a nice error message in case of count mismatch. z is not a generic class__parameters__cSsg|]}t|s|qS) _is_unpack.0pr8r8/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/typing_extensions.py dsz"_check_generic..css|]}t|tVqdSN) isinstancer r:r8r8r= esz!_check_generic..rNzToo manyfewz parameters for z ; actual z , expected ) TypeError_markerhasattrr7lensum)cls parameterselenalenZ num_tv_tuplesr8r8r=_check_genericWs  rM) cCst|tjtjtjfSr?)r@typing _GenericAlias_types GenericAlias UnionTypetr8r8r=_should_collect_from_parametersmsrWrN cCst|tjtjfSr?)r@rPrQrRrSrUr8r8r=rWrscCst|tjo|j Sr?)r@rPrQ_specialrUr8r8r=rWuscsj|dkrtj}g|D]J}t||r>|kr>t|s>|t|rfdd|jDqtS)zCollect all type variable contained in types in order of first appearance (lexicographic order). For example:: _collect_type_vars((T, List[S, T])) == (T, S) Ncsg|]}|kr|qSr8r8r;rVtvarsr8r=r>sz&_collect_type_vars..) rPTypeVarr@r9appendrWextendr7tuple)typesZ typevar_typesrVr8r\r=_collect_type_varsys rcTKTVTT_co) covariantT_contra) contravariant)rNc@seZdZddZddZdS) _FinalFormcCs d|jSNztyping_extensions._nameselfr8r8r=__repr__sz_FinalForm.__repr__cCs"t||jd}t||fSN accepts only a single type.rP _type_checkrprQrrrJitemr8r8r= __getitem__s z_FinalForm.__getitem__N__name__ __module__ __qualname__rsrzr8r8r8r=rmsrm)_rootaWA 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.)doc)rN c Cs(z d|_Wnttfk r"YnX|S)aThis 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. The decorator sets the ``__final__`` attribute to ``True`` on the decorated object to allow runtime introspection. T)Z __final__AttributeErrorrD)fr8r8r=r"s  cCs t|Sr?)rPr^)namer8r8r=r&sc@seZdZddZddZdS) _LiteralFormcCs d|jSrnrorqr8r8r=rssz_LiteralForm.__repr__cCs t||Sr?)rPrQrrrJr8r8r=rzsz_LiteralForm.__getitem__Nr{r8r8r8r=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.cCsBt|d|}z|t|j|j|jj<Wntk r<YnXtS)aDecorator 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 The overloads for a function can be retrieved at runtime using the get_overloads() function. __func__)getattr_overload_registryr}r~__code__co_firstlinenor_overload_dummy)funcrr8r8r=r* s cCsDt|d|}|jtkrgSt|j}|j|kr2gSt||jS)z6Return all defined overloads for *func* as a sequence.r)rr}rr~listvalues)rrmod_dictr8r8r=r!4s    cCs tdS)z$Clear all overloads in the registry.N)rclearr8r8r8r=r?sCallableIterableIteratorHashableSized Container Collection ReversiblecCsrt}|jddD]X}|jdkr$qt|di}t|jt|D] }|dsJ|dkrJ||qJq|S)N)r+Generic__annotations___abc_)__abstractmethods__r __weakref__ _is_protocol_is_runtime_protocol__dict____args__ __slots__Z__next_in_mro__r7 __origin____orig_bases__Z __extra__Z __tree_hash____doc____subclasshook____init____new__r}_MutableMapping__markerZ_gorg) set__mro__r|rrrkeys startswithadd)rIattrsbase annotationsattrr8r8r=_get_protocol_attrsis  rcstfddtDS)Nc3s|]}tt|dVqdSr?)callablerr;rrIr8r=rA}sz,_is_callable_members_only..)allrrr8rr=_is_callable_members_only|srcsg}d|jkrt|j}d}|jD]>}t|tjr$|jtjtfkr$|jj }|dk r\t d|j }q$|dkrr|}ndt |}t ||ksd fdd|D}d dd|D}t d|d |d |d |}t||_ dS) zHelper function used in Protocol.__init_subclass__ and _TypedDictMeta.__new__. The contents of this function are very similar to logic found in typing.Generic.__init_subclass__ on the CPython main branch. rNzECannot inherit from Generic[...] and/or Protocol[...] multiple types., c3s|]}|krt|VqdSr?strr[gvarsetr8r=rAsz+_maybe_adjust_parameters..css|]}t|VqdSr?r)r;gr8r8r=rAszSome type variables (z) are not listed in [])rrPrcrr@rQrrr+r|rDr7rjoinra)rIr]gvarsrZthe_basetvarsets_varss_argsr8rr=_maybe_adjust_parameterss0    rcOst|jrtddS)Nz Protocols cannot be instantiated)typerrDrrargskwargsr8r8r=_no_inits rcseZdZfddZZS) _ProtocolMetacsVtddrtr$tjr$dSjrJtfddtDrJdStS)NrFTc3s8|]0}t|o.tt|d p.t|dk VqdSr?)rFrrrrIinstancer8r=rAs z2_ProtocolMeta.__instancecheck__..) rr issubclass __class__rrrsuper__instancecheck__rrrr=rs  z_ProtocolMeta.__instancecheck__)r|r}r~r __classcell__r8r8rr=rsrcs>eZdZdZdZdZfddZejddZ dd Z Z S) r+aBase 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: ... r8Tcs|tkrtdt|S)NzIType Protocol cannot be instantiated; it can only be used as a base class)r+rDrr)rIrkwdsrr8r=rszProtocol.__new__cst|ts|f}|s0|tjk r0td|jddtfdd|D}|tkrtdd|Dsd}t||tjr|d7}qhtd |dd ||t t |t |krtd nt ||t |j t ||S) NzParameter list to z[...] cannot be emptyz*Parameters to generic types must be types.c3s|]}t|VqdSr?rPrwr:msgr8r=rAsz-Protocol.__class_getitem__..css|]}t|tjVqdSr?)r@rPr^r:r8r8r=rAsrzBParameters to Protocol[...] must all be type variables. Parameter z is z.Parameters to Protocol[...] must all be unique)r@rarPTuplerDr~r+rr^rGrrMr7rQ)rIparamsir8rr=__class_getitem__s,   zProtocol.__class_getitem__csdjkrtjjk}n tjjk}|r0tdtjdds\tddjD_ fdd}djkrx|_ j sdSjD]H}|t tjfks|j d kr|j tkst|tr|j std t|qt_dS) Nrz!Cannot inherit from plain Genericrcss|]}|tkVqdSr?)r+)r;br8r8r=rAsz-Protocol.__init_subclass__..csjddstStdds>tdjddkr6tStdtsftdjddkr^tStdt |t sxtd t D]t}|j D]`}||jkr|j|dkrtSqt|d i}t |t jr||krt |tr|jrqqtSqd S) NrrFrkr|)abc functoolszBInstance and class checks can only be used with @runtime protocolsz._proto_hookrzcollections.abcz5Protocols can only inherit from other protocols, got )rrPrr __bases__rDrranyrrobjectr}r|_PROTO_WHITELISTr@rreprrr)rIrrerrorrrr8rr=__init_subclass__s2     zProtocol.__init_subclass__) r|r}r~rrrrrP _tp_cacherrrr8r8rr=r+s  ) metaclasscCs(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)r@rrrDrrr8r8r=r.Ksc@s$eZdZdZejedddZdS)rr8)returncCsdSr?r8rqr8r8r= __index__gszSupportsIndex.__index__N)r|r}r~rrabstractmethodintrr8r8r8r=rcsc Cs>z tdjddkrtdWnttfk r8YnXdS)Nrr|)rrrPz4TypedDict does not support instance and class checksF)rrrrDr ValueError)rIrr8r8r= _check_failsxs  rcOs,|s td|d|dd}}t||S)N)TypedDict.__new__(): not enough argumentsrr)rDdict)rr_r8r8r= _dict_newsrz,($cls, _typename, _fields=None, /, **kwargs)totalc Os\|s td|d|dd}}|r>|d|dd}}n4d|krj|d}ddl}|jdtddntd|rz |\}Wqtk rtd t|dd YqXn.rz?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typecsi|]\}}|t|qSr8r)r;ntprr8r= sz*_TypedDictMeta.__new__..__required_keys__r8__optional_keys__r __total__)r rrrrrrPrrrritemsrupdaterr$rr#r5rr6r frozensetrrrFr)rIrr r rtp_dictrZown_annotationsZ required_keysZ optional_keysrZannotation_keyZannotation_typeZannotation_originZannotation_argsrrr=rsL              z_TypedDictMeta.__new__)T)T) r|r}r~rrrr__subclasscheck__rr8r8rr=rs9raA 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+ cCst|ttS)aCheck if an annotation is a TypedDict class For example:: class Film(TypedDict): title: str year: int is_typeddict(Film) # => True is_typeddict(Union[list, str]) # => False )r@ra_TYPEDDICT_TYPESrr8r8r=r's cCs|S)aAssert (to the type checker) that the value is of the given type. When the type checker encounters a call to assert_type(), it emits an error if the value is not of the specified type:: def greet(name: str) -> None: assert_type(name, str) # ok assert_type(name, int) # type checker error At runtime this returns the first argument unchanged and otherwise does nothing. r8)Z__valZ__typr8r8r=r0s cCst|trt|jSt|dr:|jttfkr:t|jdSt|tj rrt dd|jD}||jkrh|S| |Stt drt|t j rt dd|jD}||jkr|St |j|Stt drt|t jrt dd|jD}||jkr|Sttj|S|S) z=Strips Annotated, Required and NotRequired from a given type.rrcss|]}t|VqdSr? _strip_extrasr;ar8r8r=rANsz _strip_extras..rScss|]}t|VqdSr?rrr8r8r=rASsrTcss|]}t|VqdSr?rrr8r8r=rAXs)r@_AnnotatedAliasrrrFr5r6rrPrQra copy_withrbrSrTrreduceoperatoror_)rVZ stripped_argsr8r8r=rGs(       rFcCsHttdrtj|||dd}ntj|||d}|r6|Sdd|DS)aReturn 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, ...]', 'Required[T]' or 'NotRequired[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. rT)globalnslocalnsinclude_extras)r$r%cSsi|]\}}|t|qSr8r)r;krVr8r8r=rsz"get_type_hints..)rFrPr%r)objr$r%r&hintr8r8r=r%_s csHeZdZdZfddZddZddZdd Zd d Zd d Z Z S)raKRuntime 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?)r@r __metadata__rrr)rroriginmetadatarr8r=rs   z_AnnotatedAlias.__init__cCs$t|dkst|d}t||jS)Nrr)rGAssertionErrorrr*)rrrnew_typer8r8r=r sz_AnnotatedAlias.copy_withcCs,dt|jdddd|jDdS)Nztyping_extensions.Annotated[rcss|]}t|VqdSr?)rrr8r8r=rAsz+_AnnotatedAlias.__repr__..r)rP _type_reprrrr*rqr8r8r=rssz_AnnotatedAlias.__repr__cCstjt|jf|jffSr?)r"getitemrrr*rqr8r8r= __reduce__s z_AnnotatedAlias.__reduce__cCs*t|tstS|j|jkrdS|j|jkS)NF)r@rrrr*rrrr8r8r=__eq__s   z_AnnotatedAlias.__eq__cCst|j|jfSr?)hashrr*rqr8r8r=__hash__sz_AnnotatedAlias.__hash__) r|r}r~rrr rsr1r3r5rr8r8rr=rs rc@s2eZdZdZdZddZejddZddZ d S) raAdd 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()] r8cOs tddS)Nz&Type Annotated cannot be instantiated.rDrIrrr8r8r=rszAnnotated.__new__cCsnt|trt|dkrtdttf}t|d|kr@|d}nd}t|d|}t|dd}t ||S)NrkzUAnnotated[...] should be used with at least two arguments (a type and an annotation).rz$Annotated[t, ...]: t must be a type.r) r@rarGrDrrr$rPrwr)rIrZallowed_special_formsr+rr,r8r8r=rs zAnnotated.__class_getitem__cOstd|jddS)NCannot subclass z .Annotated)rDr}r7r8r8r=rs zAnnotated.__init_subclass__N) r|r}r~rrrrPrrrr8r8r8r=rs   )_BaseGenericAlias)rScCs>t|trtSt|tjttttfr*|j S|tj kr: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) r@rrrPrQ_typing_GenericAliasr9rrrrrr8r8r=r$s   cCszt|tr|jf|jSt|tjtfrvt|ddr8dS|j}t |t j j krr|dt k rrt|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) rZFr8rNr)r@rrr*rPrQr:rrr$ collectionsrrEllipsisr)rresr8r8r=r#s  c@seZdZddZdS)_TypeAliasFormcCs d|jSrnrorqr8r8r=rs;s_TypeAliasForm.__repr__Nr|r}r~rsr8r8r8r=r>:sr>cCst|ddS)a&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 subscriptableNr6rr8r8r=r0>s c@seZdZddZdS)r>cCs d|jSrnrorqr8r8r=rsNsr?Nr@r8r8r8r=r>MsaSpecial 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@s$eZdZdZdZddZddZdS) _Immutablez3Mixin to indicate that object should not be copied.r8cCs|Sr?r8rqr8r8r=__copy__hsz_Immutable.__copy__cCs|Sr?r8)rrmemor8r8r= __deepcopy__ksz_Immutable.__deepcopy__N)r|r}r~rrrCrEr8r8r8r=rBdsrBc@s(eZdZdZddZddZddZdS) 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 ||_dSr?rrrr+r8r8r=rzszParamSpecArgs.__init__cCs|jjdS)Nz.argsrr|rqr8r8r=rs}szParamSpecArgs.__repr__cCst|tstS|j|jkSr?)r@rrrr2r8r8r=r3s zParamSpecArgs.__eq__Nr|r}r~rrrsr3r8r8r8r=rns c@s(eZdZdZddZddZddZdS) 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 ||_dSr?rFrGr8r8r=rszParamSpecKwargs.__init__cCs|jjdS)Nz.kwargsrHrqr8r8r=rsszParamSpecKwargs.__repr__cCst|tstS|j|jkSr?)r@rrrr2r8r8r=r3s zParamSpecKwargs.__eq__NrIr8r8r8r=rs cspeZdZdZejZeddZeddZ ddddfd d Z d d Z d dZ ddZ ddZddZZS)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|Sr?)rrqr8r8r=rszParamSpec.argscCst|Sr?)rrqr8r8r=rszParamSpec.kwargsNF)boundrhrjc st|g||_t||_t||_|r.r)rPr/rrrrqr8r[r=rssz!_ConcatenateGenericAlias.__repr__cCst|j|jfSr?)r4rrrqr8r8r=r5sz!_ConcatenateGenericAlias.__hash__cOsdSr?r8rr8r8r=rWsz!_ConcatenateGenericAlias.__call__cCstdd|jDS)Ncss"|]}t|tjtfr|VqdSr?)r@rPr^r)r;rr8r8r=rA$sz:_ConcatenateGenericAlias.__parameters__..)rarrqr8r8r=r7"sz'_ConcatenateGenericAlias.__parameters__)r|r}r~rPrQrrZrrsr5rWrXr7rr8r8rr=rY s rYcsZ|dkrtdt|ts |f}t|dts6tddtfdd|D}t||S)Nr8z&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|VqdSr?rr:rr8r=rA4sz'_concatenate_getitem..)rDr@rarrYrr8rr=_concatenate_getitem*s r\cCs 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. r\rr8r8r=r>s c@seZdZddZddZdS)_ConcatenateFormcCs d|jSrnrorqr8r8r=rsNsz_ConcatenateForm.__repr__cCs t||Sr?r^rr8r8r=rzQsz_ConcatenateForm.__getitem__Nr{r8r8r8r=r_Msr_r]c@seZdZddZdS)_TypeGuardFormcCs d|jSrnrorqr8r8r=rsgs_TypeGuardForm.__repr__Nr@r8r8r8r=r`fsr`cCs 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). ru)rPrwrQrxr8r8r=r1js,c@seZdZddZddZdS)r`cCs d|jSrnrorqr8r8r=rssracCs"t||jd}t||fS)Nz accepts only a single typervrxr8r8r=rzs z_TypeGuardForm.__getitem__Nr{r8r8r8r=r`srbc@sneZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ejddZdS) _SpecialForm)rpr_getitemcCs||_|j|_|j|_dSr?)rdr|rpr)rrr0r8r8r=rsz_SpecialForm.__init__cCs|dkr|jSt|dS)N>r|r~)rpr)rrryr8r8r= __getattr__sz_SpecialForm.__getattr__cCstd|dS)Nr8r6)rrr r8r8r=__mro_entries__sz_SpecialForm.__mro_entries__cCs d|jSrnrorqr8r8r=rssz_SpecialForm.__repr__cCs|jSr?rorqr8r8r=r1sz_SpecialForm.__reduce__cOstd|dS)NzCannot instantiate r6rrrrr8r8r=rWsz_SpecialForm.__call__cCstj||fSr?rPUnionr2r8r8r=__or__sz_SpecialForm.__or__cCstj||fSr?rhr2r8r8r=__ror__sz_SpecialForm.__ror__cCst|ddS)Nz! cannot be used with isinstance()r6)rrr(r8r8r=rsz_SpecialForm.__instancecheck__cCst|ddS)Nz! cannot be used with issubclass()r6)rrrIr8r8r=rsz_SpecialForm.__subclasscheck__cCs |||Sr?)rdrr8r8r=rzsz_SpecialForm.__getitem__N)r|r}r~rrrerfrsr1rWrjrkrrrPrrzr8r8r8r=rcsrccCst|ddS)aPRepresents an arbitrary literal string. Example:: from pip._vendor.typing_extensions import LiteralString def query(sql: LiteralString) -> ...: ... query("SELECT * FROM table") # ok query(f"SELECT * FROM {input()}") # not ok See PEP 675 for details. rANr6rrrr8r8r=rscCst|ddS)zUsed to spell the type of "self" in classes. Example:: from typing import Self class ReturnsSelf: def parse(self, data: bytes) -> Self: ... return self rANr6rlr8r8r=r scCst|ddS)aThe bottom type, a type that has no members. This can be used to define a function that should never be called, or a function that never returns:: from pip._vendor.typing_extensions import Never def never_call_me(arg: Never) -> None: pass def int_or_str(arg: int | str) -> None: never_call_me(arg) # type checker error match arg: case int(): print("It's an int") case str(): print("It's a str") case _: never_call_me(arg) # ok, arg is of type Never rANr6rlr8r8r=r3-sc@seZdZddZdS)_ExtensionsSpecialFormcCs d|jSrnrorqr8r8r=rsMsz_ExtensionsSpecialForm.__repr__Nr@r8r8r8r=rmLsrmcCs"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. rurvrxr8r8r=r5PscCs"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, ) rurvrxr8r8r=r6dsc@seZdZddZddZdS) _RequiredFormcCs d|jSrnrorqr8r8r=rswsz_RequiredForm.__repr__cCs"t||jd}t||fSrtrvrxr8r8r=rzzs z_RequiredForm.__getitem__Nr{r8r8r8r=rpvsrprnroc@seZdZddZdS)_UnpackSpecialFormcCs d|jSrnrorqr8r8r=rssz_UnpackSpecialForm.__repr__Nr@r8r8r8r=rqsrqc@seZdZejZdS _UnpackAliasNr|r}r~rPr^rr8r8r8r=rssrscCs t||jd}t||fS)A special typing construct to unpack a variadic type. For example: Shape = TypeVarTuple('Shape') Batch = NewType('Batch', int) def add_batch_axis( x: Array[Unpack[Shape]] ) -> Array[Batch, Unpack[Shape]]: ... rurPrwrprsrxr8r8r=r s cCs t|tSr?r@rsr(r8r8r=r9sr9c@seZdZejZdSrrrtr8r8r8r=rssc@seZdZddZddZdS) _UnpackFormcCs d|jSrnrorqr8r8r=rssz_UnpackForm.__repr__cCs t||jd}t||fSrtrvrxr8r8r=rzs z_UnpackForm.__getitem__Nr{r8r8r8r=rysryrucCs t|tSr?rwrxr8r8r=r9sc@sNeZdZdZejZddZddZddZ dd Z d d Z d d Z ddZ dS)r aType variable tuple. Usage:: Ts = TypeVarTuple('Ts') In the same way that a normal type variable is a stand-in for a single type such as ``int``, a type variable *tuple* is a stand-in for a *tuple* type such as ``Tuple[int, str]``. Type variable tuples can be used in ``Generic`` declarations. Consider the following example:: class Array(Generic[*Ts]): ... The ``Ts`` type variable tuple here behaves like ``tuple[T1, T2]``, where ``T1`` and ``T2`` are type variables. To use these type variables as type parameters of ``Array``, we must *unpack* the type variable tuple using the star operator: ``*Ts``. The signature of ``Array`` then behaves as if we had simply written ``class Array(Generic[T1, T2]): ...``. In contrast to ``Generic[T1, T2]``, however, ``Generic[*Shape]`` allows us to parameterise the class with an *arbitrary* number of type parameters. Type variable tuples can be used anywhere a normal ``TypeVar`` can. This includes class definitions, as shown above, as well as function signatures and variable annotations:: class Array(Generic[*Ts]): def __init__(self, shape: Tuple[*Ts]): self._shape: Tuple[*Ts] = shape def get_shape(self) -> Tuple[*Ts]: return self._shape shape = (Height(480), Width(640)) x: Array[Height, Width] = Array(shape) y = abs(x) # Inferred type is Array[Height, Width] z = x + x # ... is Array[Height, Width] x.get_shape() # ... is tuple[Height, Width] ccs |jVdSr?) __unpacked__rqr8r8r=__iter__ szTypeVarTuple.__iter__c CsX||_ztdjdd}Wnttfk r:d}YnX|dkrJ||_t||_ dS)Nrr|rrK) r|rrrrrrr}r rz)rrrrPr8r8r=rs zTypeVarTuple.__init__cCs|jSr?rVrqr8r8r=rsszTypeVarTuple.__repr__cCs t|Sr?rUrqr8r8r=r5szTypeVarTuple.__hash__cCs||kSr?r8r2r8r8r=r3"szTypeVarTuple.__eq__cCs|jSr?rVrqr8r8r=r1%szTypeVarTuple.__reduce__cOsd|krtddS)Nrz&Cannot subclass special typing classesr6rgr8r8r=r(szTypeVarTuple.__init_subclass__N)r|r}r~rrPr^rr{rrsr5r3r1rr8r8r8r=r s, )__objrcCstdt|jtjd|S)aReveal the inferred type of a variable. When a static type checker encounters a call to ``reveal_type()``, it will emit the inferred type of the argument:: x: int = 1 reveal_type(x) Running a static type checker (e.g., ``mypy``) on this example will produce output similar to 'Revealed type is "builtins.int"'. At runtime, the function prints the runtime type of the argument and returns it unchanged. zRuntime type is )file)printrr|rstderr)r|r8r8r=r,0s)__argrcCs tddS)a1Assert to the type checker that a line of code is unreachable. Example:: def int_or_str(arg: int | str) -> None: match arg: case int(): print("It's an int") case str(): print("It's a str") case _: assert_never(arg) If a type checker finds that a call to assert_never() is reachable, it will emit an error. At runtime, this throws an exception when called. zExpected code to be unreachableN)r-)rr8r8r=rGsr8) eq_default order_defaultkw_only_defaultfield_specifiers.)rrrrrrc sfdd}|S)a Decorator that marks a function, class, or metaclass as providing dataclass-like behavior. Example: from pip._vendor.typing_extensions import dataclass_transform _T = TypeVar("_T") # Used on a decorator function @dataclass_transform() def create_model(cls: type[_T]) -> type[_T]: ... return cls @create_model class CustomerModel: id: int name: str # Used on a base class @dataclass_transform() class ModelBase: ... class CustomerModel(ModelBase): id: int name: str # Used on a metaclass @dataclass_transform() class ModelMeta(type): ... class ModelBase(metaclass=ModelMeta): ... class CustomerModel(ModelBase): id: int name: str Each of the ``CustomerModel`` classes defined in this example will now behave similarly to a dataclass created with the ``@dataclasses.dataclass`` decorator. For example, the type checker will synthesize an ``__init__`` method. The arguments to this decorator can be used to customize this behavior: - ``eq_default`` indicates whether the ``eq`` parameter is assumed to be True or False if it is omitted by the caller. - ``order_default`` indicates whether the ``order`` parameter is assumed to be True or False if it is omitted by the caller. - ``kw_only_default`` indicates whether the ``kw_only`` parameter is assumed to be True or False if it is omitted by the caller. - ``field_specifiers`` specifies a static list of supported classes or functions that describe fields, similar to ``dataclasses.field()``. At runtime, this decorator records its arguments in the ``__dataclass_transform__`` attribute on the decorated object. See PEP 681 for details. csd|_|S)N)rrrrr)Z__dataclass_transform__)Z cls_or_fnrrrrrr8r= decoratorsz&dataclass_transform..decoratorr8)rrrrrrr8rr=r asF c Cs6ztdjddWSttfk r0YdSXdS)Nrkr|r)rrrrrrr8r8r8r=_callersrcCsPdd|D}dd|D}tj||||d}||_|j_tjdkrL||_|S)NcSsg|] \}}|qSr8r8r;rrVr8r8r=r>sz!_make_nmtuple..c Ss&i|]\}}|t|d|dqS)zfield z annotation must be a typerrr8r8r=rsz!_make_nmtuple..defaultsmodulerX)r; namedtuplerrr version_info _field_types)rrbrrr rnm_tplr8r8r= _make_nmtuples rr}r|rc@seZdZddZdS)_NamedTupleMetac sJt|ks t|D]}|tk r|tjk rtdqtdd|D}di}g}|D]L}|krn||qV|rVtd|dt|dkrdnd d d |qVt || fd d |Ddd}||_ tj|krtjj j} t| |_ D]>} | tkrtd| q| tkr| |jkrt|| | qtj|krF||S)Nz3can only inherit from a NamedTuple type and Genericcss|]}|tkrtn|VqdSr?) _NamedTuplerar r8r8r=rAsz*_NamedTupleMeta.__new__..rzNon-default namedtuple field z cannot follow default fieldrs rcsg|] }|qSr8r8)r;rr r8r=r>sz+_NamedTupleMeta.__new__..r}rz&Cannot overwrite NamedTuple attribute )rr-rPrrDrarr_rGrrrrrr classmethod_prohibited_namedtuple_fieldsr_special_namedtuple_fieldsrsetattrr) rIrr r rrb default_names field_namerZ class_getitemkeyr8rr=rs@   2     z_NamedTupleMeta.__new__N)r|r}r~rr8r8r8r=rsrcKs.|dkr|}n |rtdt||tdS)NzIEither list of fields or keywords can be provided to NamedTuple, not both)r)rrDrr)Z __typenameZ__fieldsrr8r8r=rs  )rNz$(typename, fields=None, /, **kwargs)cCst|ks ttfSr?)rr-r)r r8r8r=_namedtuple_mro_entriess r)N)NNF)r8)N)rr;collections.abcrr"rrbrRrP__all__ZPEP_560rZ GenericMetarrErMrrWrcr4r^rdrerfrgrirrFrrcrmr"r&r(rrr*r!r defaultdictpartialrrr r rrrrrrrr_aliasrrrr)r/r2rrrrr+rABCMetarr.r-rrrr'rr__text_signature__r r|r}rrrr%rrrrQr$r#r9 ImportErrorrSr:r0r>rrrBrrrYrr\rr_r1r`_Finalrr r3r5r6rmrpr rqrsr9ryr r,rr rLrriAnyrrrr _prohibitedrrrrrrrrfr8r8r8r=sB                (  )     ,?     , '=       d !     / /+                P     Y   %