Let us walk on the 3-isogeny graph
|
Data Structures | |
class | _AnnotatedAlias |
class | _AnyMeta |
class | _ConcatenateForm |
class | _ConcatenateGenericAlias |
class | _DefaultMixin |
class | _ExtensionsSpecialForm |
class | _FinalForm |
class | _Immutable |
class | _LiteralForm |
class | _LiteralGenericAlias |
class | _NamedTupleMeta |
class | _ProtocolMeta |
class | _RequiredForm |
class | _Sentinel |
class | _SpecialForm |
class | _TypedDictMeta |
class | _TypeGuardForm |
class | _TypeVarLikeMeta |
class | _UnpackAlias |
class | _UnpackForm |
class | _UnpackSpecialForm |
class | Annotated |
class | Any |
class | Buffer |
class | NewType |
class | ParamSpec |
class | ParamSpecArgs |
class | ParamSpecKwargs |
class | Protocol |
class | SupportsAbs |
class | SupportsBytes |
class | SupportsComplex |
class | SupportsFloat |
class | SupportsIndex |
class | SupportsInt |
class | SupportsRound |
class | TypeAliasType |
class | TypeVar |
class | TypeVarTuple |
Variables | |
bool | PEP_560 = True |
GenericMeta = type | |
_marker = _Sentinel() | |
NoReturn = typing.NoReturn | |
T = typing.TypeVar('T') | |
KT = typing.TypeVar('KT') | |
VT = typing.TypeVar('VT') | |
T_co = typing.TypeVar('T_co', covariant=True) | |
T_contra = typing.TypeVar('T_contra', contravariant=True) | |
ClassVar = typing.ClassVar | |
Final = typing.Final | |
doc | |
final = typing.final | |
Literal = typing.Literal | |
_overload_dummy = typing._overload_dummy | |
overload = typing.overload | |
get_overloads = typing.get_overloads | |
clear_overloads = typing.clear_overloads | |
_overload_registry | |
Type = typing.Type | |
Awaitable = typing.Awaitable | |
Coroutine = typing.Coroutine | |
AsyncIterable = typing.AsyncIterable | |
AsyncIterator = typing.AsyncIterator | |
Deque = typing.Deque | |
ContextManager = typing.ContextManager | |
AsyncContextManager = typing.AsyncContextManager | |
DefaultDict = typing.DefaultDict | |
OrderedDict = typing.OrderedDict | |
Counter = typing.Counter | |
ChainMap = typing.ChainMap | |
AsyncGenerator = typing.AsyncGenerator | |
Text = typing.Text | |
TYPE_CHECKING = typing.TYPE_CHECKING | |
dict | _PROTO_ALLOWLIST |
dict | _EXCLUDED_ATTRS |
Protocol = typing.Protocol | |
_typing_Protocol = typing.Protocol | |
_ProtocolMetaBase = type(_typing_Protocol) | |
runtime_checkable = typing.runtime_checkable | |
runtime = runtime_checkable | |
SupportsInt = typing.SupportsInt | |
SupportsFloat = typing.SupportsFloat | |
SupportsComplex = typing.SupportsComplex | |
SupportsBytes = typing.SupportsBytes | |
SupportsIndex = typing.SupportsIndex | |
SupportsAbs = typing.SupportsAbs | |
SupportsRound = typing.SupportsRound | |
TypedDict = typing.TypedDict | |
_TypedDictMeta = typing._TypedDictMeta | |
is_typeddict = typing.is_typeddict | |
str | _TAKES_MODULE = "module" in inspect.signature(typing._type_check).parameters |
str | _fake_name = "Protocol" |
_TypedDict | |
tuple | _TYPEDDICT_TYPES = (typing._TypedDictMeta, _TypedDictMeta) |
assert_type = typing.assert_type | |
get_type_hints = typing.get_type_hints | |
Annotated = typing.Annotated | |
_AnnotatedAlias = typing._AnnotatedAlias | |
get_origin = typing.get_origin | |
get_args = typing.get_args | |
_BaseGenericAlias = typing._GenericAlias | |
_typing_GenericAlias = typing._GenericAlias | |
TypeAlias = typing.TypeAlias | |
ParamSpecArgs = typing.ParamSpecArgs | |
ParamSpecKwargs = typing.ParamSpecKwargs | |
Concatenate = typing.Concatenate | |
_ConcatenateGenericAlias = typing._ConcatenateGenericAlias | |
TypeGuard = typing.TypeGuard | |
LiteralString = typing.LiteralString | |
Self = typing.Self | |
Never = typing.Never | |
Required = typing.Required | |
NotRequired = typing.NotRequired | |
str | _UNPACK_DOC |
Unpack = typing.Unpack | |
reveal_type = typing.reveal_type | |
assert_never = typing.assert_never | |
dataclass_transform = typing.dataclass_transform | |
override = typing.override | |
_F = typing.TypeVar("_F", bound=typing.Callable[..., typing.Any]) | |
deprecated = typing.deprecated | |
_T = typing.TypeVar("_T") | |
_collect_type_vars | |
_check_generic | |
NamedTuple = typing.NamedTuple | |
_prohibited_namedtuple_fields = typing._prohibited | |
_special_namedtuple_fields = frozenset({'__module__', '__name__', '__annotations__'}) | |
_NamedTuple | |
str | _new_signature = '(typename, fields=None, /, **kwargs)' |
Buffer = collections.abc.Buffer | |
get_original_bases = _types.get_original_bases | |
NewType = typing.NewType | |
TypeAliasType = typing.TypeAliasType | |
is_protocol = typing.is_protocol | |
get_protocol_members = typing.get_protocol_members | |
AbstractSet = typing.AbstractSet | |
AnyStr = typing.AnyStr | |
BinaryIO = typing.BinaryIO | |
Callable = typing.Callable | |
Collection = typing.Collection | |
Container = typing.Container | |
Dict = typing.Dict | |
ForwardRef = typing.ForwardRef | |
FrozenSet = typing.FrozenSet | |
Generator = typing.Generator | |
Generic = typing.Generic | |
Hashable = typing.Hashable | |
IO = typing.IO | |
ItemsView = typing.ItemsView | |
Iterable = typing.Iterable | |
Iterator = typing.Iterator | |
KeysView = typing.KeysView | |
List = typing.List | |
Mapping = typing.Mapping | |
MappingView = typing.MappingView | |
Match = typing.Match | |
MutableMapping = typing.MutableMapping | |
MutableSequence = typing.MutableSequence | |
MutableSet = typing.MutableSet | |
Optional = typing.Optional | |
Pattern = typing.Pattern | |
Reversible = typing.Reversible | |
Sequence = typing.Sequence | |
Set = typing.Set | |
Sized = typing.Sized | |
TextIO = typing.TextIO | |
Tuple = typing.Tuple | |
Union = typing.Union | |
ValuesView = typing.ValuesView | |
cast = typing.cast | |
no_type_check = typing.no_type_check | |
no_type_check_decorator = typing.no_type_check_decorator | |
_is_runtime_protocol | |
|
protected |
Allow instance and class checks for special stdlib modules. The abc and functools modules indiscriminately call isinstance() and issubclass() on the whole MRO of a user class, which may contain protocols.
Definition at line 590 of file typing_extensions.py.
References pip._vendor.typing_extensions._caller().
Referenced by _ProtocolMeta.__instancecheck__(), and _ProtocolMeta.__subclasscheck__().
|
protected |
Definition at line 578 of file typing_extensions.py.
References i.
Referenced by ParamSpec.__init__(), TypeVarTuple.__init__(), NewType.__init__(), TypeAliasType.__init__(), pip._vendor.typing_extensions._allow_reckless_class_checks(), pip._vendor.typing_extensions._set_module(), pip._vendor.typing_extensions.NamedTuple(), and pip._vendor.typing_extensions.TypedDict().
|
protected |
Check correct count for parameters of a generic cls (internal helper). This gives a nice error message in case of count mismatch.
Definition at line 147 of file typing_extensions.py.
References pip._vendor.typing_extensions._is_unpack(), and i.
|
protected |
Collect all type variable contained in types in order of first appearance (lexicographic order). For example:: _collect_type_vars((T, List[S, T])) == (T, S)
Definition at line 181 of file typing_extensions.py.
References pip._vendor.typing_extensions._is_unpack(), pip._vendor.typing_extensions._should_collect_from_parameters(), and i.
|
protected |
Definition at line 1775 of file typing_extensions.py.
References i.
Referenced by _ConcatenateForm.__getitem__(), and pip._vendor.typing_extensions.Concatenate().
|
protected |
Definition at line 956 of file typing_extensions.py.
References i.
|
protected |
An internal helper for Literal creation: flatten Literals among parameters
Definition at line 324 of file typing_extensions.py.
References i.
Referenced by _LiteralForm.__getitem__().
|
protected |
Definition at line 526 of file typing_extensions.py.
References i.
Referenced by _ProtocolMeta.__init__(), and pip._vendor.typing_extensions.get_protocol_members().
|
protected |
Corresponds to is_unionable() in unionobject.c in CPython.
Definition at line 2867 of file typing_extensions.py.
References i.
Referenced by TypeAliasType.__or__(), and TypeAliasType.__ror__().
|
protected |
Definition at line 2175 of file typing_extensions.py.
References pip._vendor.typing_extensions.get_origin, and i.
Referenced by pip._vendor.typing_extensions._check_generic(), and pip._vendor.typing_extensions._collect_type_vars().
|
protected |
Definition at line 2595 of file typing_extensions.py.
References i.
Referenced by _NamedTupleMeta.__new__(), and pip._vendor.typing_extensions.NamedTuple().
|
protected |
Helper 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.
Definition at line 538 of file typing_extensions.py.
References pip._vendor.typing_extensions._collect_type_vars, and i.
Referenced by Protocol.__init_subclass__().
|
protected |
Definition at line 2653 of file typing_extensions.py.
|
protected |
Definition at line 597 of file typing_extensions.py.
References i.
|
protected |
Definition at line 716 of file typing_extensions.py.
References i, and pip._vendor.typing_extensions.is_protocol.
|
protected |
Definition at line 1482 of file typing_extensions.py.
References i.
Referenced by ParamSpec.__new__(), TypeVar.__new__(), and TypeVarTuple.__new__().
|
protected |
Definition at line 1492 of file typing_extensions.py.
References pip._vendor.typing_extensions._caller(), and i.
Referenced by ParamSpec.__new__(), TypeVar.__new__(), and TypeVarTuple.__new__().
|
protected |
Definition at line 169 of file typing_extensions.py.
References i.
Referenced by pip._vendor.typing_extensions._collect_type_vars().
|
protected |
Strips Annotated, Required and NotRequired from a given type.
Definition at line 1209 of file typing_extensions.py.
References pip._vendor.typing_extensions._strip_extras(), and i.
Referenced by pip._vendor.typing_extensions._strip_extras(), and pip._vendor.typing_extensions.get_type_hints().
|
protected |
Definition at line 334 of file typing_extensions.py.
Referenced by _LiteralGenericAlias.__eq__(), _LiteralForm.__getitem__(), and _LiteralGenericAlias.__hash__().
Assert 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.
Definition at line 2333 of file typing_extensions.py.
References i.
assert_type | ( | __val, | |
__typ | |||
) |
Assert (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.
Definition at line 1189 of file typing_extensions.py.
References i.
Concatenate | ( | self, | |
parameters | |||
) |
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.
Definition at line 1795 of file typing_extensions.py.
References pip._vendor.typing_extensions._concatenate_getitem().
typing.Callable[[T], T] dataclass_transform | ( | *bool | eq_default = True , |
bool | order_default = False , |
||
bool | kw_only_default = False , |
||
bool | frozen_default = False , |
||
typing.Tuple[ typing.Union[typing.Type[typing.Any], typing.Callable[..., typing.Any]], ... ] | field_specifiers = () , |
||
**typing.Any | kwargs | ||
) |
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. - ``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()``. At runtime, this decorator records its arguments in the ``__dataclass_transform__`` attribute on the decorated object. See PEP 681 for details.
Definition at line 2360 of file typing_extensions.py.
References i.
typing.Callable[[_T], _T] deprecated | ( | str | __msg, |
*typing.Optional[typing.Type[Warning]] | category = DeprecationWarning , |
||
int | stacklevel = 1 |
||
) |
Indicate that a class, function or overload is deprecated. Usage: @deprecated("Use B instead") class A: pass @deprecated("Use g instead") def f(): pass @overload @deprecated("int support is deprecated") def g(x: int) -> int: ... @overload def g(x: str) -> int: ... When this decorator is applied to an object, the type checker will generate a diagnostic on usage of the deprecated object. The warning specified by ``category`` will be emitted on use of deprecated objects. For functions, that happens on calls; for classes, on instantiation. If the ``category`` is ``None``, no warning is emitted. The ``stacklevel`` determines where the warning is emitted. If it is ``1`` (the default), the warning is emitted at the direct caller of the deprecated object; if it is higher, it is emitted further up the stack. The decorator sets the ``__deprecated__`` attribute on the decorated object to the deprecation message passed to the decorator. If applied to an overload, the decorator must be after the ``@overload`` decorator for the attribute to exist on the overload as returned by ``get_overloads()``. See PEP 702 for details.
Definition at line 2492 of file typing_extensions.py.
References i.
final | ( | f | ) |
This 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.
Definition at line 284 of file typing_extensions.py.
References i.
get_args | ( | tp | ) |
Get 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)
Definition at line 1424 of file typing_extensions.py.
References pip._vendor.typing_extensions.get_origin, and i.
get_origin | ( | tp | ) |
Get 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
Definition at line 1400 of file typing_extensions.py.
References i.
get_original_bases | ( | __cls | ) |
Return the class's "original" bases prior to modification by `__mro_entries__`. Examples:: from typing import TypeVar, Generic from pip._vendor.typing_extensions import NamedTuple, TypedDict T = TypeVar("T") class Foo(Generic[T]): ... class Bar(Foo[int], float): ... class Baz(list[str]): ... Eggs = NamedTuple("Eggs", [("a", int), ("b", str)]) Spam = TypedDict("Spam", {"a": int, "b": str}) assert get_original_bases(Bar) == (Foo[int], float) assert get_original_bases(Baz) == (list[str],) assert get_original_bases(Eggs) == (NamedTuple,) assert get_original_bases(Spam) == (TypedDict,) assert get_original_bases(int) == (object,)
Definition at line 2767 of file typing_extensions.py.
References i.
get_overloads | ( | func | ) |
Return all defined overloads for *func* as a sequence.
Definition at line 447 of file typing_extensions.py.
References i.
typing.FrozenSet[str] get_protocol_members | ( | type | __tp | ) |
Return the set of members defined in a Protocol. Example:: >>> from typing_extensions import Protocol, get_protocol_members >>> class P(Protocol): ... def a(self) -> str: ... ... b: int >>> get_protocol_members(P) frozenset({'a', 'b'}) Raise a TypeError for arguments that are not Protocols.
Definition at line 3011 of file typing_extensions.py.
References pip._vendor.typing_extensions._get_protocol_attrs(), i, and pip._vendor.typing_extensions.is_protocol.
Return type hints for an object. This is often the same as obj.__annotations__, but it handles forward references encoded as string literals, adds Optional[t] if a default value equal to None is set and recursively replaces all 'Annotated[T, ...]', '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.
Definition at line 1233 of file typing_extensions.py.
References pip._vendor.typing_extensions._strip_extras(), and i.
IntVar | ( | name | ) |
Definition at line 316 of file typing_extensions.py.
References i.
bool is_protocol | ( | type | __tp | ) |
Return True if the given type is a Protocol. Example:: >>> from typing_extensions import Protocol, is_protocol >>> class P(Protocol): ... def a(self) -> str: ... ... b: int >>> is_protocol(P) True >>> is_protocol(int) False
Definition at line 2990 of file typing_extensions.py.
References i.
is_typeddict | ( | tp | ) |
Check 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
Definition at line 1168 of file typing_extensions.py.
References i.
LiteralString | ( | self, | |
params | |||
) |
Represents 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.
Definition at line 1979 of file typing_extensions.py.
References i.
NamedTuple | ( | __typename, | |
__fields = _marker , |
|||
** | kwargs | ||
) |
Typed version of namedtuple. Usage:: class Employee(NamedTuple): name: str id: int This is equivalent to:: Employee = collections.namedtuple('Employee', ['name', 'id']) The resulting class has an extra __annotations__ attribute, giving a dict that maps field names to types. (The field names are also in the _fields attribute, which is part of the namedtuple API.) An alternative equivalent functional syntax is also accepted:: Employee = NamedTuple('Employee', [('name', str), ('id', int)])
Definition at line 2658 of file typing_extensions.py.
References pip._vendor.typing_extensions._caller(), pip._vendor.typing_extensions._make_nmtuple(), and i.
Never | ( | self, | |
params | |||
) |
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 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
Definition at line 2023 of file typing_extensions.py.
References i.
NotRequired | ( | self, | |
parameters | |||
) |
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, )
Definition at line 2074 of file typing_extensions.py.
References i.
overload | ( | func | ) |
Decorator for overloaded functions/methods. In a stub file, place two or more stub definitions for the same function in a row, each decorated with @overload. For example: @overload def utf8(value: None) -> None: ... @overload def utf8(value: bytes) -> bytes: ... @overload def utf8(value: str) -> bytes: ... In a non-stub file (i.e. a regular .py file), do the same but follow it with an implementation. The implementation should *not* be decorated with @overload. For example: @overload def utf8(value: None) -> None: ... @overload def utf8(value: bytes) -> bytes: ... @overload def utf8(value: str) -> bytes: ... def utf8(value): # implementation goes here The overloads for a function can be retrieved at runtime using the get_overloads() function.
Definition at line 407 of file typing_extensions.py.
References i.
Indicate 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 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 these properties. The decorator sets the ``__override__`` attribute to ``True`` on the decorated object to allow runtime introspection. See PEP 698 for details.
Definition at line 2451 of file typing_extensions.py.
References i.
Required | ( | self, | |
parameters | |||
) |
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.
Definition at line 2054 of file typing_extensions.py.
References i.
Reveal 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.
Definition at line 2310 of file typing_extensions.py.
References i.
runtime_checkable | ( | cls | ) |
Mark 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.
Definition at line 857 of file typing_extensions.py.
References i.
Self | ( | self, | |
params | |||
) |
Used to spell the type of "self" in classes. Example:: from typing import Self class ReturnsSelf: def parse(self, data: bytes) -> Self: ... return self
Definition at line 2002 of file typing_extensions.py.
References i.
TypeAlias | ( | self, | |
parameters | |||
) |
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.
Definition at line 1453 of file typing_extensions.py.
TypedDict | ( | __typename, | |
__fields = _marker , |
|||
* | total = True , |
||
** | kwargs | ||
) |
A 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 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 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.
Definition at line 1080 of file typing_extensions.py.
References pip._vendor.typing_extensions._caller(), and i.
TypeGuard | ( | self, | |
parameters | |||
) |
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).
Definition at line 1832 of file typing_extensions.py.
References i.
Unpack | ( | self, | |
parameters | |||
) |
Definition at line 2188 of file typing_extensions.py.
References i.
|
protected |
Definition at line 1281 of file typing_extensions.py.
|
protected |
Definition at line 1393 of file typing_extensions.py.
|
protected |
Definition at line 2584 of file typing_extensions.py.
Referenced by Protocol.__class_getitem__().
|
protected |
Definition at line 2583 of file typing_extensions.py.
Referenced by pip._vendor.typing_extensions._maybe_adjust_parameters().
|
protected |
Definition at line 1791 of file typing_extensions.py.
|
protected |
Definition at line 503 of file typing_extensions.py.
|
protected |
Definition at line 2449 of file typing_extensions.py.
|
protected |
Definition at line 990 of file typing_extensions.py.
|
protected |
Definition at line 871 of file typing_extensions.py.
|
protected |
Definition at line 144 of file typing_extensions.py.
|
protected |
Definition at line 2651 of file typing_extensions.py.
Definition at line 2727 of file typing_extensions.py.
|
protected |
Definition at line 394 of file typing_extensions.py.
|
protected |
Definition at line 403 of file typing_extensions.py.
|
protected |
Definition at line 2608 of file typing_extensions.py.
|
protected |
Definition at line 493 of file typing_extensions.py.
|
protected |
Definition at line 606 of file typing_extensions.py.
|
protected |
Definition at line 2609 of file typing_extensions.py.
|
protected |
Definition at line 2490 of file typing_extensions.py.
|
protected |
Definition at line 987 of file typing_extensions.py.
|
protected |
Definition at line 1077 of file typing_extensions.py.
|
protected |
Definition at line 1164 of file typing_extensions.py.
|
protected |
Definition at line 983 of file typing_extensions.py.
|
protected |
Definition at line 1398 of file typing_extensions.py.
|
protected |
Definition at line 605 of file typing_extensions.py.
|
protected |
Definition at line 2130 of file typing_extensions.py.
AbstractSet = typing.AbstractSet |
Definition at line 3036 of file typing_extensions.py.
Annotated = typing.Annotated |
Definition at line 1278 of file typing_extensions.py.
AnyStr = typing.AnyStr |
Definition at line 3037 of file typing_extensions.py.
assert_never = typing.assert_never |
Definition at line 2331 of file typing_extensions.py.
assert_type = typing.assert_type |
Definition at line 1186 of file typing_extensions.py.
AsyncContextManager = typing.AsyncContextManager |
Definition at line 476 of file typing_extensions.py.
AsyncGenerator = typing.AsyncGenerator |
Definition at line 488 of file typing_extensions.py.
AsyncIterable = typing.AsyncIterable |
Definition at line 472 of file typing_extensions.py.
AsyncIterator = typing.AsyncIterator |
Definition at line 473 of file typing_extensions.py.
Awaitable = typing.Awaitable |
Definition at line 470 of file typing_extensions.py.
BinaryIO = typing.BinaryIO |
Definition at line 3038 of file typing_extensions.py.
Buffer = collections.abc.Buffer |
Definition at line 2735 of file typing_extensions.py.
Callable = typing.Callable |
Definition at line 3039 of file typing_extensions.py.
cast = typing.cast |
Definition at line 3070 of file typing_extensions.py.
ChainMap = typing.ChainMap |
Definition at line 487 of file typing_extensions.py.
ClassVar = typing.ClassVar |
Definition at line 243 of file typing_extensions.py.
clear_overloads | ( | ) | = typing.clear_overloads |
Clear all overloads in the registry.
Definition at line 400 of file typing_extensions.py.
Collection = typing.Collection |
Definition at line 3040 of file typing_extensions.py.
Concatenate = typing.Concatenate |
Definition at line 1790 of file typing_extensions.py.
Container = typing.Container |
Definition at line 3041 of file typing_extensions.py.
ContextManager = typing.ContextManager |
Definition at line 475 of file typing_extensions.py.
Coroutine = typing.Coroutine |
Definition at line 471 of file typing_extensions.py.
Counter = typing.Counter |
Definition at line 486 of file typing_extensions.py.
dataclass_transform = typing.dataclass_transform |
Definition at line 2358 of file typing_extensions.py.
DefaultDict = typing.DefaultDict |
Definition at line 477 of file typing_extensions.py.
deprecated = typing.deprecated |
Definition at line 2488 of file typing_extensions.py.
Deque = typing.Deque |
Definition at line 474 of file typing_extensions.py.
Dict = typing.Dict |
Definition at line 3042 of file typing_extensions.py.
doc |
Definition at line 264 of file typing_extensions.py.
Final = typing.Final |
Definition at line 254 of file typing_extensions.py.
final = typing.final |
Definition at line 279 of file typing_extensions.py.
ForwardRef = typing.ForwardRef |
Definition at line 3043 of file typing_extensions.py.
FrozenSet = typing.FrozenSet |
Definition at line 3044 of file typing_extensions.py.
Generator = typing.Generator |
Definition at line 3045 of file typing_extensions.py.
Generic = typing.Generic |
Definition at line 3046 of file typing_extensions.py.
GenericMeta = type |
Definition at line 133 of file typing_extensions.py.
get_args = typing.get_args |
Definition at line 1386 of file typing_extensions.py.
Referenced by _TypedDictMeta.__new__().
get_origin = typing.get_origin |
Definition at line 1385 of file typing_extensions.py.
Referenced by Annotated.__class_getitem__(), _TypedDictMeta.__new__(), pip._vendor.typing_extensions._is_unpack(), and pip._vendor.typing_extensions.get_args().
get_original_bases = _types.get_original_bases |
Definition at line 2765 of file typing_extensions.py.
get_overloads = typing.get_overloads |
Definition at line 399 of file typing_extensions.py.
get_protocol_members = typing.get_protocol_members |
Definition at line 2988 of file typing_extensions.py.
get_type_hints = typing.get_type_hints |
Definition at line 1206 of file typing_extensions.py.
Hashable = typing.Hashable |
Definition at line 3047 of file typing_extensions.py.
IO = typing.IO |
Definition at line 3048 of file typing_extensions.py.
is_protocol = typing.is_protocol |
Definition at line 2987 of file typing_extensions.py.
Referenced by _ProtocolMeta.__new__(), pip._vendor.typing_extensions._proto_hook(), and pip._vendor.typing_extensions.get_protocol_members().
is_typeddict = typing.is_typeddict |
Definition at line 984 of file typing_extensions.py.
ItemsView = typing.ItemsView |
Definition at line 3049 of file typing_extensions.py.
Iterable = typing.Iterable |
Definition at line 3050 of file typing_extensions.py.
Iterator = typing.Iterator |
Definition at line 3051 of file typing_extensions.py.
KeysView = typing.KeysView |
Definition at line 3052 of file typing_extensions.py.
KT = typing.TypeVar('KT') |
Definition at line 207 of file typing_extensions.py.
List = typing.List |
Definition at line 3053 of file typing_extensions.py.
Literal = typing.Literal |
Definition at line 322 of file typing_extensions.py.
LiteralString = typing.LiteralString |
Definition at line 1976 of file typing_extensions.py.
Mapping = typing.Mapping |
Definition at line 3054 of file typing_extensions.py.
MappingView = typing.MappingView |
Definition at line 3055 of file typing_extensions.py.
Match = typing.Match |
Definition at line 3056 of file typing_extensions.py.
MutableMapping = typing.MutableMapping |
Definition at line 3057 of file typing_extensions.py.
MutableSequence = typing.MutableSequence |
Definition at line 3058 of file typing_extensions.py.
MutableSet = typing.MutableSet |
Definition at line 3059 of file typing_extensions.py.
NamedTuple = typing.NamedTuple |
Definition at line 2593 of file typing_extensions.py.
Never = typing.Never |
Definition at line 2020 of file typing_extensions.py.
NewType = typing.NewType |
Definition at line 2802 of file typing_extensions.py.
no_type_check = typing.no_type_check |
Definition at line 3071 of file typing_extensions.py.
no_type_check_decorator = typing.no_type_check_decorator |
Definition at line 3072 of file typing_extensions.py.
NoReturn = typing.NoReturn |
Definition at line 202 of file typing_extensions.py.
NotRequired = typing.NotRequired |
Definition at line 2051 of file typing_extensions.py.
Optional = typing.Optional |
Definition at line 3060 of file typing_extensions.py.
OrderedDict = typing.OrderedDict |
Definition at line 481 of file typing_extensions.py.
overload = typing.overload |
Definition at line 398 of file typing_extensions.py.
override = typing.override |
Definition at line 2447 of file typing_extensions.py.
ParamSpecArgs = typing.ParamSpecArgs |
Definition at line 1542 of file typing_extensions.py.
ParamSpecKwargs = typing.ParamSpecKwargs |
Definition at line 1543 of file typing_extensions.py.
Pattern = typing.Pattern |
Definition at line 3061 of file typing_extensions.py.
bool PEP_560 = True |
Definition at line 132 of file typing_extensions.py.
Protocol = typing.Protocol |
Definition at line 588 of file typing_extensions.py.
Required = typing.Required |
Definition at line 2050 of file typing_extensions.py.
reveal_type = typing.reveal_type |
Definition at line 2308 of file typing_extensions.py.
Reversible = typing.Reversible |
Definition at line 3062 of file typing_extensions.py.
runtime = runtime_checkable |
Definition at line 876 of file typing_extensions.py.
runtime_checkable = typing.runtime_checkable |
Definition at line 855 of file typing_extensions.py.
Self = typing.Self |
Definition at line 1999 of file typing_extensions.py.
Sequence = typing.Sequence |
Definition at line 3063 of file typing_extensions.py.
Set = typing.Set |
Definition at line 3064 of file typing_extensions.py.
Sized = typing.Sized |
Definition at line 3065 of file typing_extensions.py.
SupportsAbs = typing.SupportsAbs |
Definition at line 886 of file typing_extensions.py.
SupportsBytes = typing.SupportsBytes |
Definition at line 884 of file typing_extensions.py.
SupportsComplex = typing.SupportsComplex |
Definition at line 883 of file typing_extensions.py.
SupportsFloat = typing.SupportsFloat |
Definition at line 882 of file typing_extensions.py.
SupportsIndex = typing.SupportsIndex |
Definition at line 885 of file typing_extensions.py.
SupportsInt = typing.SupportsInt |
Definition at line 881 of file typing_extensions.py.
SupportsRound = typing.SupportsRound |
Definition at line 887 of file typing_extensions.py.
T = typing.TypeVar('T') |
Definition at line 206 of file typing_extensions.py.
T_co = typing.TypeVar('T_co', covariant=True) |
Definition at line 209 of file typing_extensions.py.
T_contra = typing.TypeVar('T_contra', contravariant=True) |
Definition at line 210 of file typing_extensions.py.
Text = typing.Text |
Definition at line 489 of file typing_extensions.py.
TextIO = typing.TextIO |
Definition at line 3066 of file typing_extensions.py.
Tuple = typing.Tuple |
Definition at line 3067 of file typing_extensions.py.
Type = typing.Type |
Definition at line 464 of file typing_extensions.py.
TYPE_CHECKING = typing.TYPE_CHECKING |
Definition at line 490 of file typing_extensions.py.
TypeAlias = typing.TypeAlias |
Definition at line 1449 of file typing_extensions.py.
TypeAliasType = typing.TypeAliasType |
Definition at line 2865 of file typing_extensions.py.
TypedDict = typing.TypedDict |
Definition at line 982 of file typing_extensions.py.
TypeGuard = typing.TypeGuard |
Definition at line 1828 of file typing_extensions.py.
Union = typing.Union |
Definition at line 3068 of file typing_extensions.py.
Unpack = typing.Unpack |
Definition at line 2173 of file typing_extensions.py.
ValuesView = typing.ValuesView |
Definition at line 3069 of file typing_extensions.py.
VT = typing.TypeVar('VT') |
Definition at line 208 of file typing_extensions.py.