?`uD~SrSSKJrJr SSKrSSKJr SSKrSSKrSSKrSSK r SSK r SSK r SSK J r J r JrJr SSKJrJrJrJrJrJrJrJrJr /SQrSSS .S jjrSSS .S jjrS rSrSrS S.S\ 4Sjjr!Sr"Sr#SS.Sjr$Sr%Sr&Sr'Sr(/r)0r*SSS.Sjjr+S\,SS4Sjr-"S S!5r.\."5r/\/4\0"5S".S#jjr1"S$S%5r2"S&S'5r3"S(S)\2\3S S*9r4"S+S,\4S S*9r5"S-S.\65r7"S/S0\7S19r8\4S25r9\4S35r:\4S45r;\4S55r<\4S65r=\4S75r>\4S85r?S9r@\4S:5rA\5\+"S S9S;55rB\4S<5rC\4S=5rD\4S>5rE\4S?5rF"S@SA\2S S*9rGSB\8S\ 4SCjrHSB\8S\ 4SDjrISErJSFrKSGrLSHrM\+SI5rNSJrOSKrP"SLSM\2S S*9rQ"SNSO\QS S*9rR"SPSQ\3\QS S*9rS"SRSS\SS S*9rT"STSU\3\RS S*9rU"SVSW\SS S*9rV"SXSY\SS S*9rW"SZS[\3\RS S*9rXS\rY"S]S^\RS S*9rZ"S_S`\RS S*9r[\4Sa5r\"SbSc\RS S*9r]"SdSe5r^\0"1Sfk5r_\0"1Sgk5r`\_\`-Sh1-raSirbSjrcSSljrdSSnjre/SoQSpSq/Sr.rf\RSs5rh\)R\hR5 Strk\R"\\k5 Surm\R"\\m5 CkCm\Rro\RrqSvrr"SwSx\5rs\tSy5ru"SzS{\\sS19rv"S|S}\3\RS S*9rw\5\+"S S9S~55rxSrySrzSr{\ R\ R\ R\ R\ \ \4rSSjrSrSrSrSrSrS\:S\:4SjrSrSrSr\"\GR"\\55rSrSrSrSr\"S5r\"S5r\"S5r\"SS S9r\"SS S9r\"SS S9r\"SS S9r\"SS \6S9r\"S\\,5r\Sr\"\RGR:S5r\"\RGR<Sk5r\"\RGR>S5r\"\RGR@Sk5r\"\RGRBSk5r\"\RGRDSk5r\"\RGRFSk5r\"\RGRHSk5r\"\RGRJS5r\"\RGRLSk5r\"\RGRNSk5r\V"\RGRPSm5rS\l\"\RGRRSkSS9r\"\RGRVSk5r\"\RGRXSm5r\"\RGRZSm5r\"\RGR\Sk5r\"\RGR^Sk5r\T"\RGR`SSS9r\W"\SSSS9rS\l\"\SkSSS9r\"\GRjSkSS9r\"\SkSSS9r\"\0SkSSS9r\"\RGRrSk5r\"\RGRtSk5r\"\RGRvSm5r\"\RGRxSk5r\"\SmSSS9r\"\R SmSS9r\"\GR~Sm5r\"\GRSk5r\"\GRSm5r\"\RGRS\ GR\ GR4S9r\"\RGRSm\ GR4S9r\"\6SkSSS9rS\l\y"SS\v55r\y"SS\v55r\y"SS\v55r\y"SS\v55r\y"SS\v55r\yS"55r\yS"55rSSjr\0"1Sk5r\0"1Sk5r"SS\65r\/4Sjr\6GR\SS05rSr\\lSr"SS\65r\/4S S.Sjjr\6GR\SS05rS\l\4S5r\4S5r\4S5r"SS5r\,rSr"SS\\5r"SS\\5r"SS\\,5rS"5r"SS\v5rS SSSSS.S\ S\ S\ S\ S\\6\8\S\84-S4S\8S\4SjjrSSS47 rS"5rS\6S\ 4SjrS\6S\0\,4SjrSrg)a The typing module: Support for gradual typing as defined by PEP 484 and subsequent PEPs. Among other things, the module includes the following: * Generic, Protocol, and internal machinery to support generic aliases. All subscripted types like X[int], Union[int, str] are generic aliases. * Various "special forms" that have unique meanings in type annotations: NoReturn, Never, ClassVar, Self, Concatenate, Unpack, and others. * Classes whose instances can be type arguments to generic classes and functions: TypeVar, ParamSpec, TypeVarTuple. * Public helper functions: get_type_hints, overload, cast, final, and others. * Several protocols to support duck-typing: SupportsFloat, SupportsIndex, SupportsAbs, and others. * Special types: NewType, NamedTuple, TypedDict. * Deprecated aliases for builtin types and collections.abc ABCs. Any name not present in __all__ is an implementation detail that may be changed without notice. Use at your own risk! )abstractmethodABCMetaN) defaultdict)WrapperDescriptorTypeMethodWrapperTypeMethodDescriptorType GenericAlias) _idfuncTypeVar ParamSpec TypeVarTuple ParamSpecArgsParamSpecKwargs TypeAliasTypeGeneric NoDefault)h AnnotatedAnyCallableClassVar ConcatenateFinal ForwardRefrLiteralOptionalr ProtocolTupleTyper r Union AbstractSet ByteString ContainerContextManagerHashable ItemsViewIterableIteratorKeysViewMapping MappingViewMutableMappingMutableSequence MutableSetSequenceSized ValuesView Awaitable AsyncIterator AsyncIterable Coroutine CollectionAsyncGeneratorAsyncContextManager Reversible SupportsAbs SupportsBytesSupportsComplex SupportsFloat SupportsIndex SupportsInt SupportsRoundChainMapCounterDequeDict DefaultDictList OrderedDictSet FrozenSet NamedTuple TypedDict GeneratorBinaryIOIOMatchPatternTextIOAnyStr assert_type assert_nevercastclear_overloadsdataclass_transformfinalget_args get_origin get_overloadsget_protocol_membersget_type_hints is_protocol is_typeddict LiteralStringNeverNewType no_type_checkno_type_check_decoratorrNoReturn NotRequiredoverloadoverriderrReadOnlyRequired reveal_typeruntime_checkableSelfText TYPE_CHECKING TypeAlias TypeGuardTypeIsrUnpackFallow_special_formsc`Uc [S5$[U[5(a [XUS9$U$)z=For converting None to type(None), and strings to ForwardRef.N)moduleis_class)type isinstancestrr)argrvrts -/opt/alt/python313/lib64/python3.13/typing.py _type_convertr}s1 {Dz#s#7JKK JTc [[4nU(dU[4- nU(a U[4- n[ XUS9n[ U[ 5(aURU;a[US35eU[[[[[[4;aU$U(aU[[4;aU$[ U[5(dU[[4;a[SUS35e[!U5["La[USU<SS35eU$)aCheck that the argument is a type, and return it (internal helper). As a special case, accept None and return type(None) instead. Also wrap strings into ForwardRef instances. Consider several corner cases, for example plain special forms like Union are not valid, while Union[int, str] is OK, etc. The msg argument is a human-readable error message, e.g.:: "Union[arg, ...]: arg should be a type." We append the repr() of the actual value (truncated to 100 chars). )rvrt is not valid as type argumentzPlain z Got z.100.)rrrrr}ry _GenericAlias __origin__ TypeErrorrr_rdr`rlro _SpecialFormrxtuple)r{msg is_argumentrvrtinvalid_generic_formss r| _type_checkrs%h/ (,  !eX - ! @S TC3 && NN3 33%=>?? sM8UD)DD sx&77 #|$$/B(B&%CDEE CyE3%uSL4L233 Jr~cXUSL=(d [U[[[[45$N.)ryrlistr _ConcatenateGenericAliasr{s r|_is_param_exprrs, #: @C D)%= >@@r~cUR[RRL=(a( [ U5S:H=(a [ US5(+$)aInternal helper for munging collections.abc.Callable's __args__. The canonical representation for a Callable's __args__ flattens the argument types, see https://github.com/python/cpython/issues/86361. For example:: >>> import collections.abc >>> P = ParamSpec('P') >>> collections.abc.Callable[[int, int], str].__args__ == (int, int, str) True >>> collections.abc.Callable[P, str].__args__ == (P, str) True As a result, if we need to reconstruct the Callable from its __args__, we need to unflatten it. r)r collectionsabcrlenr)typargss r|_should_unflatten_callable_argsrs@& +//222 =Ta;N47$; <r~cx[U[5(a7URS:Xa UR$URSUR3$USLag[U[R 5(a UR $[U[5(aSSRSU55-S-$[U5$) a'Return the repr() of an object, special-casing types (internal helper). If obj is a type, we return a shorter version than the default type.__repr__, based on the module and qualified name, which is typically enough to uniquely identify a type. For everything else, we fall back on repr(obj). builtinsr....[, c38# UHn[U5v M g7fN) _type_repr).0ts r| _type_repr..s:cz!}}c]) ryrx __module__ __qualname__types FunctionType__name__rjoinreprobjs r|rrs#t >>Z '## #..!3#3#3"455 cz#u))**||#uTYY:c:::S@@ 9r~enforce_default_orderingrcSnSn/nUGH,n[U[5(aM[U[5(a6UH.n[U/5HnXt;dM UR U5 M M0 Mf[ US5(awXT;apU(aVU(a UR 5(a [S5eUR 5(aSnOU(a[SU<S35eUR U5 MM[U5(aSn[USS5HnXd;dM UR U5 M GM/ [U5$) zCollect all type parameters in args in order of first appearance (lexicographic order). For example:: >>> P = ParamSpec('P') >>> T = TypeVar('T') >>> _collect_type_parameters((T, Callable[P, T])) (~T, ~P) F__typing_subst__z2Type parameter with a default follows TypeVarTupleTzType parameter z8 without a default follows type parameter with a default__parameters__) ryrxr_collect_type_parametersappendhasattr has_defaultr_is_unpacked_typevartuplegetattr)rrdefault_encounteredtype_var_tuple_encountered parametersrx collecteds r|rrs< !&J  a    5 ! !!91#!>I 2")))4"?Q* + +"+1ammoo')@AA}}.2+,'/!?Q)QRR!!!$#)++-1*Q 0"5&%%a(69>  r~c R[UR5nU(d[US35e[U5nX2:wamX2:aHURUR5(agU[ SUR55-nSU3nOUn[SX2:aSOSSUS US U35eg) zCheck correct count for parameters of a generic cls (internal helper). This gives a nice error message in case of count mismatch.  is not a generic classNc3@# UHoR5v M g7fr)rrps r|r0_check_generic_specialization..LsL9KA 9Ks at least Too manyfew arguments for ; actual , expected )rrrrsum)cls arguments expected_len actual_len expect_vals r|_check_generic_specializationr6s s))*L 3%6788YJ!  $!!*-99;; CL9K9KLL LL$\N3J%J$)BvNO #uIj\ZLRS S%"r~c/nUHFn[USS5nUb"U(aUSSLdURU5 M5URU5 MH U$)N__typing_unpacked_tuple_args__.)rextendr)rnewargsr{subargss r| _unpack_argsrUsRG#?F  GBK34F NN7 # NN3   Nr~unhashable_fallbackct[RU5$![a U(de[U5s$f=fr)dictfromkeysr_deduplicate_unhashable)paramsrs r| _deduplicater_s6/}}V$$ /" &v.. /s 77cL/nUHnX!;dM URU5 M U$r)r)unhashable_paramsnew_unhashablers r|rris-N  "  ! !! $ r~c[U5n[U5n[U5nUHnURU5 M U(+$![a gf=f)NF)rrremove ValueError) first_args second_argsfirst_unhashablesecond_unhashablerelems r|_compare_args_orderlessrpsZ.z:/ < A$D HHTN%5L sA AAc/nUHVn[U[[R45(aUR UR 5 MEUR U5 MX [[USS95$)zoInternal helper for Union creation and substitution. Flatten Unions among parameters, then remove duplicates. Tr) ry_UnionGenericAliasr UnionTyper__args__rrrrrrs r|_remove_dups_flattenr{sZ F  a,eoo> ? ? MM!** % MM!   f$? @@r~c/nUHFn[U[5(aURUR5 M5UR U5 MH [ U5$)zHInternal helper for Literal creation: flatten Literals among parameters.)ry_LiteralGenericAliasrrrrrs r|_flatten_literal_paramsrsG F  a- . . MM!** % MM!   =r~typedc*^U4SjnUbU"U5$U$)zInternal wrapper caching __getitem__ of generic types. For non-hashable arguments, the original function is used as a fallback. c>^[R"TS9"T5nU[T'[R UR 5 A[R "T5U4Sj5nU$)NrcT>[T"U0UD6$![a Of=fT"U0UD6$r)_cachesr)rkwdsfuncs r|inner+_tp_cache..decorator..inners> t}d3d33  && &s  ) functools lru_cacher _cleanupsr cache_clearwraps)rcacherrs` r| decorator_tp_cache..decorators\ ##%06 **+    '  '  r~r)rrr s ` r| _tp_cacher s (  r~funcnamereturncJSSKnSU<SUS3nURU[SS9 g)Nrz:Failing to pass a value to the 'type_params' parameter of z@ is deprecated, as it leads to incorrect behaviour when calling zl on a stringified annotation that references a PEP 695 type parameter. It will be disallowed in Python 3.15.category stacklevel)warningswarnDeprecationWarning)r r depr_messages r|._deprecation_warning_for_no_type_params_passedrs= \ z"0 1 MM,);MJr~c\rSrSrSrSrSrg) _Sentinelircg)Nz rselfs r|__repr___Sentinel.__repr__sr~N)rrr__firstlineno__ __slots__r__static_attributes__rr~r|rrs Ir~rrecursive_guardcL^^^^T[La [S5 Sm[U[5(aUR TTTTS9$[U[ [ [R45(Ga7[U[ 5(ao[SUR55nURn[X5(aURUSSUS4nOURUnU(a [Un[UUUU4SjUR55nXpR:XaU$[U[ 5(a[ URU5$[U[R5(a%[R "["R$U5$UR'U5$U$)zEvaluate all forward references in the given type t. For use of globalns and localns see the docstring for get_type_hints(). recursive_guard is used to prevent infinite recursion with a recursive ForwardRef. ztyping._eval_typerr"c3f# UH'n[U[5(a [U5OUv M) g7fr)ryrzrrr{s r|r_eval_type..s,%C$.c3#7#7 3S@%s/1Nrc 3>># UHn[UTTTTS9v M g7f)r"N) _eval_type)raglobalnslocalnsr# type_paramss r|rr's,   8Wk?  s) _sentinelrryr _evaluaterr rrrr __unpacked__rrrrrreduceoperatoror_ copy_with)rr+r,r-r#r is_unpackedev_argss ```` r|r)r)sTi67JK !Z  {{8Wk?{[[!m\5??CDD a & &::D..K.q77LL$s)T"X!67LL&1I ZZ    jj H a & & g6 6 a ) )##HLL': :;;w' ' Hr~c"\rSrSrSrSrSrSrg)_FinalizMixin to prohibit subclassing.) __weakref__c&SU;a [S5eg)N_rootz&Cannot subclass special typing classesr)rrrs r|__init_subclass___Final.__init_subclass__s $ DE E r~rN)rrrr__doc__r r=r!rr~r|r8r8s( IFr~r8c \rSrSrSrSrSrSrg) _NotIterableiarMixin to prevent iteration, without being compatible with Iterable. That is, we could do:: def __iter__(self): raise TypeError() But this would make users of this mixin duck type-compatible with collections.abc.Iterable - isinstance(foo, Iterable) would be True. Luckily, we can instead prevent iteration by setting __iter__ to None, which is treated specially. rN)rrrrr?r __iter__r!rr~r|rArAs IHr~rAcd\rSrSrSrSrSrSrSrSr Sr S r S r S r S r\S 5rSrg)ri)_namer?_getitemcTXlURUlURUlgr)rErrDr?)rgetitems r|__init___SpecialForm.__init__s %%  r~c<US;a UR$[U5e)N>rr)rDAttributeError)ritems r| __getattr___SpecialForm.__getattr__ s / /:: T""r~c [SU<35e)NCannot subclass r<rbasess r|__mro_entries___SpecialForm.__mro_entries__&s*4(344r~c SUR-$Ntyping.rDrs r|r_SpecialForm.__repr__)4::%%r~cUR$rrXrs r| __reduce___SpecialForm.__reduce__, zzr~c [SU<35e)NzCannot instantiate r<)rrrs r|__call___SpecialForm.__call__/s-dX677r~c[X4$rrrothers r|__or___SpecialForm.__or__2T[!!r~c[X4$rrcrds r|__ror___SpecialForm.__ror__5U[!!r~c[US35e)Nz! cannot be used with isinstance()r<rrs r|__instancecheck___SpecialForm.__instancecheck__84& ABCCr~c[US35e)Nz! cannot be used with issubclass()r<rrs r|__subclasscheck___SpecialForm.__subclasscheck__;rqr~c$URX5$r)rErrs r| __getitem___SpecialForm.__getitem__>s}}T..r~)r?rErDN)rrrrr rHrMrSrr\r`rfrjrortr rxr!rr~r|rrsO0I' # 5&8""DD//r~r)r;c\rSrSrSrSrg)_TypedCacheSpecialFormiCcX[U[5(dU4nUR"U/UQ76$r)ryrrErws r|rx"_TypedCacheSpecialForm.__getitem__Ds**e,,$J}}T/J//r~rN)rrrrrxr!rr~r|r{r{Cs0r~r{c4^\rSrSrU4SjrU4SjrSrU=r$)_AnyMetaiJcJ>U[La [S5e[TU] U5$)Nz+typing.Any cannot be used with isinstance())rrsuperro)rr __class__s r|ro_AnyMeta.__instancecheck__Ks& 3;IJ Jw(--r~c4>U[Lag[TU] 5$)Nz typing.Any)rrr)rrs r|r_AnyMeta.__repr__Ps 3;w!!r~r)rrrrrorr! __classcell__rs@r|rrJs. ""r~rc,^\rSrSrSrU4SjrSrU=r$)riVa;Special type indicating an unconstrained type. - Any is compatible with every type. - Any assumed to have all methods. - All values assumed to be instances of Any. Note that all the above statements are true from the point of view of static type checkers. At runtime, Any should not be used with instance checks. cJ>U[La [S5e[TU] U5$)NzAny cannot be instantiated)rrr__new__rrkwargsrs r|r Any.__new__bs% #:89 9ws##r~r)rrrrr?rr!rrs@r|rrVs $$r~r) metaclassc[US35e)ajSpecial type indicating functions that never return. Example:: from typing import NoReturn def stop() -> NoReturn: raise Exception('no way') NoReturn can also be used as a bottom type, a type that has no values. Starting in Python 3.11, the Never type should be used for this concept instead. Type checkers should treat the two equivalently.  is not subscriptabler<rws r|rdrdhs tf12 33r~c[US35e)a(The 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 typing 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 rr<rws r|r`r`}s, tf12 33r~c[US35e)aKUsed to spell the type of "self" in classes. Example:: from typing import Self class Foo: def return_self(self) -> Self: ... return self This is especially useful for: - classmethods that are used as alternative constructors - annotating an `__enter__` method which returns self rr<rws r|rlrls" tf12 33r~c[US35e)aRepresents an arbitrary literal string. Example:: from typing import LiteralString def run_query(sql: LiteralString) -> None: ... def caller(arbitrary_string: str, literal_string: LiteralString) -> None: run_query("SELECT * FROM students") # OK run_query(literal_string) # OK run_query("SELECT * FROM " + literal_string) # OK run_query(arbitrary_string) # type checker error run_query( # type checker error f"SELECT * FROM students WHERE name = {arbitrary_string}" ) Only string literals and other LiteralStrings are compatible with LiteralString. This provides a tool to help prevent security issues such as SQL injection. rr<rws r|r_r_s0 tf12 33r~c4[XS3SS9n[X45$)aSpecial 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().  accepts only single type.TrsrrrrrLs r|rr&& zV+E#F\` aD w ''r~c4[XS3SS9n[X45$)aSpecial typing construct to indicate final names to type checkers. A final 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. rTrsrrs r|rrrr~c(^US:Xa [S5e[U[5(dU4nSm[U4SjU55n[U5n[ U5S:XaUS$[ U5S:Xa[ S5U;a [ XS S 9$[ X5$) aUnion type; Union[X, Y] means either X or Y. On Python 3.10 and higher, the | operator can also be used to denote unions; X | Y means the same thing to the type checker as Union[X, Y]. To define a union, use e.g. Union[int, str]. Details: - The arguments must be types and there must be at least one. - None as an argument is a special case and is replaced by type(None). - Unions of unions are flattened, e.g.:: assert Union[Union[int, str], float] == Union[int, str, float] - Unions of a single argument vanish, e.g.:: assert Union[int] == int # The constructor actually returns int - Redundant arguments are skipped, e.g.:: assert Union[int, str, int] == Union[int, str] - When comparing unions, the argument order is ignored, e.g.:: assert Union[int, str] == Union[str, int] - You cannot subclass or instantiate a union. - You can use Optional[X] as a shorthand for Union[X, None]. rz Cannot take a Union of no types.z)Union[arg, ...]: each arg must be a type.c3<># UHn[UT5v M g7frrrrrs r|rUnion..s?Jq{1c**JrrNrname)rryrrrrxrrrrs @r|rrs>R:;; j% ( ( ] 5C?J??J%j1J :!!} :!T j 8!$DD d //r~c[X4$)zUsed from the C implementation of TypeVar. TypeVar.__or__ calls this instead of returning types.UnionType because we want to allow unions between TypeVars and strings (forward references). rc)leftrights r| _make_unionrs  r~cF[XS35n[U[S54$)z,Optional[X] is equivalent to Union[X, None].z requires a single type.N)rrrx)rrr{s r|rr&s) jF*B"C DC d4j !!r~c [U5n[S[[[ U55555n[ X5$![ a Nf=f)aSpecial typing form to define literal types (a.k.a. value types). This form can be used to indicate to type checkers that the corresponding variable or function parameter has a value equivalent to the provided literal (or one of several literals):: def validate_simple(data: Any) -> Literal[True]: # always returns True ... MODE = Literal['r', 'rb', 'w', 'wb'] def open_helper(file: str, mode: MODE) -> str: ... open_helper('/some/path', 'r') # Passes type check open_helper('/other/path', 'typo') # Error in type checker Literal[...] cannot be subclassed. At runtime, an arbitrary value is allowed as type argument to Literal[...], but type checkers may impose restrictions. c3*# UH upUv M g7frr)rr_s r|rLiteral..Hs^)]1)]s)rrrr_value_and_type_iterrrrws r|rr,sU2)4J ^d;OPZ;[6\)]^^   11    s-A AAc[US35e)aSpecial form for marking type aliases. Use TypeAlias to indicate 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. rr<rws r|roroOs tf12 33r~c^US:Xa [S5e[U[5(dU4nUSSLd#[US[5(d [S5eSm/U4SjUSS5QUSP7n[ X5$) aGSpecial form for annotating higher-order functions. ``Concatenate`` can be used in conjunction with ``ParamSpec`` and ``Callable`` to represent a higher-order function which adds, removes or transforms the parameters of a callable. For example:: Callable[Concatenate[int, P], int] See PEP 612 for detailed information. rz&Cannot take a Concatenate of no types.r.zMThe last parameter to Concatenate should be a ParamSpec variable or ellipsis.z/Concatenate[arg, ...]: each arg must be a type.c3<># UHn[UT5v M g7frrrs r|rConcatenate..vsAAK3''rN)rryrr rrs @r|rr`sR@AA j% ( ( ] rNc !Z 2 %J%J:; ; ;CRACRAR:b>RJ #D 55r~c6[XS35n[X45$)a Special typing construct for marking user-defined type predicate functions. ``TypeGuard`` can be used to annotate the return type of a user-defined type predicate 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 predicate". Sometimes it would be convenient to use a user-defined boolean function as a type predicate. Such a function should use ``TypeGuard[...]`` or ``TypeIs[...]`` as its return type to alert static type checkers to this intention. ``TypeGuard`` should be used over ``TypeIs`` when narrowing from an incompatible type (e.g., ``list[object]`` to ``list[int]``) or when the function does not return ``True`` for all instances of the narrowed type. Using ``-> TypeGuard[NarrowedType]`` 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 ``NarrowedType``. For example:: def is_str_list(val: list[object]) -> TypeGuard[list[str]]: '''Determines whether all objects in the list are strings''' return all(isinstance(x, str) for x in val) def func1(val: list[object]): if is_str_list(val): # Type of ``val`` is narrowed to ``list[str]``. print(" ".join(val)) else: # Type of ``val`` remains as ``list[object]``. print("Not a list of strings!") 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 predicates is left to the user. ``TypeGuard`` also works with type variables. For more information, see PEP 647 (User-Defined Type Guards). rrrs r|rprpzs$h zV+E#F GD w ''r~c6[XS35n[X45$)aV Special typing construct for marking user-defined type predicate functions. ``TypeIs`` can be used to annotate the return type of a user-defined type predicate function. ``TypeIs`` only accepts a single type argument. At runtime, functions marked this way should return a boolean and accept at least one argument. ``TypeIs`` 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 predicate". Sometimes it would be convenient to use a user-defined boolean function as a type predicate. Such a function should use ``TypeIs[...]`` or ``TypeGuard[...]`` as its return type to alert static type checkers to this intention. ``TypeIs`` usually has more intuitive behavior than ``TypeGuard``, but it cannot be used when the input and output types are incompatible (e.g., ``list[object]`` to ``list[int]``) or when the function does not return ``True`` for all instances of the narrowed type. Using ``-> TypeIs[NarrowedType]`` 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 intersection of the argument's original type and ``NarrowedType``. 3. If the return value is ``False``, the type of its argument is narrowed to exclude ``NarrowedType``. For example:: from typing import assert_type, final, TypeIs class Parent: pass class Child(Parent): pass @final class Unrelated: pass def is_parent(val: object) -> TypeIs[Parent]: return isinstance(val, Parent) def run(arg: Child | Unrelated): if is_parent(arg): # Type of ``arg`` is narrowed to the intersection # of ``Parent`` and ``Child``, which is equivalent to # ``Child``. assert_type(arg, Child) else: # Type of ``arg`` is narrowed to exclude ``Parent``, # so only ``Unrelated`` is left. assert_type(arg, Unrelated) The type inside ``TypeIs`` must be consistent with the type of the function's argument; if it is not, static type checkers will raise an error. An incorrectly written ``TypeIs`` function can lead to unsound behavior in the type system; it is the user's responsibility to write such functions in a type-safe manner. ``TypeIs`` also works with type variables. For more information, see PEP 742 (Narrowing types with ``TypeIs``). rrrs r|rqrqs$B zV+E#F GD w ''r~cX\rSrSrSrSrSSS.Sjjr\4SjrS r S r S r S r S r Srg)riz-Internal wrapper to hold a forward reference.)__forward_arg____forward_code____forward_evaluated____forward_value____forward_is_argument____forward_is_class____forward_module__NF)rwc8[U[5(d[SU<35eURS5(aSUS3nOUn[ USS5nXlX`lSUlSUl X l X@l X0l g![ a [ SU<35ef=f) Nz*Forward reference must be a string -- got *(z,)[0]zevalz/Forward reference must be an expression -- got F) ryrzr startswithcompile SyntaxErrorrrrrrrr)rr{rrvrwarg_to_compilecodes r|rHForwardRef.__init__s#s##HPQ Q >>#   U^N N Y>:v>D # $%*"!%'2$$,!"( Y OPSwWX X Ys  A??BcU[La [S5 SnURU;aU$UR(aX!LGaUcUc0=pO UcUnOUcUnURb5[ [ RRURS5SU5nU(aX[U5[U5p!UH=nURnUR(aXa;dM'XQU'URUS5 M? [[URX5SUR URS9n[#UUUUX@R1-S9UlSUlUR$$)Nztyping.ForwardRef._evaluater__dict__z*Forward references must evaluate to types.)rrtr"T)r.rrrrrsysmodulesgetrrrpoprrrrr)r)rr+r,r-r#param param_nametype_s r|r/ForwardRef._evaluatesQ ) # :;X YK   ? 2K))W-DGO%''7!""&&2"KKOOD$;$;TBJPX$(NDM'(E!&J44 8R/4, J5 )  T**H>< 88$($=$= E &0!04H4H3I!I &D "*.D &%%%r~c`[U[5(d[$UR(aJUR(a9URUR:H=(a UR UR :H$URUR:H=(a UR UR :H$r)ryrNotImplementedrrrrrds r|__eq__ForwardRef.__eq__Hs%,,! !  % %%*E*E((E,A,AAF**e.E.EE G$$(=(==D''5+C+CC Er~cD[URUR45$r)hashrrrs r|__hash__ForwardRef.__hash__QsT))4+B+BCDDr~c[X4$rrcrds r|rfForwardRef.__or__Trhr~c[X4$rrcrds r|rjForwardRef.__ror__Wrlr~chURcSnOSUR<3nSUR<US3$)Nz , module=z ForwardRef())rr)r module_reprs r|rForwardRef.__repr__Zs@  " " *K%d&=&=%@AKT114[MCCr~)rrrrrrrTN)rrrrr?r rHr.r/rrrfrjrr!rr~r|rrs@7'I )u)08A/&bEE""Dr~rrcT[U[5(+=(a [USS5$)N#__typing_is_unpacked_typevartuple__F)ryrxrrs r|rrbs(At$ $ E A?? Jr~c  URnURU5nX4S-SH&n[U[5(dM[ SU35e [ U5n[ U5nUnXt- S- n Sn Sn [ U5Hbup[U [5(aM[U SS5nU(dM2[ U5S:XdMCUSSLdMMU b [ S5eU n USn Md U b[X5n[XU - S- 5n OX-U:a[ S US US US- 35eXU - :Xa+UR5(a[UR5nOX(Xi- n/USUQU /XH- -QUPU /Xy- U- U- S- -QX&U - SQ7$) Nrz(More than one TypeVarTuple parameter in rrr.z6More than one unpacked arbitrary-length tuple argumentrToo few arguments for rz, expected at least ) rindexryr rr enumeraterxrminrr __default__)raliasrrtypevartuple_indexralenplenrrvar_tuple_indexfillargkr{r replacements r|_typevartuple_prepare_substrts  ! !Fd+Q./0 e\ * *FugNO O1 t9D v;D D  % )EOGD/#t$$c#CTJGw3w<1,1C".#$\]]"#!!*""4)E/1A56  08##'&(.sD1K#566zFExpected a list of types, an ellipsis, ParamSpec, or Concatenate. Got )ryrrrrrr{s r|_paramspec_substrs[#e}%%DDD JC ::=@A A Jr~cURnURU5nU[U5:Xa%UR5(a/UQURPnU[U5:a[ SU35e[U5S:Xa [ US5(d US:XdeU4nU$[X$[5(a/USUQ[X$5PX$S-SQ7nU$)Nrrr) rrrrrrrryrr)rrrris r|_paramspec_prepare_substrs  ! !F TACI~$**,,((t''(CI~0899 6{atAw 7 7Av vw K DGT " "7bq75>7D1J7 Kr~c[U[5(dU4n[SU55nU[[4;nU(aU(d[ SUR S35e[ SU55(d[ SURS35e[[U55[U5:wa[ SURS35eOURHn[USS 5nUcMU"X5nM [X5 /n[URU5H>up6[U[5(aURU5 M-UR!U5 M@ [U5n[#X5$) ajParameterizes a generic class. At least, parameterizing a generic class is the *main* thing this method does. For example, for some generic class `Foo`, this is called when we do `Foo[int]` - there, with `cls=Foo` and `args=int`. However, note that this method is also called when defining generic classes in the first place with `class Foo(Generic[T]): ...`. c38# UHn[U5v M g7frr}rs r|r)_generic_class_getitem..s04aq!!4rzParameter list to z[...] cannot be emptyc38# UHn[U5v M g7fr)rrs r|rrs51#A&&rzParameters to zF[...] must all be type variables or parameter specification variables.z[...] must all be unique__typing_prepare_subst__N)ryrrrrrallrrsetrrrzipr rrr)rris_generic_or_protocolrpreparenew_argsnew_args r|_generic_class_getitemrsc dE " "w 040 0D Wh$77$S%5%5$66KL 5555 /89: : s4y>SY & .FGI I ' ''Ee%?FG"s)( &c0!#"4"4d;NE%..(( < X  ##r~c^ [[U] "U0UD6 /nSUR;a[UR;nOB[UR ;=(a( UR S:g=(a [U5[:gnU(a [S5eSUR;a[UR5nSnURHIn[U[5(dMUR[LdM/Ub [S5eURnMK Ubc[U5n[U5m UT ::dESR!U 4SjU55nSR!SU55n [SUS U S 35eUn[#U5Ulg) N__orig_bases__rz!Cannot inherit from plain Genericz0Cannot inherit from Generic[...] multiple times.rc3H># UHoT;dM [U5v M g7frrz)rrgvarsets r|r)_generic_init_subclass..s"M5aW.Bs-"+B#2t,HB1HH"+s46) rrrryr)rxrranyr7r)rrRresrbmeth new_basess r|rS!_BaseGenericAlias.__mro_entries__.s ??% ' JJt ' KK stA!.//a&&q"3T:+/DKT y%00"+  1Aw''" JJw Szr~cUS;a)UR=(d URR$SUR;a&[ U5(d[ URU5$[ U5e)N>rrr)rDrrrr'rrK)rr&s r|rM_BaseGenericAlias.__getattr__NsX / /::9!9!9 9 4== (D1A1A4??D1 1T""r~c~>[U5(dUS;a[TU] X5 g[URX5 g)N>r-rD_nparams _defaults)r'r __setattr__setattrr)rr&valrs r|rE_BaseGenericAlias.__setattr__Xs1 d  t'RR G  * DOOT /r~c6UR[U55$r)rtrxrns r|ro#_BaseGenericAlias.__instancecheck__^s%%d3i00r~c[S5e)NzBSubscripted generics cannot be used with class and instance checksr<rss r|rt#_BaseGenericAlias.__subclasscheck__as56 6r~c >[[[TU] 5[ UR 5Vs/sHn[ U5(aMUPM sn-55$s snfr)rr r__dir__dirrr'rr&rs r|rN_BaseGenericAlias.__dir__esPC)$'$8Q$8D 4@P4$8QRST TQs AA)rr r-rD)rrrrr?rHr`rSrMrErortrNr!rrs@r|r)r)s?(,$ @#0 16TTr~r)c^\rSrSrSSS.U4SjjrSrSrSrS r\ S 5r S r S r S r SrSrU4SjrSrSrU=r$)riuTNr*c>[TU]XUS9 [U[5(dU4n[SU55UlU[ [ 4;n[UUS9UlU(dURUl gg)Nr*c3<# UHnU[LaSOUv M g7f).N)_TypingEllipsisrs r|r)_GenericAlias.__init__..s&/)-A&'/%9c )-sr) rrHryrrrrrrr)rr.rr+rrrs r|rH_GenericAlias.__init__s| 6$&&7D/)-// #)gx-@#@ 6 %= $//DOr~c[U[5(d[$URUR:H=(a URUR:H$r)ryrrrrrds r|r_GenericAlias.__eq__sA%//! !5#3#334MMU^^3 5r~cD[URUR45$r)rrrrs r|r_GenericAlias.__hash__sT__dmm455r~c[X4$rrcrrs r|rf_GenericAlias.__or__rhr~c[X4$rrcrrs r|rj_GenericAlias.__ror__TZ  r~c&UR[[4;a[SU35eUR(d[US35e[ U[ 5(dU4n[SU56nURU5nURU5nU$)Nz%Cannot subscript already-subscripted rc38# UHn[U5v M g7frrrs r|r,_GenericAlias.__getitem__..s=1mA..r) rrrrrryrr_determine_new_argsr4)rrrrs r|rx_GenericAlias.__getitem__s" ??w1 1CD6JK K""tf$;<= =$&&7D==>++D1 NN8 $r~c DURnUHn[USS5nUcMU"X5nM [U5n[U5nXV:wa[SXV:aSOSSUSUSU35e[ [ X!55n[ URURU55$)Nrrrrrrr) rrrrrr r_make_substitutionr)rrrrr rrnew_arg_by_params r|rf!_GenericAlias._determine_new_argss$$Ee%?FG"t*4y6{ <dT[6e"DOTXSYZ''+fKv?@ @F 12T,,T]]#G-=rB  %G G&%a66#NN+;+>?#NN+;+>? ' &eGn5G+//":"::z'SX?Y?Y(*733(GU++$11'LM(qrr~c`URURXRURS9$N)rr+)rrrDr-rrs r|r4_GenericAlias.copy_with&s#~~doot**4::~VVr~cUR(aSUR-nO[UR5nUR(a6SR URVs/sHn[U5PM sn5nOSnUSUS3$s snf)NrWrz()rr)rDrrrr)rrr*rs r|r_GenericAlias.__repr__)sq ::tzz)Ddoo.D ==99T]]C]jm]CDDDqa  Ds!BcUR(a[5URnO URn[UR5n[ U5S:Xa[ US[5(dUun[RX44$Nrr) rDglobalsrrrrryr2rG)rr.rs r|r\_GenericAlias.__reduce__5se ::Ytzz*F__FT]]# t9>*T!We"<"<ED&//r~cn>[UR[5(a[SU<35eUR(a[ TU]U5$UR[LaG[U;agURU5nXS-SH n[U[5(dMX0LdM g UR4$)NrPrr) ryrrrrDrrSrrrr))rrRrr<rs r|rS_GenericAlias.__mro_entries__?s doo| 4 4.th78 8 ::7*51 1 ??g %5  D!AQ34[a!233 !!!r~c#"# [Uv g7fr)rrrs r|rB_GenericAlias.__iter__NsTls )rrr)rrrrrHrrrfrjr rxrfrjr4rr\rSrBr!rrs@r|rrusg4.2 0 05 6"!<O:<|W !0 "r~rcn^\rSrSrSSSS.U4Sjjr\S5rSrS rU4S jr S r S r S r Sr U=r$)_SpecialGenericAliasiVTNr)r+rdefaultsc>Uc URn[TU] XUS9 X lXPlUR S:XaSUR S3UlgSUR SUR S3Ulg)Nr*rzA generic version of r)rrrHrCrDrrr?)rr.nparamsr+rrrs r|rH_SpecialGenericAlias.__init__Wsw <??D 6 !    *263F3F2GqIDL263D3D2EQvGZGZF[[\]DLr~c ^[U[5(dU4nSm[U4SjU55nUR(ar[U5UR:aY[U5[UR5-UR:a*/UQUR[U5UR- SQ7n[U5nX R:waUR(a&SUR[UR5- 3nO[ UR5nUR(d[ US35e[ SX R:aSOSSUS US U35eURU5$) Nrc3<># UHn[UT5v M g7frrrs r|r3_SpecialGenericAlias.__getitem__..g;Fq{1c**Frrrrrrrrr)ryrrDrrCrzrr4)rrrexpectedrs @r|rx _SpecialGenericAlias.__getitem__bs:&%((YF:;F;; NNF dmm+F c$..11T]]BMvMs6{T]]/J/K LMF[  &~~&t}}s4>>7J'J&KLt}}-==4&(? @AAdZ---G6U"SSbcgbhi''1l+hZIJ J~~f%%r~cV[URUURURS9$rs)rrrDr-rrs r|r4_SpecialGenericAlias.copy_withzs$T__f"&**4::? ?r~c SUR-$rVrXrs r|r_SpecialGenericAlias.__repr__~rZr~c>[U[5(a [URUR5$[U[5(d[XR5$[ TU]U5$r)ryrr7rrrrt)rrrs r|rt&_SpecialGenericAlias.__subclasscheck__sR c/ 0 0cnndoo> >#}--c??3 3w(--r~cUR$rrXrs r|r\_SpecialGenericAlias.__reduce__r^r~c[X4$rrcr]s r|rf_SpecialGenericAlias.__or__rhr~c[X4$rrcr`s r|rj_SpecialGenericAlias.__ror__rbr~)r?rDrC)rrrrrHr rxr4rrtr\rfrjr!rrs@r|rrVsM044" ^ ^&&.?&."!!r~rc>^\rSrSrSSS.U4SjjrU4SjrSrU=r$)_DeprecatedGenericAliasiTNr*c.>[TU]XXES9 X0lg)Nr*)rrH_removal_version)rr.rremoval_versionr+rrs r|rH _DeprecatedGenericAlias.__init__s t? /r~c>SSKnURURSUR3URS9 [ TU]U5$)Nrrr)r _deprecatedrrDrrro)rr+rrs r|ro)_DeprecatedGenericAlias.__instancecheck__sJq -d6K6K  w(..r~)r)rrrrrHror!rrs@r|rrs8<400 //r~rc.^\rSrSrU4SjrSrSrU=r$)_CallableGenericAliasic ,>URS:XdeURn[U5S:Xa![US5(a[TU]5$SSR USSVs/sHn[U5PM sn5S[US5S3$s snf) Nrrrztyping.Callable[[rrz], r)rDrrrrrrr)rrr*rs r|r_CallableGenericAlias.__repr__szzZ'''}} t9>nT!W557#% %YYtCRyAy! 1 yABC3d2h'(+ ,As#B cURn[U5S:Xa[US5(d[USS5US4n[R [ U44$)Nrrr)rrrrr2rGrrts r|r\ _CallableGenericAlias.__reduce__sR}}D Q>$q'#:#:Sb ?DH,D(D!111r~r)rrrrrr\r!rrs@r|rrs,22r~rc0\rSrSrSrSr\S5rSrg) _CallableTypeicV[URUURURS9$rs)rrrDr-rs r|r4_CallableType.copy_withs&$T__f*.**4::G Gr~c[U[5(a[U5S:wa [S5eUup#[U[5(a[U5U4nOX#4nUR U5$)Nrz6Callable must be used as Callable[[arg, ...], result].)ryrrrr__getitem_inner__)rrrr3s r|rx_CallableType.__getitem__sh&%((CK1,<<= =  dD ! !Dk6*F^F%%f--r~cUup#Sn[X45nU[LaUR[U45$[ U[ 5(dU4n[ SU55nX#4-nURU5$)Nz.Callable[args, result]: result must be a type.c38# UHn[U5v M g7frrr&s r|r2_CallableType.__getitem_inner__..s84C]3''4r)rEllipsisr4rUryr)rrrr3rs r|r_CallableType.__getitem_inner__sq >V) 8 >>?F";< <$&&7D8488 !~~f%%r~rN) rrrrr4rxr rr!rr~r|rrs!G . & &r~rc$\rSrSr\S5rSrg) _TupleTypeic^[U[5(dU4n[U5S:a<USSLa4Sm[U4SjUSS55nUR/UQ[P75$Sm[U4SjU55nURU5$)Nrr.z Tuple[t, ...]: t must be a type.c3<># UHn[UT5v M g7frrrs r|r)_TupleType.__getitem__..sD 1;q#.. rz*Tuple[t0, t1, ...]: each t must be a type.c3<># UHn[UT5v M g7frrrs r|rrrr)ryrrr4rU)rrrs @r|rx_TupleType.__getitem__s&%((YF v;! r c 14CDs DDF>>"[[UR55$r)r frozensetrrs r|r_UnionGenericAlias.__hash__sIdmm,--r~c>URn[U5S:XaFUS[S5LaS[US5S3$US[S5LaS[US5S3$[TU]5$)Nrrztyping.Optional[rr)rrrxrrrrrrs r|r_UnionGenericAlias.__repr__sw}} t9>Aw$t*$)*T!W*=)>a@@aDJ&)*T!W*=)>a@@w!!r~cNURHn[X5(dM g gNTF)rry)rrr{s r|ro$_UnionGenericAlias.__instancecheck__#==C###!r~cNURHn[X5(dM g gr)rr7)rrr{s r|rt$_UnionGenericAlias.__subclasscheck__rr~c>>[TU]5unup#U[U44$r)rr\r)rrr.rrs r|r\_UnionGenericAlias.__reduce__s&$w13nveT]""r~r) rrrrr4rrrrortr\r!rrs@r|rrs,J."  ##r~rcSU5$)Nc3:# UHo[U54v M g7fr)rxrs r|r'_value_and_type_iter.. s -*QQL*rr)rs r|rr s -* --r~c \rSrSrSrSrSrg)ric[U[5(d[$[[ UR 55[[ UR 55:H$r)ryrrr rrrds r|r_LiteralGenericAlias.__eq__sB%!566! !' 673?STYTbTb?c;dddr~cP[[[UR555$r)rrrrrs r|r_LiteralGenericAlias.__hash__sI24==ABCCr~rN)rrrrrrr!rr~r|rrse Dr~rc(^\rSrSrU4SjrSrU=r$)ric>[US[[45(a /USSQUSQ7$[US[5(a/USSQUSRQ7n[ TU]U5$)Nr)ryrrrrrr4)rrrs r|r4"_ConcatenateGenericAlias.copy_withss fRj4- 0 0.VCR[.6":. . fRj": ; ;9vcr{9VBZ%8%89Fw ((r~r)rrrrr4r!rrs@r|rrs ))r~rc2[XS35n[X4S9$)aqType unpack operator. The type unpack operator takes the child types from some container type, such as `tuple[int, str]` or a `TypeVarTuple`, and 'pulls them out'. For example:: # For some generic class `Foo`: Foo[Unpack[tuple[int, str]]] # Equivalent to Foo[int, str] Ts = TypeVarTuple('Ts') # Specifies that `Bar` is generic in an arbitrary number of types. # (Think of `Ts` as a tuple of an arbitrary number of individual # `TypeVar`s, which the `Unpack` is 'pulling out' directly into the # `Generic[]`.) class Bar(Generic[Unpack[Ts]]): ... Bar[int] # Valid Bar[int, str] # Also valid From Python 3.11, this can also be done using the `*` operator:: Foo[*tuple[int, str]] class Bar(Generic[*Ts]): ... And from Python 3.12, it can be done using built-in syntax for generics:: Foo[*tuple[int, str]] class Bar[*Ts]: ... The operator can also be used along with a `TypedDict` to annotate `**kwargs` in a function signature:: class Movie(TypedDict): name: str year: int # This function expects two keyword arguments - *name* of type `str` and # *year* of type `int`. def foo(**kwargs: Unpack[Movie]): ... Note that there is only some runtime checking of this operator. Not everything the runtime allows may be accepted by static type checkers. For more information, see PEPs 646 and 692. r)r.r)r_UnpackGenericAliasrs r|rrrr"s$^ zV+E#F GD d 99r~cN^\rSrSrSrU4Sjr\S5r\S5rSr U=r $)riUc:S[URS5S3$)Nztyping.Unpack[rr)rrrs r|r_UnpackGenericAlias.__repr__Vs" 4==+; <=Q??r~cH>UR(aU$[TU] U5$r)rrrxrs r|rx_UnpackGenericAlias.__getitem__[s!  3 3Kw"4((r~cUR[Lde[UR5S:XdeURun[ U[ [ R45(a*UR[La [S5eUR$g)Nrz*Unpack[...] must be used with a tuple type) rrrrrryrrr rrrs r|r2_UnpackGenericAlias.__typing_unpacked_tuple_args__`ss&(((4==!Q&&&}} cM5+=+=> ? ?~~U* LMM<< r~cUR[Lde[UR5S:Xde[ URS[ 5$ry)rrrrrryr rs r|r7_UnpackGenericAlias.__typing_is_unpacked_typevartuple__ksA&(((4==!Q&&&$--*L99r~r) rrrrrrxpropertyrrr!rrs@r|rrUs6@ ) ::r~rc\rSrSrSrSrg)rUirz(Internal placeholder for ... (ellipsis).rN)rrrrr?r!rr~r|rUrUrs2r~rU> _is_protocolrr1r__type_params____protocol_attrs___is_runtime_protocol__non_callable_proto_members__>r?rrrHr rr9__match_args____annotations__r__subclasshook____class_getitem____abstractmethods__r!_MutableMapping__markerc[5nURSSHonURS;aM[US05n/URQUQ7H8nUR S5(aMU[ ;dM'URU5 M: Mq U$)zCollect protocol members from a protocol class objects. This includes names actually defined in the class dictionary, as well as names that appear in annotations. Special names (above) are skipped. Nr>rrr_abc_)r __mro__rrrrEXCLUDED_ATTRIBUTESadd)rattrsr annotationsr&s r|_get_protocol_attrsrs EE CR  ==3 3 d$5r: 2dmm2k2D??7++Nrr)r)rs r|_allow_reckless_class_checksrs 5>7 77r~) rr1r&r'r3r2r$r/r"r5r8BufferAbstractContextManagerAbstractAsyncContextManager)zcollections.abc contextlibcSSKJn U$)Nrgetattr_static)inspectr r s r|_lazy_load_getattr_staticrs ' r~c([UR44$r)rr)psargss r|_pickle_psargsrs 6,,. ..r~c([UR44$r)rr)pskwargss r|_pickle_pskwargsrs X002 22r~cD[U[5(d [S5eg)aRaise TypeError if `arg` is not an instance of `type` in `issubclass(arg, )`. In most cases, this is verified by type.__subclasscheck__. Checking it again unnecessarily would slow down issubclass() checks, so, we don't perform this check unless we absolutely have to. For various error paths, however, we want to ensure that *this* error message is shown to the user where relevant, rather than a typing.py-specific error message. z"issubclass() arg 1 must be a classN)ryrxrrs r|_type_check_issubclass_arg_1rs" c4 <== !r~c@^\rSrSrU4SjrU4SjrSrSrSrU=r $) _ProtocolMetaic b>US:Xa U[4:XaO[U;aUH{nU[[1;aMUR[R UR /5;aME[U[5(a[USS5(aMn[SU<35e [TU],"XX#40UD6$)NrrFz5Protocols can only inherit from other protocols, got ) rrrr_PROTO_ALLOWLISTrrr7rrrr)mclsrrR namespacerrrs r|r_ProtocolMeta.__new__s : %G:"5   VW--}}(8(<([TU]"U0UD6 [USS5(a[U5Ulgg)NrF)rrHrrrrs r|rH_ProtocolMeta.__init__s6 $)&) 3 . .%8%=C " /r~cU[La[RX5$[USS5(a[ 5(d[USS5(d[ U5 [ S5eUR(a]URRS5[La;[ U5 [UR5n[ S[U5SSS 35e[X5$) NrFrLInstance and class checks can only be used with @runtime_checkable protocolsrzRProtocols with non-method members don't support issubclass(). Non-method members: rrr)rrxrtrrrrrrr _proto_hooksortedrz_abc_subclasscheck)rrenon_method_attrss r|rt_ProtocolMeta.__subclasscheck__s (?))#5 5 C / /0223 6>>,U33 22LL$$%78KG,U3#)#*L*L#M ,,/0@,A!B,G+HK"#--r~cU[La[RX5$[USS5(d [ X5$[USS5(d[ 5(d [ S5e[ X5(ag[5nURH"nU"X5nUbMX0R;dM" g g![a  gf=f)NrFrr"T) rrxror_abc_instancecheckrrrrrKr)rinstancer r&rGs r|ro_ProtocolMeta.__instancecheck__8s (?))#8 8sNE22%c4 43U;;,..<= = c , ,24**D $X4{t+M+MM+ "  sB66 CCr) rrrrrrHrtror!rrs@r|rrsG&> .4r~rcURRSS5(d[$URHnURHnX#R;aURUc [s s $ M>[ US05n[ U[RR5(dMgX$;dMn[U[5(dM[ USS5(dM M [s $ g)NrFrT) rrrrrrryrrr)r7r)rrer&rrs r|r#r#Zs <<  NE 2 2&&MMD}}$==&.))"$(92>K; (?(?@@'ug..75.RW3X3X"" !' r~c8^\rSrSrSrSrSrSrU4SjrSr U=r $)rira Base 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.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... rTFcV>[TU]"U0UD6 URRSS5(d![ SUR 55UlSUR;a [UlUR (a*UR[RLa [Ul ggg)NrFc30# UH o[Lv M g7frrrr<s r|r-Protocol.__init_subclass__..s"H-Q=-sr) rr=rrr:rrr#rrHrrrs r|r=Protocol.__init_subclass__s !4262||66""H#--"HHC  S\\ 1#.C     0A0A A3CL!B r~) rrrrr?r rrr=r!rrs@r|rrrs%@IL  4 4r~rc\^\rSrSrSrU4SjrSrSrSrSr Sr U4S jr S r S r U=r$) _AnnotatedAliasialRuntime 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. The metadata itself is stored in a '__metadata__' attribute as a tuple. c>[U[5(aURU-nURn[TU]XSS9 X lg)Nrr)ryr5 __metadata__rrrH)rr.metadatars r|rH_AnnotatedAlias.__init__sC fo . .**X5H&&F k:$r~cX[U5S:XdeUSn[X R5$ry)rr5r7)rrnew_types r|r4_AnnotatedAlias.copy_withs.6{a!9x):):;;r~cSR[UR5SRSUR555$)Nztyping.Annotated[{}, {}]rc38# UHn[U5v M g7fr)rrs r|r+_AnnotatedAlias.__repr__..s9'8!d1gg'8r)formatrrrr7rs r|r_AnnotatedAlias.__repr__s9)00 t ' II9t'8'89 9  r~cb[R[UR4UR-44$r)r2rGrrr7rs r|r\_AnnotatedAlias.__reduce__s1 )D,=,=="   r~c[U[5(d[$URUR:H=(a URUR:H$r)ryr5rrr7rds r|r_AnnotatedAlias.__eq__sE%11! !5#3#33<%%););; =r~cD[URUR45$r)rrr7rs r|r_AnnotatedAlias.__hash__sT__d&7&7899r~c0>US;ag[TU]U5$)N>rrr)rrMrPs r|rM_AnnotatedAlias.__getattr__s / /w"4((r~cUR4$r)rrQs r|rS_AnnotatedAlias.__mro_entries__s!!r~)r7)rrrrr?rHr4rr\rrrMrSr!rrs@r|r5r5s5%<   = :) ""r~r5c[U5S:a [S5e[US5(a [S5eSn[USUSS9n[ USS 5n[ X45$) aAdd context-specific metadata to a type. Example: Annotated[int, runtime_check.Unsigned] indicates to the hypothetical runtime_check module that this type is an unsigned int. Every other consumer of this type can ignore this metadata and treat this type as int. The first argument to Annotated must be a valid type. Details: - It's an error to call `Annotated` with less than two arguments. - Access the metadata via the ``__metadata__`` attribute:: assert Annotated[int, '$'].__metadata__ == ('$',) - Nested Annotated types are flattened:: assert Annotated[Annotated[T, Ann1, Ann2], Ann3] == Annotated[T, Ann1, Ann2, Ann3] - Instantiating an annotated type is equivalent to instantiating the underlying type:: assert Annotated[C, Ann1](5) == C(5) - Annotated can be used as a generic type alias:: type Optimized[T] = Annotated[T, runtime.Optimize()] # type checker will treat Optimized[int] # as equivalent to Annotated[int, runtime.Optimize()] type OptimizedList[T] = Annotated[list[T], runtime.Optimize()] # type checker will treat OptimizedList[int] # as equivalent to Annotated[list[int], runtime.Optimize()] - Annotated cannot be used with an unpacked TypeVarTuple:: type Variadic[*Ts] = Annotated[*Ts, Ann1] # NOT valid This would be equivalent to:: Annotated[T1, T2, T3, ..., Ann1] where T1, T2 etc. are TypeVars, which would be invalid, because only one type should be passed to Annotated. rzUAnnotated[...] should be used with at least two arguments (a type and an annotation).rz?Annotated[...] should not be used with an unpacked TypeVarTuplez$Annotated[t, ...]: t must be a type.TrsrN)rrrrrr5)rrrr.r8s r|rrswb 6{Q'( (!++01 1 0C CT BFVABZ H 6 ,,r~c|[U[5(a[USS5(d[SU-5eSUl[ 5UlURH=n[[XS55nU(dUR RU5 M=M? U$![an[SU<S35UeSnAff=f)a Mark a protocol class as a runtime protocol. Such protocol 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 one trick ponies in collections.abc such as Iterable. For example:: @runtime_checkable class Closable(Protocol): def close(self): ... assert isinstance(open('/some/file'), Closable) Warning: this will check only the presence of the required methods, not their type signatures! rFzB@runtime_checkable can be only applied to protocol classes, got %rTNz,Failed to determine whether protocol member z is a method member) r7rrrrr rrcallablerr2)rr& is_callablees r|rkrk s& c7 # #73+N+N"$'() )#C *-C&&& ="73d#;thG%%  sB B;%B66B;cU$)zCast a value to a type. This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don't check anything (we want this to be as fast as possible). r)rrGs r|rTrTC s  Jr~cU$)aAsk a static type checker to confirm that the value is of the given type. At runtime this does nothing: it returns the first argument unchanged with no checks or side effects, no matter the actual type of the argument. When a static 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 r)rGrs r|rRrRN s  Jr~c[USS5(a0$[U[5(GaP0n[UR5HnUc6[[ R RURS5S05nOUnURRS05n[U[R5(a0nUc[[U55OUnUcUcXpUR5HMupU c [S5n [U [5(a [!U SSS9n [#XXR$5n XU 'MO M U(aU$UR5V V s0sHupU ['U 5_M sn n $Ucq[U[R(5(a URnO?Un [+U S5(aU R,n [+U S5(aM[U S 05nUcUnOUcUn[USS5nUc1[U[.5(a0$[1S R3U55e[U5n[US S 5nUR5H^upU c [S5n [U [5(a([!U [U[R(5(+SS9n [#XX.5XI'M` U(aU$UR5V V s0sHupU ['U 5_M sn n $s sn n fs sn n f) aReturn type hints for an object. This is often the same as obj.__annotations__, but it handles forward references encoded as string literals 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. For classes, the search order is globals first then locals. - 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. __no_type_check__NrrFT)rrw __wrapped__ __globals__z1{!r} is not a module, class, method, or function.rr)rryrxreversedrrrrrrrGetSetDescriptorTypervarsitemsrzrr)r_strip_annotations ModuleTyperrU_allowed_typesrr@)rr+r,include_extrashintsr base_globalsann base_localsrvaluerrnsobjr-s r|r\r\c s>s'.. #tS[[)D&s{{t'Mz[]^ ' --##$5r:C#u99::.5o$tDz*7K8#3-8k"yy{ = JEeS))&u%$OE"5 EYEYZ#d +#*0'u`RWR]R]R_,`R_$!Q0B10E-ER_,`` c5++ , ,||HE%//))%//umR8H ?G  C*D 1E } c> * *I++16#;8 8 KE#0"5K{{}  =JE eS ! ! *30@0@ AAE !'G %#5\ekkm(\mda,>q,A)Am(\\K-aJ)]s K7K=c"[U[5(a[UR5$[ US5(a7UR[ [ [4;a[URS5$[U[5(a>[SUR55nXR:XaU$URU5$[U[5(aC[SUR55nXR:XaU$[URU5$[U[R5(aR[SUR55nXR:XaU$[R "["R$U5$U$)z(Strip the annotations from a given type.rrc38# UHn[U5v M g7frr[rs r|r%_strip_annotations.. HZ033Zrc38# UHn[U5v M g7frrgrs r|rrh rirc38# UHn[U5v M g7frrgrs r|rrh rir)ryr5r[rrrirerhrrrr4r rrrr1r2r3)r stripped_argss r|r[r[ s !_%%!!,,//q,ALLX{H4U$U!!**Q-00!]##HQZZHH JJ &H{{=))!\""HQZZHH JJ &HALL-88!U__%%HQZZHH JJ &H m<< Hr~c[U[5(a[$[U[[[ [ 45(a UR$U[La[$[U[R5(a[R$g)a[Get the unsubscripted version of a type. This supports generic types, Callable, Tuple, Union, Literal, Final, ClassVar, Annotated, and others. Return None for unsupported types. Examples:: >>> P = ParamSpec('P') >>> assert get_origin(Literal[42]) is Literal >>> assert get_origin(int) is None >>> assert get_origin(ClassVar[int]) is ClassVar >>> assert get_origin(Generic) is Generic >>> assert get_origin(Generic[T]) is Generic >>> assert get_origin(Union[T, int]) is Union >>> assert get_origin(List[Tuple[T, T]][int]) is list >>> assert get_origin(P.args) is P N) ryr5rr)r rrrrrrtps r|rYrY si$"o&&"(,$o788}} W}"eoo&& r~cP[U[5(aUR4UR-$[U[[ 45(a1UR n[X5(a[USS5US4nU$[U[R5(a UR $g)aGet type arguments with all substitutions performed. For unions, basic simplifications used by Union constructor are performed. Examples:: >>> T = TypeVar('T') >>> assert get_args(Dict[str, int]) == (str, int) >>> assert get_args(int) == () >>> assert get_args(Union[int, Union[T, int], str][int]) == (int, str) >>> assert get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) >>> assert get_args(Callable[[], T][int]) == ([], int) Nrr) ryr5rr7rr rrrrr)ror;s r|rXrX s"o&& "//11"}l344kk *2 3 3CR>3r7+C "eoo&&{{ r~c"[U[5$)zCheck if an annotation is a TypedDict class. For example:: >>> from typing import TypedDict >>> class Film(TypedDict): ... title: str ... year: int ... >>> is_typeddict(Film) True >>> is_typeddict(dict) False )ryrrns r|r^r^ s b. ))r~dr{cr[U5n[U5[:a US[S-n[SU35e)aStatically assert 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. Nrz*Expected code to be unreachable, but got: )rr_ASSERT_NEVER_REPR_MAX_LENGTHAssertionError)r{rcs r|rSrS- s@& IE 5z11445= EeWM NNr~c:[U[5(a[U5Hn[X5n[ US5(aDUR UR SUR 3:wd[USS5UR:waMe[U[R5(aSUl [U[R5(aSURl [U[5(dM[U5 M SUl U$![a U$f=f)a5Decorator to indicate that annotations are not type hints. The argument must be a class or function; if it is a class, it applies recursively to all methods and classes defined in that class (but not to methods defined in its superclasses or subclasses). This mutates the function(s) or class(es) in place. rrrNT)ryrxrOrrrrrrrrT MethodType__func__rbr)r{keyrs r|rbrbF s#ts8C##CC00###*:*:);1S\\N'KK3 d3s~~E #u1122(,%#u//0015 .#t$$c"%& $ J   J sD DDcn^SSKnURSSS9 [R"T5U4Sj5nU$)zDecorator to give another decorator the @no_type_check effect. This wraps the decorator with something that wraps the decorated function in @no_type_check. rNztyping.no_type_check_decoratorrrc.>T"U0UD6n[U5nU$r)rb)rrrr s r|wrapped_decorator2no_type_check_decorator..wrapped_decoratorr s!$'$'T" r~)rrrr)r rr~s` r|rcrcj s?  9'J__Y  r~c[S5e)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.)NotImplementedError)rrs r|_overload_dummyr{ s  9 ::r~c[USU5nU[URURURR '[$![ a [$f=f)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:: @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. rx)r_overload_registryrr__code__co_firstlinenorKr)rfs r|rfrf sa@ j$'A VZ1<<(89R9RS     s7A AAc[USU5nUR[;a/$[URnURU;a/$[ X!RR 55$)z6Return all defined overloads for *func* as a sequence.rx)rrrrrvalues)rrmod_dicts r|rZrZ s^ j$'A||-- !!,,/H~~X% (//1 22r~c,[R5 g)z$Clear all overloads in the registry.N)rclearrr~r|rUrU sr~cDSUlU$![[4a U$f=f)aDecorator to indicate final methods and final classes. Use this decorator 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 attempts to set the ``__final__`` attribute to ``True`` on the decorated object to allow runtime introspection. T) __final__rKr)rs r|rWrW s54  H I &  H   TKTVTT_co) covariantV_coVT_coT_contra) contravariantCT_co)rboundrQraDeprecated alias to collections.abc.Callable. Callable[[int], str] signifies a function that takes a single parameter of type int and returns a str. The subscription syntax must always be used with exactly two values: the argument list and the return type. The argument list must be a list of types, a ParamSpec, Concatenate or ellipsis. The return type must be a single type. There is no syntax to indicate optional or keyword arguments; such function types are rarely used as callback types. r r)r)rrrr*a]Deprecated alias to builtins.tuple. Tuple[X, Y] is the cross-product type of X and Y. Example: Tuple[T1, T2] is a tuple of two elements corresponding to type variables T1 and T2. Tuple[int, float, str] is a tuple of an int, a float and a string. To specify a variable-length tuple of homogeneous type, use Tuple[T, ...]. rErBrGrHrCrD)rraDeprecated alias to builtins.type. builtins.type or typing.Type can be used 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:: def new_user[U](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. c4\rSrSrSrSr\S\4Sj5rSr g)r>iV z(An ABC with one abstract method __int__.rr cgrrrs r|__int__SupportsInt.__int__\  r~N) rrrrr?r rintrr!rr~r|r>r>V s#2I   r~r>c4\rSrSrSrSr\S\4Sj5rSr g)r<ia z*An ABC with one abstract method __float__.rr cgrrrs r| __float__SupportsFloat.__float__g rr~N) rrrrr?r rfloatrr!rr~r|r<r<a #4I 5  r~r<c4\rSrSrSrSr\S\4Sj5rSr g)r;il z,An ABC with one abstract method __complex__.rr cgrrrs r| __complex__SupportsComplex.__complex__r rr~N) rrrrr?r rcomplexrr!rr~r|r;r;l s#6I W  r~r;c4\rSrSrSrSr\S\4Sj5rSr g)r:iw z*An ABC with one abstract method __bytes__.rr cgrrrs r| __bytes__SupportsBytes.__bytes__} rr~N) rrrrr?r rbytesrr!rr~r|r:r:w rr~r:c4\rSrSrSrSr\S\4Sj5rSr g)r=i z*An ABC with one abstract method __index__.rr cgrrrs r| __index__SupportsIndex.__index__ rr~N) rrrrr?r rrrr!rr~r|r=r= s#4I 3  r~r=c@^^S7=m4m"UU4SjST7 n[U5$)rc>>\rSrSrYrSrSr\SY4Sj5rSr g)r9i zMAn ABC with one abstract method __abs__ that is covariant in its return type.rr cgrrrs r|__abs__SupportsAbs.__abs__ rr~N) rrrrrr?r rrr! .type_paramsrsr|r9r9 s&WI   r~r9r0 .generic_baserrs @@r|#r s  X r~c@^^S7=m4m"UU4SjST7 n[U5$)rcF>\rSrSrYrSrSr\SS\SY4Sjj5r Sr g) r?i zOAn ABC with one abstract method __round__ that is covariant in its return type.rndigitsr cgrr)rrs r| __round__SupportsRound.__round__ rr~Nr) rrrrrr?r rrrr!rsr|r?r? s-YI  Q  r~r?r0rs @@r|%r s  x r~rc UVVs/sHupEUPM nnnUVVs0sHupEU[USUS35_M nnn[R"XX2S9nU=UlURlU$s snnfs snnf)Nzfield z annotation must be a typerrv)rr namedtuplerr)rrrvrnrfieldsnm_tpls r| _make_nmtupler s! "EDAaEF "  As*DEF F   # #D-5FF>CCFV^^; M # s A+A1> _maker_asdict_fields_sourcerH_replacer __getnewargs___field_defaults>rrrc\rSrSrSrSrg)NamedTupleMetai c [U;deUH"nU[LdMU[LdM[S5e [SU55nUR S05n/nUHVnXs;aUR U5 MU(dM$[SUS[ U5S:aSOSS S RU535e [XR"5UVs/sHoUPM snUS S 9n X)l [U;a[n [U 5U l UR5HdupU [;a[S U -5eU [ ;dM)XR";a [%XU 5 ['U 5R(n U "XU 5 Mf [U;aU R15 U $s snf![*a6nUR-S['U 5R.<SU <SU<35 eSnAff=f![a Mf=f)Nz3can only inherit from a NamedTuple type and Genericc3B# UHo[La[OUv M g7fr) _NamedTupler)rrs r|r)NamedTupleMeta.__new__.. sO{2e<rzNon-default namedtuple field z cannot follow default fieldrsr rrrz&Cannot overwrite NamedTuple attribute zError calling __set_name__ on z instance z in )rrrrrrrrrrZrr classmethodr _prohibitedrK_specialrrFrx __set_name__ BaseExceptionadd_noterr=)rtypenamerRnsrr default_names field_namerr class_getitemryrGset_namerPs r|rNamedTupleMeta.__new__ se###D;&4w+>IKKOOO("- J$$Z0"? |L>*-m*??  x8E(F 1A (F&(&68! e 2M'2='AF $ HCk!$%MPS%STTH$nn,F- #Cy55H c2#( e   $ $ & ;)G() (VDG,   O  B  J (>(VDG,   O CD D fn-wW x :B# B Ir~rIc([U;de[4$r)rIrrRs r|_namedtuple_mro_entriesr( s    >r~c#&# [U5nU[La[U5nU(aUSnO_gU[La[v [U5unO?U[La[v [U5unO U[ La[ v [U5unOgM7f)Nr)rYrrXrirerh)annotation_typeannotation_originannotation_argss r|_get_typeddict_qualifiersr/ s &7  )&7O"1!"4 ( *N!)/!: _ + - !)/!: _ ( *N!)/!: _ % sBBc,\rSrSrSSjr\rSr\rSr g)riE c UH+n[U5[LdMU[LdM"[S5e [ SU55(a[4nOSn[R [U/UQ[ P7U5n[US5(dX'l0nURS05n Sn U R5V V s0sHupU [XURS9_M n n n [5n [5n[5n[5nUHnURURRS055 URRS[55nU U-n UU-nURRS [55nU U-n UU-nURURRS S55 URURRS S55 M URU 5 U R5Hunn[[!U55n["U;aS nO[$U;aS nOUnU(a#U R'U5 UR)U5 O"UR'U5 U R)U5 [*U;a)UU;a[SU<S35eUR'U5 MUR'U5 UR)U5 M U R-U5(dSUSU <SU<35eXl[1U 5Ul[1U5Ul[1U5Ul5UlXGlU$s sn n f)aCreate a new typed dict class object. This method is called when TypedDict is subclassed, or when TypedDict is instantiated. This way TypedDict supports all three syntax forms described in its docstring. Subclasses and instances of TypedDict return actual dictionaries. zHcannot inherit from both a TypedDict type and a non-TypedDict base classc3B# UHn[U[5v M g7fr)r7rr1s r|r)_TypedDictMeta.__new__..S s5u!z!W%%urrrrz?TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a typer__required_keys____optional_keys____readonly_keys____mutable_keys__TFzCannot override mutable key z with read-only keyz,Required keys overlap with optional keys in z: required_keys=z, optional_keys=)rxrrrr:rrrrrrZrrr updaterrrirerdiscardrh isdisjointrrrrrr __total__)rrrRrtotalr generic_basetp_dictrown_annotationsrrro required_keys optional_keys readonly_keys mutable_keys base_required base_optionalannotation_keyr qualifiers is_requireds r|r_TypedDictMeta.__new__F s=DDz/D4G!ABB 5u5 5 5#:LL,,~t5J|5JT5JBOw 011%* " &&!2B7O)..0 0 {27+=+=> >0     u D   t}}001BBG H MM--.A35IM ] *M ] *M MM--.A35IM ] *M ] *M  !2!23F!K L    1 12Db I J ?+/>/D/D/F +NO6GHJ:%"  *# # !!.1%%n5!!.1%%n5:%!\1#6~6H-.!!.1  0%%n530G6'' 66 :4&A0-!1 3 6#.$-m$<!$-m$<!$-m$<!#,\#: !{ s8!Mc[S5e)Nz4TypedDict does not support instance and class checksr<)rres r|rt _TypedDictMeta.__subclasscheck__ sNOOr~rN)T) rrrrrrr`rtror!rr~r|rrE sWrHP*r~rr cU[LdUc6SSKnU[LaSnOSnSUSU<S3nSU-S -nURXFS S 9 0nS [U50n[ 5nUbXS '[ USXrS9n [ 4U lU $)aA simple typed namespace. At runtime it is equivalent to a plain dict. TypedDict creates a dictionary type such that a type checker will expect all instances to have a certain set of keys, where each key is associated with a value of a consistent type. This expectation is not checked at runtime. 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 >>> Point2D(x=1, y=2, label='first') == dict(x=1, y=2, label='first') True The type info can be accessed via the Point2D.__annotations__ dict, and the Point2D.__required_keys__ and Point2D.__optional_keys__ frozensets. TypedDict supports an additional equivalent form:: Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str}) By default, all keys must be present in a TypedDict. It is possible to override this by specifying totality:: class Point2D(TypedDict, total=False): x: int y: int This means that a Point2D TypedDict can have any of the keys omitted. A type checker is only expected to support a literal False or True as the value of the total argument. True is the default, and makes all items defined in the class body be required. The Required and NotRequired special forms can also be used to mark individual keys as being required or not required:: class Point2D(TypedDict): x: int # the "x" key must always be present (Required is the default) y: NotRequired[int] # the "y" key can be omitted See PEP 655 for more details on Required and NotRequired. The ReadOnly special form can be used to mark individual keys as immutable for type checkers:: class DatabaseUser(TypedDict): id: ReadOnly[int] # the "id" key must not be modified username: str # the "username" key can be changed Nrrrrz = TypedDict(z, {{}})`z{name} is deprecated and will be disallowed in Python {remove}. To create a TypedDict class with 0 fields using the functional syntax, pass an empty dictionary, e.g. rr{rrrrr)r.rrrrrrJr) rrr rrrrrrvtds r|rJrJ snfn Y S I hZ}XL E .     -wW T&\ *B YF !< "b 6B" B Ir~rJc[4$r) _TypedDictrs r|r  s:-r~cJ[XRS35n[X45$)aSpecial typing construct to mark a TypedDict key as required. This is mainly useful for total=False TypedDicts. 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.  accepts only a single type.rrDrrs r|riri s'( zjj\1M#N OD w ''r~cJ[XRS35n[X45$)aSpecial typing construct to mark a TypedDict key 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, ) r"r#rs r|rere s' zjj\1M#N OD w ''r~cJ[XRS35n[X45$)aXA special typing construct to mark an item of a TypedDict as read-only. For example:: class Movie(TypedDict): title: ReadOnly[str] year: int def mutate_movie(m: Movie) -> None: m["year"] = 1992 # allowed m["title"] = "The Matrix" # typechecker error There is no runtime checking for this property. r"r#rs r|rhrh* s' zjj\1M#N OD w ''r~c@\rSrSrSr\rSrSrSr Sr Sr Sr S r g ) rai> aNewType 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 callable 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 cXlSU;aURS5SnXlX l[ 5nUS:waX0lgg)Nrrtyping)r rpartitionr __supertype__rr)rrrodef_mods r|rHNewType.__init__V sF  $;??3'+D ) h %O r~c<^URm"U4SjS5nU4$)Nc">\rSrSrU4SjrSrg)&NewType.__mro_entries__..Dummyie c H>URn[SUSU<STS35e)NzGCannot subclass an instance of NewType. Perhaps you were looking for: `z = NewType(rz)`)rr)r subclass_namesuperclass_names r|r=8NewType.__mro_entries__..Dummy.__init_subclass__f s: # %k-1B"_DUUWYr~rN)rrrrr=r!)r2sr|Dummyr/e s   r~r4)r)rrRr4r2s @r|rSNewType.__mro_entries__` s!--  xr~c8URSUR3$)Nr)rrrs r|rNewType.__repr__o s//"!D$5$5#677r~cUR$r)rrs r|r\NewType.__reduce__r s   r~c[X4$rrcrds r|rfNewType.__or__u rhr~c[X4$rrcrds r|rjNewType.__ror__x rlr~)rrrr*N)rrrrr?r r`rHrSrr\rfrjr!rr~r|rara> s,*H& 8!""r~racJ\rSrSrSrSr\\S\4Sj55r \\S\4Sj55r \S"Sj5r \\S\ 4S j55r \S\4S j5r\S"S j5r\S\ 4S j5r\S#S \S\4Sjj5r\S\ 4Sj5r\S#S\S\4Sjj5r\S#S\S\\4Sjj5r\S$S\S\S\4Sjj5r\S\ 4Sj5r\S\4Sj5r\S%S\S\4Sjj5r\S\ 4Sj5r\S\S\4Sj5r\S\\SS4Sj5r\S&S j5r\S"S!j5r Sr!g)'rMi aGeneric base class for TextIO and BinaryIO. This is an abstract, generic version of the return of open(). NOTE: This does not distinguish between the different possible classes (text vs. binary, read vs. write vs. read/write, append-only, unbuffered). The TextIO and BinaryIO subclasses below capture the distinctions between text vs. binary, which is pervasive in the interface; however we currently do not offer a way to track the other distinctions in the type system. rr cgrrrs r|modeIO.mode  r~cgrrrs r|rIO.name rBr~Ncgrrrs r|closeIO.close rr~cgrrrs r|closed IO.closed rBr~cgrrrs r|fileno IO.fileno rr~cgrrrs r|flushIO.flush rr~cgrrrs r|isatty IO.isatty rr~rcgrr)rrs r|readIO.read rr~cgrrrs r|readable IO.readable rr~limitcgrr)rrZs r|readline IO.readline rr~hintcgrr)rr^s r| readlines IO.readlines rr~offsetwhencecgrr)rrbrcs r|seekIO.seek rr~cgrrrs r|seekable IO.seekable rr~cgrrrs r|tellIO.tell rr~sizecgrr)rrms r|truncate IO.truncate rr~cgrrrs r|writable IO.writable rr~rcgrrrrs r|writeIO.write rr~linescgrr)rrxs r| writelines IO.writelines rr~cgrrrs r| __enter__ IO.__enter__ rr~cgrr)rrxrc tracebacks r|__exit__ IO.__exit__ rr~)r N)rrr)r z IO[AnyStr])"rrrrr?r rrrzr@rrFboolrIrrLrOrRrQrUrXr\rEr`rerhrkrorrrvrzr}rr!rr~r|rMrM sd I  c   c                c 6   $   c 6   c 4<   3  C   $   c   S C   $   v #   V        r~rMcV\rSrSrSrSr\S\\\ 4S\ 4Sj5r \S Sj5r Sr g) rLi z5Typed version of the return of open() in binary mode.rrr cgrrrus r|rvBinaryIO.write rr~cgrrrs r|r}BinaryIO.__enter__ rr~N)r rL)rrrrr?r rrr bytearrayrrvr}r!rr~r|rLrL sH?I uUI-. 3    r~rLc\rSrSrSrSr\\S\4Sj55r \\S\ 4Sj55r \\S\ \ 4Sj55r \\S\4Sj55r\\S\4S j55r\S S j5rSrg ) rPi z3Typed version of the return of open() in text mode.rr cgrrrs r|buffer TextIO.buffer rBr~cgrrrs r|encodingTextIO.encoding rBr~cgrrrs r|errors TextIO.errorsrBr~cgrrrs r|line_bufferingTextIO.line_buffering rBr~cgrrrs r|newlinesTextIO.newlinesrBr~cgrrrs r|r}TextIO.__enter__rr~N)r rP)rrrrr?r rrrLrrzrrrrrrrr}r!rr~r|rPrP s=I     #          #    r~rPc"S7=n4SUSU4Sjs8$)rrr cd[S[U5R<3[RS9 U$)aAsk a static type checker to reveal the inferred type of an expression. 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 the argument unchanged. zRuntime type is )file)printrxrrstderrrs r|rjrjs* T#Y//2 3#**E Jr~r) .defaultsrs r|#rsr~c4^\rSrSrmU4Sj"5rSrUrg)_IdentityCallablei+c$>S7=n4SUSU4Sjs8$)rr{r cgrrrs r|r`_IdentityCallable.__call__,s r~r)rr __classdict__s r| 2_IdentityCallable.,s q  r~rN)rrrrr`r!__classdictcell__)rs@r|rr+s  r~r) eq_default order_defaultkw_only_defaultfrozen_defaultfield_specifiersrrrrr.rc (^^^^^^UUUUUU4SjnU$)aDecorator to mark an object as providing dataclass-like behaviour. The decorator can be applied to a function, class, or metaclass. Example usage with a decorator function:: @dataclass_transform() def create_model[T](cls: type[T]) -> type[T]: ... return cls @create_model class CustomerModel: id: int name: str On a base class:: @dataclass_transform() class ModelBase: ... class CustomerModel(ModelBase): id: int name: str On a metaclass:: @dataclass_transform() class ModelMeta(type): ... class ModelBase(metaclass=ModelMeta): ... class CustomerModel(ModelBase): id: int name: str The ``CustomerModel`` classes defined above will be treated by type checkers similarly to classes created with ``@dataclasses.dataclass``. For example, type checkers will assume these classes have ``__init__`` methods that accept ``id`` and ``name``. 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. - ``frozen_default`` indicates whether the ``frozen`` 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()``. - Arbitrary other keyword arguments are accepted in order to allow for possible future extensions. At runtime, this decorator records its arguments in the ``__dataclass_transform__`` attribute on the decorated object. It has no other runtime effect. See PEP 681 for more details. c$>TTTTTTS.UlU$)N)rrrrrr)__dataclass_transform__) cls_or_fnrrrrrrs r|r &dataclass_transform..decoratorws'$*., 0 - )r~r)rrrrrrr s`````` r|rVrV0sN   r~_Funcc [S[4$r)rrrr~r|rrsXc3h r~c&SS8=n4SUSU4Sjs8$)Fc[$r)rrr~r|rrsr~methodr cDSUlU$![[4a U$f=f)aIndicate that a method is intended to override a method in a base class. Usage:: class Base: def method(self) -> None: pass class Child(Base): @override def method(self) -> None: super().method() When this decorator is applied to a method, the type checker will validate that it overrides a method or attribute with the same name on a base class. This helps prevent bugs that may occur when a base class is changed without an equivalent change to a child class. There is no runtime checking of this property. The decorator attempts to set the ``__override__`` attribute to ``True`` on the decorated object to allow runtime introspection. See PEP 698 for details. T) __override__rKr)rs r|rgrgs62 " M I &  M  rr)rrs r| rsXX q  r~rocj[U[5=(a [USS5=(a U[:g$)zReturn True if the given type is a Protocol. Example:: >>> from typing import Protocol, is_protocol >>> class P(Protocol): ... def a(self) -> str: ... ... b: int >>> is_protocol(P) True >>> is_protocol(int) False rF)ryrxrrrns r|r]r]s0 2t  B .  (Nr~cj[U5(d[U<S35e[UR5$)aDReturn the set of members defined in a Protocol. Example:: >>> from typing import Protocol, get_protocol_members >>> class P(Protocol): ... def a(self) -> str: ... ... b: int >>> get_protocol_members(P) == frozenset({'a', 'b'}) True Raise a TypeError for arguments that are not Protocols. z is not a Protocol)r]rrrrns r|r[r[s1 r??2& 2344 R** ++r~c6US;aSSKn[[X5S5nOkUS;a&SSKn[[USU35SU[S-4S9nO?US :Xa"SSKnS nUR U[SS 9 [nO[S [<S U<35eU[5U'U$)zImprove the import time of the typing module. Soft-deprecated objects which are costly to create are only created on-demand here. >rNrOrNr>r#r7Abstractr)rr_collect_parameterszThe private _collect_parameters function is deprecated and will be removed in a future version of Python. Any use of private functions is discouraged and may break in the future.rzmodule z has no attribute ) re_aliasrr rrrrrrKrrz)r&rrr rrs r|rMrMs  ##WR&* : :WZ8D6):;QTUY\`U`Tbc & & ;   l-?A N&wxl2DTHMNNGIdO Jr~rr)r__main__)r)NNF)r)r?rrrrrcollections.abccopyregrr2rrrrrr _typingr r r r rrrrr__all__r}rrrrrrrrrrrrrrrr rzrrr.rr)r8rArr{rxrrrdr`rlr_rrrrrrrorrprqrrrrrrrrr"r'r)rrrrrrrrrrrrrrU_TYPING_INTERNALS_SPECIAL_NAMESrrrrrrrrrrrpicklerror)rtr%rrrr#rr5rrkrTrRrBuiltinFunctionTyperwr\r]r\r[rYrXr^rtrSrbrcrpartialrrrfrZrUrWrrrrrrrrrrQrr$r1r4r3r2r&r'r8r/r"r5rrGr r-r)r+r.r,r!rrrrEdequerBr rHr*r(r%r0rCrDrFrAr@rKNoneTyper6rr>r<r;r:r=r9r?rrrrrIrrrrSrrrJrrirerhrarmrnrMrLrPrjrrVrrgr]r[rMrr~r|rs ((# ^^   t n5PUB@ 02HL//dS>16/  A   U> KS KT K K 2;( y{( VFF((/6"TGTn  .24w-24j1"lM1"h 9-9-x'T  $$e&?&?""E$4$4'): [__00!4 +//**A . ;??,,a 0 KOO.. 2  dAE/[,,amD [,,a0 $$a ( +&& * ;??,,a5>>5>>:Z [  66U^^DUV dAE/ 2 (   H   h   H   H      DE  B C0T0f!*<|ll><R@ 5 ,`*T`*F )QdQf\\.+r2 > 7 ((.(($((&;";"~  ` ` F  r%y    RW  F&  ! CE QQQ Q  Q DIc(::C?@ QQQh  FD*,T,3,&r~