chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2136bb0c-8ac4-40b2-8413-e99c82b8d676 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,397 | supabase-export-v2 | af19edc37cdea284 | # OK: ``x`` is assigned to a tuple of length 1 where the sole element is an int x: tuple[int] = (5,)
# OK: ``y`` is assigned to a tuple of length 2;
# element 1 is an int, element 2 is a str
y: tuple[int, str] = (5, "foo") | trusted_official_docs | CPython Docs | # OK: ``x`` is assigned to a tuple of length 1 where the sole element is an int x: tuple[int] = (5,)
# OK: ``y`` is assigned to a tuple of length 2;
# element 1 is an int, element 2 is a str
y: tuple[int, str] = (5, "foo") | # OK: ``x`` is assigned to a tuple of length 1 where the sole element is an int x: tuple[int] = (5,)
# OK: ``y`` is assigned to a tuple of length 2;
# element 1 is an int, element 2 is a str
y: tuple[int, str] = (5, "foo") | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
21d00636-7a2e-4407-9267-692ae9d69a24 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,530 | supabase-export-v2 | 953eb722fc013336 | * Every type is compatible with :data:`Any`. * :data:`Any` is compatible with every type.
.. versionchanged:: 3.11
:data:`Any` can now be used as a base class. This can be useful for
avoiding type checker errors with classes that can duck type anywhere or
are highly dynamic. | trusted_official_docs | CPython Docs | * Every type is compatible with :data:`Any`. * :data:`Any` is compatible with every type.
.. versionchanged:: 3.11
:data:`Any` can now be used as a base class. This can be useful for
avoiding type checker errors with classes that can duck type anywhere or
are highly dynamic. | * Every type is compatible with :data:`Any`. * :data:`Any` is compatible with every type.
.. versionchanged:: 3.11
:data:`Any` can now be used as a base class. This can be useful for
avoiding type checker errors with classes that can duck type anywhere or
are highly dynamic. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
22a6dad6-4aa3-459d-aecd-3dea04e52e7d | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,807 | supabase-export-v2 | c7c78f5b9ea14a91 | generic types as well as for generic function and type alias definitions. See :class:`Generic` for more information on generic types. Generic functions work as follows::
def repeat[T](x: T, n: int) -> Sequence[T]:
"""Return a list containing n references to x."""
return [x]*n | trusted_official_docs | CPython Docs | generic types as well as for generic function and type alias definitions. See :class:`Generic` for more information on generic types. Generic functions work as follows::
def repeat[T](x: T, n: int) -> Sequence[T]:
"""Return a list containing n references to x."""
return [x]*n | generic types as well as for generic function and type alias definitions. See :class:`Generic` for more information on generic types. Generic functions work as follows::
def repeat[T](x: T, n: int) -> Sequence[T]:
"""Return a list containing n references to x."""
return [x]*n | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
22ec4a44-43fb-4b35-b71c-4e3a6e7e236c | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,871 | supabase-export-v2 | 1106e68d7081a828 | fails to type check (and fails at runtime) # because tuple[()] is not compatible with tuple[T, *Ts] # (at least one element is required) move_first_element_to_last(tup=())
Note the use of the unpacking operator ``*`` in ``tuple[T, *Ts]``. Conceptually, you can think of ``Ts`` as a tuple of type variables
``(T1, T2, ..... | trusted_official_docs | CPython Docs | fails to type check (and fails at runtime) # because tuple[()] is not compatible with tuple[T, *Ts] # (at least one element is required) move_first_element_to_last(tup=())
Note the use of the unpacking operator ``*`` in ``tuple[T, *Ts]``. Conceptually, you can think of ``Ts`` as a tuple of type variables
``(T1, T2, ..... | fails to type check (and fails at runtime) # because tuple[()] is not compatible with tuple[T, *Ts] # (at least one element is required) move_first_element_to_last(tup=())
Note the use of the unpacking operator ``*`` in ``tuple[T, *Ts]``. Conceptually, you can think of ``Ts`` as a tuple of type variables
``(T1, T2, ..... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
26ddf358-6db5-4845-9b22-e2963806249e | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,017 | supabase-export-v2 | 1b6b44fe68470a15 | .. versionchanged:: 3.9 Removed the ``_field_types`` attribute in favor of the more standard ``__annotations__`` attribute which has the same information.
.. versionchanged:: 3.9
``NamedTuple`` is now a function rather than a class. It can still be used as a class base, as described above. | trusted_official_docs | CPython Docs | .. versionchanged:: 3.9 Removed the ``_field_types`` attribute in favor of the more standard ``__annotations__`` attribute which has the same information.
.. versionchanged:: 3.9
``NamedTuple`` is now a function rather than a class. It can still be used as a class base, as described above. | .. versionchanged:: 3.9 Removed the ``_field_types`` attribute in favor of the more standard ``__annotations__`` attribute which has the same information.
.. versionchanged:: 3.9
``NamedTuple`` is now a function rather than a class. It can still be used as a class base, as described above. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
27b5059f-ff29-4c58-98d6-1ac8591a8265 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,626 | supabase-export-v2 | a96bd3ec09c41a42 | signature. In this case, the :class:`ParamSpec` indicates that the returned callable's parameter types are dependent on the parameter types of the callable being passed in::
from collections.abc import Callable
from threading import Lock
from typing import Concatenate | trusted_official_docs | CPython Docs | signature. In this case, the :class:`ParamSpec` indicates that the returned callable's parameter types are dependent on the parameter types of the callable being passed in::
from collections.abc import Callable
from threading import Lock
from typing import Concatenate | signature. In this case, the :class:`ParamSpec` indicates that the returned callable's parameter types are dependent on the parameter types of the callable being passed in::
from collections.abc import Callable
from threading import Lock
from typing import Concatenate | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
27eb8c8a-85aa-43ef-85b4-9ecc425eed03 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,549 | supabase-export-v2 | fcb479ef2bfb395a | 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 check... | trusted_official_docs | CPython Docs | 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 check... | 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 check... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
28bffda8-46c1-4e71-ab6e-9e57e06e9db5 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,182 | supabase-export-v2 | 09045ffead1aca2b | Ask a static type checker to reveal the inferred type of an expression.
When a static type checker encounters a call to this function,
it emits a diagnostic with the inferred type of the argument. For example:: | trusted_official_docs | CPython Docs | Ask a static type checker to reveal the inferred type of an expression.
When a static type checker encounters a call to this function,
it emits a diagnostic with the inferred type of the argument. For example:: | Ask a static type checker to reveal the inferred type of an expression.
When a static type checker encounters a call to this function,
it emits a diagnostic with the inferred type of the argument. For example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
296e2908-cb10-46c6-82a4-db67c1c4f6b9 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,870 | supabase-export-v2 | bdafc5bc3a30b82e | bound to int, Ts is bound to (str, float) # Return value is ('spam', 3.0, 1), which has type tuple[str, float, int] move_first_element_to_last(tup=(1, 'spam', 3.0))
# This fails to type check (and fails at runtime)
# because tuple[()] is not compatible with tuple[T, *Ts]
# (at least one element is required)
move_fir... | trusted_official_docs | CPython Docs | bound to int, Ts is bound to (str, float) # Return value is ('spam', 3.0, 1), which has type tuple[str, float, int] move_first_element_to_last(tup=(1, 'spam', 3.0))
# This fails to type check (and fails at runtime)
# because tuple[()] is not compatible with tuple[T, *Ts]
# (at least one element is required)
move_fir... | bound to int, Ts is bound to (str, float) # Return value is ('spam', 3.0, 1), which has type tuple[str, float, int] move_first_element_to_last(tup=(1, 'spam', 3.0))
# This fails to type check (and fails at runtime)
# because tuple[()] is not compatible with tuple[T, *Ts]
# (at least one element is required)
move_fir... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
29730e45-8047-46e9-85bf-c84b6c30f3d1 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,263 | supabase-export-v2 | 6ade3b1cefff6da4 | Decorator to mark a class as a disjoint base.
Type checkers do not allow child classes of a disjoint base ``C`` to
inherit from other disjoint bases that are not parent or child classes of ``C``. | trusted_official_docs | CPython Docs | Decorator to mark a class as a disjoint base.
Type checkers do not allow child classes of a disjoint base ``C`` to
inherit from other disjoint bases that are not parent or child classes of ``C``. | Decorator to mark a class as a disjoint base.
Type checkers do not allow child classes of a disjoint base ``C`` to
inherit from other disjoint bases that are not parent or child classes of ``C``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2988f8e4-b977-4ab3-9aad-765597f64adf | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,282 | supabase-export-v2 | 5cf4078c6fbc31b9 | This is often the same as :func:`annotationlib.get_annotations`, but this function makes the following changes to the annotations dictionary:
* Forward references encoded as string literals or :class:`ForwardRef`
objects are handled by evaluating them in *globalns*, *localns*, and
(where applicable) *obj*'s :ref:`typ... | trusted_official_docs | CPython Docs | This is often the same as :func:`annotationlib.get_annotations`, but this function makes the following changes to the annotations dictionary:
* Forward references encoded as string literals or :class:`ForwardRef`
objects are handled by evaluating them in *globalns*, *localns*, and
(where applicable) *obj*'s :ref:`typ... | This is often the same as :func:`annotationlib.get_annotations`, but this function makes the following changes to the annotations dictionary:
* Forward references encoded as string literals or :class:`ForwardRef`
objects are handled by evaluating them in *globalns*, *localns*, and
(where applicable) *obj*'s :ref:`typ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2a8cef42-9c8e-4718-921c-e1a2581ac996 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,940 | supabase-export-v2 | 20aa1f9482c05cb0 | .. method:: evaluate_default
An :term:`evaluate function` corresponding to the :attr:`~ParamSpec.__default__` attribute. When called directly, this method supports only the :attr:`~annotationlib.Format.VALUE`
format, which is equivalent to accessing the :attr:`~ParamSpec.__default__` attribute directly,
but the metho... | trusted_official_docs | CPython Docs | .. method:: evaluate_default
An :term:`evaluate function` corresponding to the :attr:`~ParamSpec.__default__` attribute. When called directly, this method supports only the :attr:`~annotationlib.Format.VALUE`
format, which is equivalent to accessing the :attr:`~ParamSpec.__default__` attribute directly,
but the metho... | .. method:: evaluate_default
An :term:`evaluate function` corresponding to the :attr:`~ParamSpec.__default__` attribute. When called directly, this method supports only the :attr:`~annotationlib.Format.VALUE`
format, which is equivalent to accessing the :attr:`~ParamSpec.__default__` attribute directly,
but the metho... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2a9542bb-3e98-43b3-9a8e-c4048930aa1e | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,713 | supabase-export-v2 | 456c164e017af1b9 | type Vec[T] = Annotated[list[tuple[T, T]], MaxLen(10)]
# When used in a type annotation, a type checker will treat "V" the same as
# ``Annotated[list[tuple[int, int]], MaxLen(10)]``:
type V = Vec[int] | trusted_official_docs | CPython Docs | type Vec[T] = Annotated[list[tuple[T, T]], MaxLen(10)]
# When used in a type annotation, a type checker will treat "V" the same as
# ``Annotated[list[tuple[int, int]], MaxLen(10)]``:
type V = Vec[int] | type Vec[T] = Annotated[list[tuple[T, T]], MaxLen(10)]
# When used in a type annotation, a type checker will treat "V" the same as
# ``Annotated[list[tuple[int, int]], MaxLen(10)]``:
type V = Vec[int] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2b885963-1d3a-4b56-8856-ba67cee6bf5f | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,213 | supabase-export-v2 | d3329e66297b3d4e | :param field_specifiers: Specifies a static list of supported classes or functions that describe fields, similar to :func:`dataclasses.field`. Defaults to ``()``. :type field_specifiers: tuple[Callable[..., Any], ...]
:param Any \**kwargs:
Arbitrary other keyword arguments are accepted in order to allow for
possible ... | trusted_official_docs | CPython Docs | :param field_specifiers: Specifies a static list of supported classes or functions that describe fields, similar to :func:`dataclasses.field`. Defaults to ``()``. :type field_specifiers: tuple[Callable[..., Any], ...]
:param Any \**kwargs:
Arbitrary other keyword arguments are accepted in order to allow for
possible ... | :param field_specifiers: Specifies a static list of supported classes or functions that describe fields, similar to :func:`dataclasses.field`. Defaults to ``()``. :type field_specifiers: tuple[Callable[..., Any], ...]
:param Any \**kwargs:
Arbitrary other keyword arguments are accepted in order to allow for
possible ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2bb02ae0-678d-4517-8e8f-47981550d953 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,368 | supabase-export-v2 | 08c8c29854e56101 | def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes: for item in data: ...
def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]:
... def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]:
... | trusted_official_docs | CPython Docs | def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes: for item in data: ...
def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]:
... def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]:
... | def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes: for item in data: ...
def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]:
... def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]:
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2c505777-43c5-44e0-ab7e-83cdeeac4aac | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,369 | supabase-export-v2 | a4101deb0eeafdc5 | def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]: ... def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]: ...
batch_proc([], good_cb) # OK
batch_proc([], bad_cb) # Error! Argument 2 has incompatible type because of
# different name and kind in the callback | trusted_official_docs | CPython Docs | def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]: ... def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]: ...
batch_proc([], good_cb) # OK
batch_proc([], bad_cb) # Error! Argument 2 has incompatible type because of
# different name and kind in the callback | def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]: ... def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]: ...
batch_proc([], good_cb) # OK
batch_proc([], bad_cb) # Error! Argument 2 has incompatible type because of
# different name and kind in the callback | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2c76888f-f7ad-4787-a599-f14d3dfd3039 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,754 | supabase-export-v2 | b9d7212d3d129912 | 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.
If a ``TypeIs`` function is a class or instance method, then the type in
``TypeIs`` maps to the type of the second parameter (after ``cls`` or
``self``). | trusted_official_docs | CPython Docs | 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.
If a ``TypeIs`` function is a class or instance method, then the type in
``TypeIs`` maps to the type of the second parameter (after ``cls`` or
``self``). | 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.
If a ``TypeIs`` function is a class or instance method, then the type in
``TypeIs`` maps to the type of the second parameter (after ``cls`` or
``self``). | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2cac1cf4-80a2-4e3a-9e91-02e4eb663dd8 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,378 | supabase-export-v2 | 7a3b5abdc2ca4347 | class Employee: ...
# Sequence[Employee] indicates that all elements in the sequence
# must be instances of "Employee". # Mapping[str, str] indicates that all keys and all values in the mapping
# must be strings. def notify_by_email(employees: Sequence[Employee],
overrides: Mapping[str, str]) -> None: ... | trusted_official_docs | CPython Docs | class Employee: ...
# Sequence[Employee] indicates that all elements in the sequence
# must be instances of "Employee". # Mapping[str, str] indicates that all keys and all values in the mapping
# must be strings. def notify_by_email(employees: Sequence[Employee],
overrides: Mapping[str, str]) -> None: ... | class Employee: ...
# Sequence[Employee] indicates that all elements in the sequence
# must be instances of "Employee". # Mapping[str, str] indicates that all keys and all values in the mapping
# must be strings. def notify_by_email(employees: Sequence[Employee],
overrides: Mapping[str, str]) -> None: ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2cd9d435-9e78-46db-9b07-71150edc7f67 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,789 | supabase-export-v2 | dd011cf5a4cd7526 | class Mapping[KT, VT]: def __getitem__(self, key: KT) -> VT: ... # Etc.
Such a class implicitly inherits from ``Generic``. The runtime semantics of this syntax are discussed in the
:ref:`Language Reference <generic-classes>`. | trusted_official_docs | CPython Docs | class Mapping[KT, VT]: def __getitem__(self, key: KT) -> VT: ... # Etc.
Such a class implicitly inherits from ``Generic``. The runtime semantics of this syntax are discussed in the
:ref:`Language Reference <generic-classes>`. | class Mapping[KT, VT]: def __getitem__(self, key: KT) -> VT: ... # Etc.
Such a class implicitly inherits from ``Generic``. The runtime semantics of this syntax are discussed in the
:ref:`Language Reference <generic-classes>`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2d0a2322-e2c0-4e11-b577-49c3b0af59c2 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,883 | supabase-export-v2 | 48540eafd57a167b | However, note that at most one type variable tuple may appear in a single list of type arguments or type parameters::
x: tuple[*Ts, *Ts] # Not valid
class Array[*Shape, *Shape]: # Not valid
pass | trusted_official_docs | CPython Docs | However, note that at most one type variable tuple may appear in a single list of type arguments or type parameters::
x: tuple[*Ts, *Ts] # Not valid
class Array[*Shape, *Shape]: # Not valid
pass | However, note that at most one type variable tuple may appear in a single list of type arguments or type parameters::
x: tuple[*Ts, *Ts] # Not valid
class Array[*Shape, *Shape]: # Not valid
pass | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2e135514-c35a-4500-b9ce-57747355d101 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,374 | supabase-export-v2 | c8e32d62fa4d8b6a | Generics ========
Since type information about objects kept in containers cannot be statically
inferred in a generic way, many container classes in the standard library support
subscription to denote the expected types of container elements. | trusted_official_docs | CPython Docs | Generics ========
Since type information about objects kept in containers cannot be statically
inferred in a generic way, many container classes in the standard library support
subscription to denote the expected types of container elements. | Generics ========
Since type information about objects kept in containers cannot be statically
inferred in a generic way, many container classes in the standard library support
subscription to denote the expected types of container elements. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2f850f11-c19c-40d5-b541-a2f3656ba879 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,426 | supabase-export-v2 | 37a7a492ce0787c3 | Simple generators that only ever yield values can also be annotated as having a return type of either :class:`Iterable[YieldType] <collections.abc.Iterable>` or :class:`Iterator[YieldType] <collections.abc.Iterator>`::
def infinite_stream(start: int) -> Iterator[int]:
while True:
yield start
start += 1 | trusted_official_docs | CPython Docs | Simple generators that only ever yield values can also be annotated as having a return type of either :class:`Iterable[YieldType] <collections.abc.Iterable>` or :class:`Iterator[YieldType] <collections.abc.Iterator>`::
def infinite_stream(start: int) -> Iterator[int]:
while True:
yield start
start += 1 | Simple generators that only ever yield values can also be annotated as having a return type of either :class:`Iterable[YieldType] <collections.abc.Iterable>` or :class:`Iterator[YieldType] <collections.abc.Iterator>`::
def infinite_stream(start: int) -> Iterator[int]:
while True:
yield start
start += 1 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3001a9d2-092b-423d-bcac-c6f9c3a6c325 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,515 | supabase-export-v2 | 1a08e84193df0d73 | Deprecated alias to :class:`contextlib.AbstractContextManager`.
The first type parameter, ``T_co``, represents the type returned by
the :meth:`~object.__enter__` method. The optional second type parameter, ``ExitT_co``,
which defaults to ``bool | None``, represents the type returned by the
:meth:`~object.__exit__` m... | trusted_official_docs | CPython Docs | Deprecated alias to :class:`contextlib.AbstractContextManager`.
The first type parameter, ``T_co``, represents the type returned by
the :meth:`~object.__enter__` method. The optional second type parameter, ``ExitT_co``,
which defaults to ``bool | None``, represents the type returned by the
:meth:`~object.__exit__` m... | Deprecated alias to :class:`contextlib.AbstractContextManager`.
The first type parameter, ``T_co``, represents the type returned by
the :meth:`~object.__enter__` method. The optional second type parameter, ``ExitT_co``,
which defaults to ``bool | None``, represents the type returned by the
:meth:`~object.__exit__` m... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
30525725-7ad3-4175-9125-0c5131b44547 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,772 | supabase-export-v2 | 09f2fe3b53c12979 | the unpack operator ``*`` on a :ref:`type variable tuple <typevartuple>` is equivalent to using ``Unpack`` to mark the type variable tuple as having been unpacked::
Ts = TypeVarTuple('Ts')
tup: tuple[*Ts]
# Effectively does:
tup: tuple[Unpack[Ts]] | trusted_official_docs | CPython Docs | the unpack operator ``*`` on a :ref:`type variable tuple <typevartuple>` is equivalent to using ``Unpack`` to mark the type variable tuple as having been unpacked::
Ts = TypeVarTuple('Ts')
tup: tuple[*Ts]
# Effectively does:
tup: tuple[Unpack[Ts]] | the unpack operator ``*`` on a :ref:`type variable tuple <typevartuple>` is equivalent to using ``Unpack`` to mark the type variable tuple as having been unpacked::
Ts = TypeVarTuple('Ts')
tup: tuple[*Ts]
# Effectively does:
tup: tuple[Unpack[Ts]] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
313ac662-9cb9-44d7-a487-50726e9abcdb | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,542 | supabase-export-v2 | b6aa79d4d2624114 | # The better way of annotating this function: def greet_proper(cond: bool) -> str | bytes: return "hi there!" if cond else b"greetings!"
.. deprecated-removed:: 3.13 3.18
Deprecated in favor of the new :ref:`type parameter syntax <type-params>`. Use ``class A[T: (str, bytes)]: ...`` instead of importing ``AnyStr``. Se... | trusted_official_docs | CPython Docs | # The better way of annotating this function: def greet_proper(cond: bool) -> str | bytes: return "hi there!" if cond else b"greetings!"
.. deprecated-removed:: 3.13 3.18
Deprecated in favor of the new :ref:`type parameter syntax <type-params>`. Use ``class A[T: (str, bytes)]: ...`` instead of importing ``AnyStr``. Se... | # The better way of annotating this function: def greet_proper(cond: bool) -> str | bytes: return "hi there!" if cond else b"greetings!"
.. deprecated-removed:: 3.13 3.18
Deprecated in favor of the new :ref:`type parameter syntax <type-params>`. Use ``class A[T: (str, bytes)]: ...`` instead of importing ``AnyStr``. Se... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
315baf7e-b497-430c-b707-112c3364bdfb | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,742 | supabase-export-v2 | 5d0b0c39ea9e8769 | 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 take at
least one positional argum... | trusted_official_docs | CPython Docs | 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 take at
least one positional argum... | 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 take at
least one positional argum... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
31eb6bec-7d0d-4e6d-ae9c-3bb2816a5413 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,412 | supabase-export-v2 | 7a9a5487782a58fd | subtype of ``type[User]`` make_new_user(TeamUser) # Still fine make_new_user(User()) # Error: expected ``type[User]`` but got ``User`` make_new_user(int) # Error: ``type[int]`` is not a subtype of ``type[User]``
The only legal parameters for :class:`type` are classes, :data:`Any`,
:ref:`type variables <generics>`, and ... | trusted_official_docs | CPython Docs | subtype of ``type[User]`` make_new_user(TeamUser) # Still fine make_new_user(User()) # Error: expected ``type[User]`` but got ``User`` make_new_user(int) # Error: ``type[int]`` is not a subtype of ``type[User]``
The only legal parameters for :class:`type` are classes, :data:`Any`,
:ref:`type variables <generics>`, and ... | subtype of ``type[User]`` make_new_user(TeamUser) # Still fine make_new_user(User()) # Error: expected ``type[User]`` but got ``User`` make_new_user(int) # Error: ``type[int]`` is not a subtype of ``type[User]``
The only legal parameters for :class:`type` are classes, :data:`Any`,
:ref:`type variables <generics>`, and ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3223bab3-70f9-4950-ac6a-c487d2fc00a7 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,208 | supabase-export-v2 | aaf5a618fadb4168 | :param bool eq_default: Indicates whether the ``eq`` parameter is assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``True``.
:param bool order_default:
Indicates whether the ``order`` parameter is
assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``False``. | trusted_official_docs | CPython Docs | :param bool eq_default: Indicates whether the ``eq`` parameter is assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``True``.
:param bool order_default:
Indicates whether the ``order`` parameter is
assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``False``. | :param bool eq_default: Indicates whether the ``eq`` parameter is assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``True``.
:param bool order_default:
Indicates whether the ``order`` parameter is
assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``False``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
32c50dfc-0282-48d9-aab3-7f3c23bde125 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,392 | supabase-export-v2 | 57fb6ff37bc2d363 | # Type checker will infer that all elements in ``x`` are meant to be ints x: list[int] = []
# Type checker error: ``list`` only accepts a single type argument:
y: list[int, str] = [1, 'foo'] | trusted_official_docs | CPython Docs | # Type checker will infer that all elements in ``x`` are meant to be ints x: list[int] = []
# Type checker error: ``list`` only accepts a single type argument:
y: list[int, str] = [1, 'foo'] | # Type checker will infer that all elements in ``x`` are meant to be ints x: list[int] = []
# Type checker error: ``list`` only accepts a single type argument:
y: list[int, str] = [1, 'foo'] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
32ee9947-72ea-4036-a5cd-7b3077117c63 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,427 | supabase-export-v2 | 283f8c49511fe0e4 | def infinite_stream(start: int) -> Iterator[int]: while True: yield start start += 1
Async generators are handled in a similar fashion, but don't
expect a ``ReturnType`` type argument
(:class:`AsyncGenerator[YieldType, SendType] <collections.abc.AsyncGenerator>`). The ``SendType`` argument defaults to :const:`!None`, s... | trusted_official_docs | CPython Docs | def infinite_stream(start: int) -> Iterator[int]: while True: yield start start += 1
Async generators are handled in a similar fashion, but don't
expect a ``ReturnType`` type argument
(:class:`AsyncGenerator[YieldType, SendType] <collections.abc.AsyncGenerator>`). The ``SendType`` argument defaults to :const:`!None`, s... | def infinite_stream(start: int) -> Iterator[int]: while True: yield start start += 1
Async generators are handled in a similar fashion, but don't
expect a ``ReturnType`` type argument
(:class:`AsyncGenerator[YieldType, SendType] <collections.abc.AsyncGenerator>`). The ``SendType`` argument defaults to :const:`!None`, s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33024caf-6d5b-45f5-a68b-e410d242eb50 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,602 | supabase-export-v2 | f987ad2e58134772 | However, this does not apply to unions referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type A = Union[int, str]
Union[A, float] != Union[int, str, float] | trusted_official_docs | CPython Docs | However, this does not apply to unions referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type A = Union[int, str]
Union[A, float] != Union[int, str, float] | However, this does not apply to unions referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type A = Union[int, str]
Union[A, float] != Union[int, str, float] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33169811-7c2e-4285-81e9-4fa5767cb23d | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,398 | supabase-export-v2 | 0500e256ba2c328d | is assigned to a tuple of length 2; # element 1 is an int, element 2 is a str y: tuple[int, str] = (5, "foo")
# Error: the type annotation indicates a tuple of length 1,
# but ``z`` has been assigned to a tuple of length 3
z: tuple[int] = (1, 2, 3) | trusted_official_docs | CPython Docs | is assigned to a tuple of length 2; # element 1 is an int, element 2 is a str y: tuple[int, str] = (5, "foo")
# Error: the type annotation indicates a tuple of length 1,
# but ``z`` has been assigned to a tuple of length 3
z: tuple[int] = (1, 2, 3) | is assigned to a tuple of length 2; # element 1 is an int, element 2 is a str y: tuple[int, str] = (5, "foo")
# Error: the type annotation indicates a tuple of length 1,
# but ``z`` has been assigned to a tuple of length 3
z: tuple[int] = (1, 2, 3) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33b541ac-1ce9-4df9-ad5d-4802fde971ed | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,756 | supabase-export-v2 | 19a2ef8ef758a60d | means that if ``foo(arg)`` returns ``True``, then ``arg`` is an instance of ``TypeB``, and if it returns ``False``, it is not an instance of ``TypeB``.
``TypeIs`` also works with type variables. For more information, see
:pep:`742` (Narrowing types with ``TypeIs``). | trusted_official_docs | CPython Docs | means that if ``foo(arg)`` returns ``True``, then ``arg`` is an instance of ``TypeB``, and if it returns ``False``, it is not an instance of ``TypeB``.
``TypeIs`` also works with type variables. For more information, see
:pep:`742` (Narrowing types with ``TypeIs``). | means that if ``foo(arg)`` returns ``True``, then ``arg`` is an instance of ``TypeB``, and if it returns ``False``, it is not an instance of ``TypeB``.
``TypeIs`` also works with type variables. For more information, see
:pep:`742` (Narrowing types with ``TypeIs``). | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33ee820a-ea9b-42d3-b490-676d303a0284 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,283 | supabase-export-v2 | 6ac01f43022f9292 | ``C``'s base classes with those on ``C`` directly. This is done by traversing :attr:`C.__mro__ <type.__mro__>` and iteratively combining :term:`annotations <variable annotation>` of each base class.
Annotations
on classes appearing earlier in the :term:`method resolution order` always
take precedence over annotations... | trusted_official_docs | CPython Docs | ``C``'s base classes with those on ``C`` directly. This is done by traversing :attr:`C.__mro__ <type.__mro__>` and iteratively combining :term:`annotations <variable annotation>` of each base class.
Annotations
on classes appearing earlier in the :term:`method resolution order` always
take precedence over annotations... | ``C``'s base classes with those on ``C`` directly. This is done by traversing :attr:`C.__mro__ <type.__mro__>` and iteratively combining :term:`annotations <variable annotation>` of each base class.
Annotations
on classes appearing earlier in the :term:`method resolution order` always
take precedence over annotations... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33f685ff-ae44-4b04-b5a6-58f9a627e866 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,050 | supabase-export-v2 | 0b9fc349973aa974 | Mark a protocol class as a runtime protocol.
Such a protocol can be used with :func:`isinstance` and :func:`issubclass`. This allows a simple-minded structural check, very similar to "one trick ponies"
in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example:: | trusted_official_docs | CPython Docs | Mark a protocol class as a runtime protocol.
Such a protocol can be used with :func:`isinstance` and :func:`issubclass`. This allows a simple-minded structural check, very similar to "one trick ponies"
in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example:: | Mark a protocol class as a runtime protocol.
Such a protocol can be used with :func:`isinstance` and :func:`issubclass`. This allows a simple-minded structural check, very similar to "one trick ponies"
in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
342e68ed-5bed-4335-9e4c-d16a171223c1 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,292 | supabase-export-v2 | 26103ed3b3d1088d | .. note::
The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as :term:`type checkers <static type checker>`,
IDEs, linters, etc. | trusted_official_docs | CPython Docs | .. note::
The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as :term:`type checkers <static type checker>`,
IDEs, linters, etc. | .. note::
The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as :term:`type checkers <static type checker>`,
IDEs, linters, etc. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3457c14f-13b6-449d-99f1-ee759cc326cb | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,433 | supabase-export-v2 | 688b23809d8c5cf5 | Coroutines can be annotated using :class:`Coroutine[YieldType, SendType, ReturnType] <collections.abc.Coroutine>`. Generic arguments correspond to those of :class:`~collections.abc.Generator`, for example::
from collections.abc import Coroutine
c: Coroutine[list[str], str, int] # Some coroutine defined elsewhere
x = ... | trusted_official_docs | CPython Docs | Coroutines can be annotated using :class:`Coroutine[YieldType, SendType, ReturnType] <collections.abc.Coroutine>`. Generic arguments correspond to those of :class:`~collections.abc.Generator`, for example::
from collections.abc import Coroutine
c: Coroutine[list[str], str, int] # Some coroutine defined elsewhere
x = ... | Coroutines can be annotated using :class:`Coroutine[YieldType, SendType, ReturnType] <collections.abc.Coroutine>`. Generic arguments correspond to those of :class:`~collections.abc.Generator`, for example::
from collections.abc import Coroutine
c: Coroutine[list[str], str, int] # Some coroutine defined elsewhere
x = ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
34ab7ff2-10fd-49cf-9e7d-f2c1a5e7a6e2 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,166 | supabase-export-v2 | 09bd73bc06da8a79 | 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:: | trusted_official_docs | CPython Docs | 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:: | 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:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
34d4671a-7479-4a9d-a93b-755705ce34ae | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,705 | supabase-export-v2 | 44a13866a73947c0 | assert Annotated[Annotated[int, ValueRange(3, 10)], ctype("char")] == Annotated[ int, ValueRange(3, 10), ctype("char") ]
However, this does not apply to ``Annotated`` types referenced through a type
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`:: | trusted_official_docs | CPython Docs | assert Annotated[Annotated[int, ValueRange(3, 10)], ctype("char")] == Annotated[ int, ValueRange(3, 10), ctype("char") ]
However, this does not apply to ``Annotated`` types referenced through a type
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`:: | assert Annotated[Annotated[int, ValueRange(3, 10)], ctype("char")] == Annotated[ int, ValueRange(3, 10), ctype("char") ]
However, this does not apply to ``Annotated`` types referenced through a type
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
36066c25-8c3e-4cf1-89a8-537f3588241c | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,734 | supabase-export-v2 | 1198f598706bb309 | This value encodes the information supplied in the type expression, and it represents the type described by that type expression.
When used in a type expression, ``TypeForm`` describes a set of type form
objects. It accepts a single type argument, which must be a valid type
expression. ``TypeForm[T]`` describes the s... | trusted_official_docs | CPython Docs | This value encodes the information supplied in the type expression, and it represents the type described by that type expression.
When used in a type expression, ``TypeForm`` describes a set of type form
objects. It accepts a single type argument, which must be a valid type
expression. ``TypeForm[T]`` describes the s... | This value encodes the information supplied in the type expression, and it represents the type described by that type expression.
When used in a type expression, ``TypeForm`` describes a set of type form
objects. It accepts a single type argument, which must be a valid type
expression. ``TypeForm[T]`` describes the s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3756f729-0547-4a6f-9c53-0540d9949cc9 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,866 | supabase-export-v2 | ed282e99e61db805 | def move_first_element_to_last(tup: tuple[T, *Ts]) -> tuple[*Ts, T]: return (*tup[1:], tup[0])
A normal type variable enables parameterization with a single type. A type
variable tuple, in contrast, allows parameterization with an
*arbitrary* number of types by acting like an *arbitrary* number of type
variables wra... | trusted_official_docs | CPython Docs | def move_first_element_to_last(tup: tuple[T, *Ts]) -> tuple[*Ts, T]: return (*tup[1:], tup[0])
A normal type variable enables parameterization with a single type. A type
variable tuple, in contrast, allows parameterization with an
*arbitrary* number of types by acting like an *arbitrary* number of type
variables wra... | def move_first_element_to_last(tup: tuple[T, *Ts]) -> tuple[*Ts, T]: return (*tup[1:], tup[0])
A normal type variable enables parameterization with a single type. A type
variable tuple, in contrast, allows parameterization with an
*arbitrary* number of types by acting like an *arbitrary* number of type
variables wra... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
39b895f2-74e7-4b31-a939-779daf9bed33 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,706 | supabase-export-v2 | 95fe37311de95bc6 | However, this does not apply to ``Annotated`` types referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type From3To10[T] = Annotated[T, ValueRange(3, 10)]
assert Annotated[From3To10[int], ctype("char")] != Annotated[
int, ValueRange(3, 10), ctype("char")
] | trusted_official_docs | CPython Docs | However, this does not apply to ``Annotated`` types referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type From3To10[T] = Annotated[T, ValueRange(3, 10)]
assert Annotated[From3To10[int], ctype("char")] != Annotated[
int, ValueRange(3, 10), ctype("char")
] | However, this does not apply to ``Annotated`` types referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type From3To10[T] = Annotated[T, ValueRange(3, 10)]
assert Annotated[From3To10[int], ctype("char")] != Annotated[
int, ValueRange(3, 10), ctype("char")
] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
39fea18a-be63-4667-8f81-1c1e9cb69922 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,723 | supabase-export-v2 | e959d888b6588786 | >>> from typing import Annotated >>> X = Annotated[int, "very", "important", "metadata"] >>> X typing.Annotated[int, 'very', 'important', 'metadata'] >>> X.__metadata__ ('very', 'important', 'metadata')
If you want to retrieve the original type wrapped by ``Annotated``, use the
:attr:`!__origin__` attribute: | trusted_official_docs | CPython Docs | >>> from typing import Annotated >>> X = Annotated[int, "very", "important", "metadata"] >>> X typing.Annotated[int, 'very', 'important', 'metadata'] >>> X.__metadata__ ('very', 'important', 'metadata')
If you want to retrieve the original type wrapped by ``Annotated``, use the
:attr:`!__origin__` attribute: | >>> from typing import Annotated >>> X = Annotated[int, "very", "important", "metadata"] >>> X typing.Annotated[int, 'very', 'important', 'metadata'] >>> X.__metadata__ ('very', 'important', 'metadata')
If you want to retrieve the original type wrapped by ``Annotated``, use the
:attr:`!__origin__` attribute: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3abd8d15-9f28-4701-bfdc-dff4591426f1 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,792 | supabase-export-v2 | d5163427232f6998 | def lookup_name[X, Y](mapping: Mapping[X, Y], key: X, default: Y) -> Y: try: return mapping[key] except KeyError: return default
Here the brackets after the function name indicate a
:ref:`generic function <generic-functions>`. | trusted_official_docs | CPython Docs | def lookup_name[X, Y](mapping: Mapping[X, Y], key: X, default: Y) -> Y: try: return mapping[key] except KeyError: return default
Here the brackets after the function name indicate a
:ref:`generic function <generic-functions>`. | def lookup_name[X, Y](mapping: Mapping[X, Y], key: X, default: Y) -> Y: try: return mapping[key] except KeyError: return default
Here the brackets after the function name indicate a
:ref:`generic function <generic-functions>`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3ae4afef-3b85-4171-b8bd-e547c9e96d92 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,003 | supabase-export-v2 | 5197670429dfe3b5 | Fields with a default value must come after any fields without a default.
The resulting class has an extra attribute ``__annotations__`` giving a
dict that maps the field names to the field types. (The field names are in
the ``_fields`` attribute and the default values are in the
``_field_defaults`` attribute, both ... | trusted_official_docs | CPython Docs | Fields with a default value must come after any fields without a default.
The resulting class has an extra attribute ``__annotations__`` giving a
dict that maps the field names to the field types. (The field names are in
the ``_fields`` attribute and the default values are in the
``_field_defaults`` attribute, both ... | Fields with a default value must come after any fields without a default.
The resulting class has an extra attribute ``__annotations__`` giving a
dict that maps the field names to the field types. (The field names are in
the ``_fields`` attribute and the default values are in the
``_field_defaults`` attribute, both ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3bb5dd5c-e250-4811-9969-df29bbb2af71 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,646 | supabase-export-v2 | 868c6dfa0172e0d9 | However, this does not apply to ``Literal`` types referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type A = Literal[1, 2]
assert Literal[A, 3] != Literal[1, 2, 3] | trusted_official_docs | CPython Docs | However, this does not apply to ``Literal`` types referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type A = Literal[1, 2]
assert Literal[A, 3] != Literal[1, 2, 3] | However, this does not apply to ``Literal`` types referenced through a type alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
type A = Literal[1, 2]
assert Literal[A, 3] != Literal[1, 2, 3] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3ca077ba-4cc8-4da4-b1aa-04baa54042f4 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,809 | supabase-export-v2 | cd5ac7ce48aed8f5 | def print_capitalized[S: str](x: S) -> S: """Print x capitalized, and return x.""" print(x.capitalize()) return x
def concatenate[A: (str, bytes)](x: A, y: A) -> A:
"""Add two strings or bytes objects together."""
return x + y | trusted_official_docs | CPython Docs | def print_capitalized[S: str](x: S) -> S: """Print x capitalized, and return x.""" print(x.capitalize()) return x
def concatenate[A: (str, bytes)](x: A, y: A) -> A:
"""Add two strings or bytes objects together."""
return x + y | def print_capitalized[S: str](x: S) -> S: """Print x capitalized, and return x.""" print(x.capitalize()) return x
def concatenate[A: (str, bytes)](x: A, y: A) -> A:
"""Add two strings or bytes objects together."""
return x + y | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3e325e7a-3d20-48c7-bf30-6d4c7dd629a5 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,242 | supabase-export-v2 | 3576ac46033082ba | 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
... | trusted_official_docs | CPython Docs | 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
... | 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
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3e7eefcd-e9ff-43fa-8388-2b7a46a09880 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,393 | supabase-export-v2 | c7886e5fe5ece492 | # Type checker error: ``list`` only accepts a single type argument: y: list[int, str] = [1, 'foo']
# Type checker will infer that all keys in ``z`` are meant to be strings,
# and that all values in ``z`` are meant to be either strings or ints
z: Mapping[str, str | int] = {} | trusted_official_docs | CPython Docs | # Type checker error: ``list`` only accepts a single type argument: y: list[int, str] = [1, 'foo']
# Type checker will infer that all keys in ``z`` are meant to be strings,
# and that all values in ``z`` are meant to be either strings or ints
z: Mapping[str, str | int] = {} | # Type checker error: ``list`` only accepts a single type argument: y: list[int, str] = [1, 'foo']
# Type checker will infer that all keys in ``z`` are meant to be strings,
# and that all values in ``z`` are meant to be either strings or ints
z: Mapping[str, str | int] = {} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3f1f3679-7f34-4e81-8a7d-b59df6e052dc | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,188 | supabase-export-v2 | 4a633b9c06380df1 | Note that the runtime type may be different from (more or less specific than) the type statically inferred by a type checker.
Most type checkers support ``reveal_type()`` anywhere, even if the
name is not imported from ``typing``. Importing the name from
``typing``, however, allows your code to run without runtime er... | trusted_official_docs | CPython Docs | Note that the runtime type may be different from (more or less specific than) the type statically inferred by a type checker.
Most type checkers support ``reveal_type()`` anywhere, even if the
name is not imported from ``typing``. Importing the name from
``typing``, however, allows your code to run without runtime er... | Note that the runtime type may be different from (more or less specific than) the type statically inferred by a type checker.
Most type checkers support ``reveal_type()`` anywhere, even if the
name is not imported from ``typing``. Importing the name from
``typing``, however, allows your code to run without runtime er... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3f6efaac-ccd3-4721-8dd8-b3da509f340c | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,818 | supabase-export-v2 | 01f01ba5d42299db | The upper bound of a type variable can be a concrete type, abstract type (ABC or Protocol), or even a union of types::
# Can be anything with an __abs__ method
def print_abs[T: SupportsAbs](arg: T) -> None:
print("Absolute value:", abs(arg)) | trusted_official_docs | CPython Docs | The upper bound of a type variable can be a concrete type, abstract type (ABC or Protocol), or even a union of types::
# Can be anything with an __abs__ method
def print_abs[T: SupportsAbs](arg: T) -> None:
print("Absolute value:", abs(arg)) | The upper bound of a type variable can be a concrete type, abstract type (ABC or Protocol), or even a union of types::
# Can be anything with an __abs__ method
def print_abs[T: SupportsAbs](arg: T) -> None:
print("Absolute value:", abs(arg)) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3f7eb7cb-cf7f-47d1-8bde-88eebf9dda14 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,618 | supabase-export-v2 | 1cc6a7ddc463b8ac | def foo(arg: int = 0) -> None: ...
On the other hand, if an explicit value of ``None`` is allowed, the
use of ``Optional`` is appropriate, whether the argument is optional
or not. For example:: | trusted_official_docs | CPython Docs | def foo(arg: int = 0) -> None: ...
On the other hand, if an explicit value of ``None`` is allowed, the
use of ``Optional`` is appropriate, whether the argument is optional
or not. For example:: | def foo(arg: int = 0) -> None: ...
On the other hand, if an explicit value of ``None`` is allowed, the
use of ``Optional`` is appropriate, whether the argument is optional
or not. For example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
40258c66-176b-44f3-ac18-eb66ae458330 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,658 | supabase-export-v2 | a71551b935196494 | 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 | trusted_official_docs | CPython Docs | 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 | 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 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
412625e5-b3de-44f7-a857-b6e773ea27e0 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,210 | supabase-export-v2 | de12a42ddfc02cc1 | :param bool kw_only_default: Indicates whether the ``kw_only`` parameter is assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``False``.
:param bool frozen_default:
Indicates whether the ``frozen`` parameter is
assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults ... | trusted_official_docs | CPython Docs | :param bool kw_only_default: Indicates whether the ``kw_only`` parameter is assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``False``.
:param bool frozen_default:
Indicates whether the ``frozen`` parameter is
assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults ... | :param bool kw_only_default: Indicates whether the ``kw_only`` parameter is assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults to ``False``.
:param bool frozen_default:
Indicates whether the ``frozen`` parameter is
assumed to be ``True`` or ``False`` if it is omitted by the caller. Defaults ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4171e676-5364-416e-808a-d7a6720d66df | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,950 | supabase-export-v2 | 802606018f555e35 | .. note:: Only parameter specification variables defined in global scope can be pickled.
.. seealso::
* :pep:`612` -- Parameter Specification Variables (the PEP which introduced
``ParamSpec`` and ``Concatenate``)
* :data:`Concatenate`
* :ref:`annotating-callables` | trusted_official_docs | CPython Docs | .. note:: Only parameter specification variables defined in global scope can be pickled.
.. seealso::
* :pep:`612` -- Parameter Specification Variables (the PEP which introduced
``ParamSpec`` and ``Concatenate``)
* :data:`Concatenate`
* :ref:`annotating-callables` | .. note:: Only parameter specification variables defined in global scope can be pickled.
.. seealso::
* :pep:`612` -- Parameter Specification Variables (the PEP which introduced
``ParamSpec`` and ``Concatenate``)
* :data:`Concatenate`
* :ref:`annotating-callables` | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4344ecb1-61c2-4847-b875-22214f497b66 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,873 | supabase-export-v2 | 9f4b9c65ef2af045 | Type variable tuples must *always* be unpacked. This helps distinguish type variable tuples from normal type variables::
x: Ts # Not valid
x: tuple[Ts] # Not valid
x: tuple[*Ts] # The correct way to do it | trusted_official_docs | CPython Docs | Type variable tuples must *always* be unpacked. This helps distinguish type variable tuples from normal type variables::
x: Ts # Not valid
x: tuple[Ts] # Not valid
x: tuple[*Ts] # The correct way to do it | Type variable tuples must *always* be unpacked. This helps distinguish type variable tuples from normal type variables::
x: Ts # Not valid
x: tuple[Ts] # Not valid
x: tuple[*Ts] # The correct way to do it | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
44c131a5-0c13-41a2-b580-17229851aa49 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,944 | supabase-export-v2 | c7f5aaeac025b92a | .. versionadded:: 3.13
Parameter specification variables created with ``covariant=True`` or
``contravariant=True`` can be used to declare covariant or contravariant
generic types. The ``bound`` argument is also accepted, similar to
:class:`TypeVar`. However the actual semantics of these keywords are yet to
be decid... | trusted_official_docs | CPython Docs | .. versionadded:: 3.13
Parameter specification variables created with ``covariant=True`` or
``contravariant=True`` can be used to declare covariant or contravariant
generic types. The ``bound`` argument is also accepted, similar to
:class:`TypeVar`. However the actual semantics of these keywords are yet to
be decid... | .. versionadded:: 3.13
Parameter specification variables created with ``covariant=True`` or
``contravariant=True`` can be used to declare covariant or contravariant
generic types. The ``bound`` argument is also accepted, similar to
:class:`TypeVar`. However the actual semantics of these keywords are yet to
be decid... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
48890fdd-89e8-4566-b877-e3e4d7334304 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,776 | supabase-export-v2 | 2bc07985d4d2842f | Ts = TypeVarTuple('Ts') tup: tuple[*Ts] # Syntax error on Python <= 3.10! tup: tuple[Unpack[Ts]] # Semantically equivalent, and backwards-compatible
``Unpack`` can also be used along with :class:`typing.TypedDict` for typing
``**kwargs`` in a function signature:: | trusted_official_docs | CPython Docs | Ts = TypeVarTuple('Ts') tup: tuple[*Ts] # Syntax error on Python <= 3.10! tup: tuple[Unpack[Ts]] # Semantically equivalent, and backwards-compatible
``Unpack`` can also be used along with :class:`typing.TypedDict` for typing
``**kwargs`` in a function signature:: | Ts = TypeVarTuple('Ts') tup: tuple[*Ts] # Syntax error on Python <= 3.10! tup: tuple[Unpack[Ts]] # Semantically equivalent, and backwards-compatible
``Unpack`` can also be used along with :class:`typing.TypedDict` for typing
``**kwargs`` in a function signature:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
48a2f33d-5ea4-4876-8dd7-f465cd37677d | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,207 | supabase-export-v2 | ba32f6d5dff3b9fa | The arguments to the ``dataclass_transform`` decorator can be used to customize the default behaviors of the decorated class, metaclass, or function:
:param bool eq_default:
Indicates whether the ``eq`` parameter is assumed to be
``True`` or ``False`` if it is omitted by the caller. Defaults to ``True``. | trusted_official_docs | CPython Docs | The arguments to the ``dataclass_transform`` decorator can be used to customize the default behaviors of the decorated class, metaclass, or function:
:param bool eq_default:
Indicates whether the ``eq`` parameter is assumed to be
``True`` or ``False`` if it is omitted by the caller. Defaults to ``True``. | The arguments to the ``dataclass_transform`` decorator can be used to customize the default behaviors of the decorated class, metaclass, or function:
:param bool eq_default:
Indicates whether the ``eq`` parameter is assumed to be
``True`` or ``False`` if it is omitted by the caller. Defaults to ``True``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4a0d814d-8ca3-4448-b9c5-9cd903abf388 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,774 | supabase-export-v2 | cc7cd1eb96f64020 | <TypeVarTuple>` and :class:`builtins.tuple <tuple>` types. You might see ``Unpack`` being used explicitly in older versions of Python, where ``*`` couldn't be used in certain places::
# In older versions of Python, TypeVarTuple and Unpack
# are located in the `typing_extensions` backports package. from typing_extensio... | trusted_official_docs | CPython Docs | <TypeVarTuple>` and :class:`builtins.tuple <tuple>` types. You might see ``Unpack`` being used explicitly in older versions of Python, where ``*`` couldn't be used in certain places::
# In older versions of Python, TypeVarTuple and Unpack
# are located in the `typing_extensions` backports package. from typing_extensio... | <TypeVarTuple>` and :class:`builtins.tuple <tuple>` types. You might see ``Unpack`` being used explicitly in older versions of Python, where ``*`` couldn't be used in certain places::
# In older versions of Python, TypeVarTuple and Unpack
# are located in the `typing_extensions` backports package. from typing_extensio... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4a346432-5484-4ad0-b154-5dc4ac3c9fd6 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,507 | supabase-export-v2 | 4e717716a8e296cd | it, and assigning it to a variable (or using it as a return value) of a more specialized type is a type error. For example::
def hash_a(item: object) -> int:
# Fails type checking; an object does not have a 'magic' method. item.magic()
... | trusted_official_docs | CPython Docs | it, and assigning it to a variable (or using it as a return value) of a more specialized type is a type error. For example::
def hash_a(item: object) -> int:
# Fails type checking; an object does not have a 'magic' method. item.magic()
... | it, and assigning it to a variable (or using it as a return value) of a more specialized type is a type error. For example::
def hash_a(item: object) -> int:
# Fails type checking; an object does not have a 'magic' method. item.magic()
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4b79bde1-8558-4094-b1b7-f0399193ec6b | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,942 | supabase-export-v2 | 3d0ba964223fd1de | .. method:: has_default()
Return whether or not the parameter specification has a default value. This is equivalent
to checking whether :attr:`__default__` is not the :data:`typing.NoDefault`
singleton, except that it does not force evaluation of the
:ref:`lazily evaluated <lazy-evaluation>` default value. | trusted_official_docs | CPython Docs | .. method:: has_default()
Return whether or not the parameter specification has a default value. This is equivalent
to checking whether :attr:`__default__` is not the :data:`typing.NoDefault`
singleton, except that it does not force evaluation of the
:ref:`lazily evaluated <lazy-evaluation>` default value. | .. method:: has_default()
Return whether or not the parameter specification has a default value. This is equivalent
to checking whether :attr:`__default__` is not the :data:`typing.NoDefault`
singleton, except that it does not force evaluation of the
:ref:`lazily evaluated <lazy-evaluation>` default value. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4cc49610-4e50-495c-9669-f004f5b19e95 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,491 | supabase-export-v2 | b06faf6f39cb638c | Note that generics with :class:`ParamSpec` may not have correct ``__parameters__`` after substitution in some cases because they are intended primarily for static type checking.
.. versionchanged:: 3.10
:class:`Generic` can now be parameterized over parameter expressions. See :class:`ParamSpec` and :pep:`612` for more... | trusted_official_docs | CPython Docs | Note that generics with :class:`ParamSpec` may not have correct ``__parameters__`` after substitution in some cases because they are intended primarily for static type checking.
.. versionchanged:: 3.10
:class:`Generic` can now be parameterized over parameter expressions. See :class:`ParamSpec` and :pep:`612` for more... | Note that generics with :class:`ParamSpec` may not have correct ``__parameters__`` after substitution in some cases because they are intended primarily for static type checking.
.. versionchanged:: 3.10
:class:`Generic` can now be parameterized over parameter expressions. See :class:`ParamSpec` and :pep:`612` for more... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4cf1add4-0788-4080-aeee-1a9d81eaf9b2 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,690 | supabase-export-v2 | 5f091cfb807951d2 | x]``. Metadata added using ``Annotated`` can be used by static analysis tools or at runtime. At runtime, the metadata is stored in a :attr:`!__metadata__` attribute.
If a library or tool encounters an annotation ``Annotated[T, x]`` and has
no special logic for the metadata, it should ignore the metadata and simply
tr... | trusted_official_docs | CPython Docs | x]``. Metadata added using ``Annotated`` can be used by static analysis tools or at runtime. At runtime, the metadata is stored in a :attr:`!__metadata__` attribute.
If a library or tool encounters an annotation ``Annotated[T, x]`` and has
no special logic for the metadata, it should ignore the metadata and simply
tr... | x]``. Metadata added using ``Annotated`` can be used by static analysis tools or at runtime. At runtime, the metadata is stored in a :attr:`!__metadata__` attribute.
If a library or tool encounters an annotation ``Annotated[T, x]`` and has
no special logic for the metadata, it should ignore the metadata and simply
tr... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4de749cd-69c8-4c3e-ae1a-c53035f66687 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,517 | supabase-export-v2 | 5df287cbebf565c2 | class Bucket(Sized, Iterable[int]): ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ...
:pep:`544` solves this problem by allowing users to write
the above code without explicit base classes in the class definition,
allowing ``Bucket`` to be implicitly considered a subtype of both ``Sized``
and `... | trusted_official_docs | CPython Docs | class Bucket(Sized, Iterable[int]): ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ...
:pep:`544` solves this problem by allowing users to write
the above code without explicit base classes in the class definition,
allowing ``Bucket`` to be implicitly considered a subtype of both ``Sized``
and `... | class Bucket(Sized, Iterable[int]): ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ...
:pep:`544` solves this problem by allowing users to write
the above code without explicit base classes in the class definition,
allowing ``Bucket`` to be implicitly considered a subtype of both ``Sized``
and `... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4e6a10d4-5bce-4134-851e-4229282f4533 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,071 | supabase-export-v2 | 4a4b0948f56ef1d6 | 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 | trusted_official_docs | CPython Docs | 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 | 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 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4e922ff4-7bed-49a5-a358-3f917c1a5d33 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,169 | supabase-export-v2 | 0aab68400cb4775b | This function is useful for ensuring the type checker's understanding of a script is in line with the developer's intentions::
def complex_function(arg: object):
# Do some complex type-narrowing logic,
# after which we hope the inferred type will be `int`
... # Test whether the type checker correctly understands our... | trusted_official_docs | CPython Docs | This function is useful for ensuring the type checker's understanding of a script is in line with the developer's intentions::
def complex_function(arg: object):
# Do some complex type-narrowing logic,
# after which we hope the inferred type will be `int`
... # Test whether the type checker correctly understands our... | This function is useful for ensuring the type checker's understanding of a script is in line with the developer's intentions::
def complex_function(arg: object):
# Do some complex type-narrowing logic,
# after which we hope the inferred type will be `int`
... # Test whether the type checker correctly understands our... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4e9b3198-f0f2-4760-845c-f4ef14c03ad7 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,759 | supabase-export-v2 | fd2059577b5a997f | Special typing construct for marking user-defined type predicate functions.
Type predicate functions are user-defined functions that return whether their
argument is an instance of a particular type. ``TypeGuard`` works similarly to :data:`TypeIs`, but has subtly different
effects on type checking behavior (see below... | trusted_official_docs | CPython Docs | Special typing construct for marking user-defined type predicate functions.
Type predicate functions are user-defined functions that return whether their
argument is an instance of a particular type. ``TypeGuard`` works similarly to :data:`TypeIs`, but has subtly different
effects on type checking behavior (see below... | Special typing construct for marking user-defined type predicate functions.
Type predicate functions are user-defined functions that return whether their
argument is an instance of a particular type. ``TypeGuard`` works similarly to :data:`TypeIs`, but has subtly different
effects on type checking behavior (see below... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
50e2bb34-f0be-4c8f-b321-dc4d8e37deeb | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,952 | supabase-export-v2 | f876e0d663e1f265 | .. data:: ParamSpecArgs ParamSpecKwargs
Arguments and keyword arguments attributes of a :class:`ParamSpec`. The
``P.args`` attribute of a ``ParamSpec`` is an instance of ``ParamSpecArgs``,
and ``P.kwargs`` is an instance of ``ParamSpecKwargs``. They are intended
for runtime introspection and have no special meaning ... | trusted_official_docs | CPython Docs | .. data:: ParamSpecArgs ParamSpecKwargs
Arguments and keyword arguments attributes of a :class:`ParamSpec`. The
``P.args`` attribute of a ``ParamSpec`` is an instance of ``ParamSpecArgs``,
and ``P.kwargs`` is an instance of ``ParamSpecKwargs``. They are intended
for runtime introspection and have no special meaning ... | .. data:: ParamSpecArgs ParamSpecKwargs
Arguments and keyword arguments attributes of a :class:`ParamSpec`. The
``P.args`` attribute of a ``ParamSpec`` is an instance of ``ParamSpecArgs``,
and ``P.kwargs`` is an instance of ``ParamSpecKwargs``. They are intended
for runtime introspection and have no special meaning ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5129a8e5-955e-402f-a2c8-01a6a5d9b2fc | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,714 | supabase-export-v2 | f3fc8de22247944d | # When used in a type annotation, a type checker will treat "V" the same as # ``Annotated[list[tuple[int, int]], MaxLen(10)]``: type V = Vec[int]
``Annotated`` cannot be used with an unpacked :class:`TypeVarTuple`:: | trusted_official_docs | CPython Docs | # When used in a type annotation, a type checker will treat "V" the same as # ``Annotated[list[tuple[int, int]], MaxLen(10)]``: type V = Vec[int]
``Annotated`` cannot be used with an unpacked :class:`TypeVarTuple`:: | # When used in a type annotation, a type checker will treat "V" the same as # ``Annotated[list[tuple[int, int]], MaxLen(10)]``: type V = Vec[int]
``Annotated`` cannot be used with an unpacked :class:`TypeVarTuple`:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
51bbf703-7e74-47b7-ab1e-5fe5fd23f8e3 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,844 | supabase-export-v2 | 31dabeea517c4afc | .. versionchanged:: 3.12
For type variables created through :ref:`type parameter syntax <type-params>`,
the constraints are evaluated only when the attribute is accessed, not when
the type variable is created (see :ref:`lazy-evaluation`). | trusted_official_docs | CPython Docs | .. versionchanged:: 3.12
For type variables created through :ref:`type parameter syntax <type-params>`,
the constraints are evaluated only when the attribute is accessed, not when
the type variable is created (see :ref:`lazy-evaluation`). | .. versionchanged:: 3.12
For type variables created through :ref:`type parameter syntax <type-params>`,
the constraints are evaluated only when the attribute is accessed, not when
the type variable is created (see :ref:`lazy-evaluation`). | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
51e68451-6399-488d-9949-84cae83e9ce7 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,872 | supabase-export-v2 | 36d5b2566dad96fd | is equivalent to ``tuple[T, T1, T2, ...]``. (Note that in older versions of Python, you might see this written using :data:`Unpack <Unpack>` instead, as ``Unpack[Ts]``.)
Type variable tuples must *always* be unpacked. This helps distinguish type
variable tuples from normal type variables:: | trusted_official_docs | CPython Docs | is equivalent to ``tuple[T, T1, T2, ...]``. (Note that in older versions of Python, you might see this written using :data:`Unpack <Unpack>` instead, as ``Unpack[Ts]``.)
Type variable tuples must *always* be unpacked. This helps distinguish type
variable tuples from normal type variables:: | is equivalent to ``tuple[T, T1, T2, ...]``. (Note that in older versions of Python, you might see this written using :data:`Unpack <Unpack>` instead, as ``Unpack[Ts]``.)
Type variable tuples must *always* be unpacked. This helps distinguish type
variable tuples from normal type variables:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5272fd09-1c45-4cd3-8e33-e7ffdfd842c5 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,227 | supabase-export-v2 | 270697004fff6ec6 | None: ... @overload def process(response: int) -> tuple[int, str]: ... @overload def process(response: bytes) -> str: ... def process(response): ... # actual implementation goes here
See :pep:`484` for more details and comparison with other typing semantics. | trusted_official_docs | CPython Docs | None: ... @overload def process(response: int) -> tuple[int, str]: ... @overload def process(response: bytes) -> str: ... def process(response): ... # actual implementation goes here
See :pep:`484` for more details and comparison with other typing semantics. | None: ... @overload def process(response: int) -> tuple[int, str]: ... @overload def process(response: bytes) -> str: ... def process(response): ... # actual implementation goes here
See :pep:`484` for more details and comparison with other typing semantics. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
52a2c631-c580-4b9f-9b2e-ec065fcdf51b | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,206 | supabase-export-v2 | cfd9ed0308747729 | ``eq``, ``order``, ``unsafe_hash``, ``frozen``, ``match_args``, ``kw_only``, and ``slots``. It must be possible for the value of these arguments (``True`` or ``False``) to be statically evaluated.
The arguments to the ``dataclass_transform`` decorator can be used to
customize the default behaviors of the decorated cla... | trusted_official_docs | CPython Docs | ``eq``, ``order``, ``unsafe_hash``, ``frozen``, ``match_args``, ``kw_only``, and ``slots``. It must be possible for the value of these arguments (``True`` or ``False``) to be statically evaluated.
The arguments to the ``dataclass_transform`` decorator can be used to
customize the default behaviors of the decorated cla... | ``eq``, ``order``, ``unsafe_hash``, ``frozen``, ``match_args``, ``kw_only``, and ``slots``. It must be possible for the value of these arguments (``True`` or ``False``) to be statically evaluated.
The arguments to the ``dataclass_transform`` decorator can be used to
customize the default behaviors of the decorated cla... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
532b68c6-7223-4255-9512-40deec1e426e | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,016 | supabase-export-v2 | c28d893806c337fa | .. versionchanged:: 3.8 The ``_field_types`` and ``__annotations__`` attributes are now regular dictionaries instead of instances of ``OrderedDict``.
.. versionchanged:: 3.9
Removed the ``_field_types`` attribute in favor of the more
standard ``__annotations__`` attribute which has the same information. | trusted_official_docs | CPython Docs | .. versionchanged:: 3.8 The ``_field_types`` and ``__annotations__`` attributes are now regular dictionaries instead of instances of ``OrderedDict``.
.. versionchanged:: 3.9
Removed the ``_field_types`` attribute in favor of the more
standard ``__annotations__`` attribute which has the same information. | .. versionchanged:: 3.8 The ``_field_types`` and ``__annotations__`` attributes are now regular dictionaries instead of instances of ``OrderedDict``.
.. versionchanged:: 3.9
Removed the ``_field_types`` attribute in favor of the more
standard ``__annotations__`` attribute which has the same information. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
53cc85dc-980e-4bf5-be9b-4d3cc598d09e | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,299 | supabase-export-v2 | 2975b5a6fd480c11 | can be simple classes like :class:`float` or :class:`str`, they can also be more complex. The :mod:`typing` module provides a vocabulary of more advanced type hints.
New features are frequently added to the ``typing`` module. The :pypi:`typing_extensions` package
provides backports of these new features to older versio... | trusted_official_docs | CPython Docs | can be simple classes like :class:`float` or :class:`str`, they can also be more complex. The :mod:`typing` module provides a vocabulary of more advanced type hints.
New features are frequently added to the ``typing`` module. The :pypi:`typing_extensions` package
provides backports of these new features to older versio... | can be simple classes like :class:`float` or :class:`str`, they can also be more complex. The :mod:`typing` module provides a vocabulary of more advanced type hints.
New features are frequently added to the ``typing`` module. The :pypi:`typing_extensions` package
provides backports of these new features to older versio... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5417912e-f1c1-43a2-b40b-ffe9c0ae9a0e | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,248 | supabase-export-v2 | c50602a229692402 | Decorator to indicate that annotations are not type hints.
This works as a class or function :term:`decorator`. With a class, it
applies recursively to all methods and classes defined in that class
(but not to methods defined in its superclasses or subclasses). Type
checkers will ignore all annotations in a function... | trusted_official_docs | CPython Docs | Decorator to indicate that annotations are not type hints.
This works as a class or function :term:`decorator`. With a class, it
applies recursively to all methods and classes defined in that class
(but not to methods defined in its superclasses or subclasses). Type
checkers will ignore all annotations in a function... | Decorator to indicate that annotations are not type hints.
This works as a class or function :term:`decorator`. With a class, it
applies recursively to all methods and classes defined in that class
(but not to methods defined in its superclasses or subclasses). Type
checkers will ignore all annotations in a function... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
54fa7848-96f5-4ef3-b3f6-6380bce4d702 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,231 | supabase-export-v2 | dd33619f006c6703 | Return a sequence of :deco:`overload`-decorated definitions for *func*.
*func* is the function object for the implementation of the
overloaded function. For example, given the definition of ``process`` in
the documentation for :deco:`overload`,
``get_overloads(process)`` will return a sequence of three function obje... | trusted_official_docs | CPython Docs | Return a sequence of :deco:`overload`-decorated definitions for *func*.
*func* is the function object for the implementation of the
overloaded function. For example, given the definition of ``process`` in
the documentation for :deco:`overload`,
``get_overloads(process)`` will return a sequence of three function obje... | Return a sequence of :deco:`overload`-decorated definitions for *func*.
*func* is the function object for the implementation of the
overloaded function. For example, given the definition of ``process`` in
the documentation for :deco:`overload`,
``get_overloads(process)`` will return a sequence of three function obje... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
55691655-99ab-49b5-8430-be35f7965dbd | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,154 | supabase-export-v2 | d7f23da8da1d8484 | .. class:: IO[AnyStr] TextIO BinaryIO
Generic class ``IO[AnyStr]`` and its subclasses ``TextIO(IO[str])``
and ``BinaryIO(IO[bytes])``
represent the types of I/O streams such as returned by
:func:`open`. Please note that these classes are not protocols, and
their interface is fairly broad. | trusted_official_docs | CPython Docs | .. class:: IO[AnyStr] TextIO BinaryIO
Generic class ``IO[AnyStr]`` and its subclasses ``TextIO(IO[str])``
and ``BinaryIO(IO[bytes])``
represent the types of I/O streams such as returned by
:func:`open`. Please note that these classes are not protocols, and
their interface is fairly broad. | .. class:: IO[AnyStr] TextIO BinaryIO
Generic class ``IO[AnyStr]`` and its subclasses ``TextIO(IO[str])``
and ``BinaryIO(IO[bytes])``
represent the types of I/O streams such as returned by
:func:`open`. Please note that these classes are not protocols, and
their interface is fairly broad. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
55cce329-2118-4ab1-adbd-dafe01c96303 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,051 | supabase-export-v2 | 692f79e00a32d40c | be used with :func:`isinstance` and :func:`issubclass`. This allows a simple-minded structural check, very similar to "one trick ponies" in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example::
@runtime_checkable
class Closable(Protocol):
def close(self): ... | trusted_official_docs | CPython Docs | be used with :func:`isinstance` and :func:`issubclass`. This allows a simple-minded structural check, very similar to "one trick ponies" in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example::
@runtime_checkable
class Closable(Protocol):
def close(self): ... | be used with :func:`isinstance` and :func:`issubclass`. This allows a simple-minded structural check, very similar to "one trick ponies" in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example::
@runtime_checkable
class Closable(Protocol):
def close(self): ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
563c1331-c449-4d9b-9e1e-a6af9ad28015 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,862 | supabase-export-v2 | 133b995d212d0bcf | Type variable tuples can be declared in :ref:`type parameter lists <type-params>` using a single asterisk (``*``) before the name::
def move_first_element_to_last[T, *Ts](tup: tuple[T, *Ts]) -> tuple[*Ts, T]:
return (*tup[1:], tup[0]) | trusted_official_docs | CPython Docs | Type variable tuples can be declared in :ref:`type parameter lists <type-params>` using a single asterisk (``*``) before the name::
def move_first_element_to_last[T, *Ts](tup: tuple[T, *Ts]) -> tuple[*Ts, T]:
return (*tup[1:], tup[0]) | Type variable tuples can be declared in :ref:`type parameter lists <type-params>` using a single asterisk (``*``) before the name::
def move_first_element_to_last[T, *Ts](tup: tuple[T, *Ts]) -> tuple[*Ts, T]:
return (*tup[1:], tup[0]) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
566ec01b-89d1-49e3-86dc-5a631e7b47a4 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,187 | supabase-export-v2 | 919f2d70600d894f | x = reveal_type(1) # prints "Runtime type is int" print(x) # prints "1"
Note that the runtime type may be different from (more or less specific
than) the type statically inferred by a type checker. | trusted_official_docs | CPython Docs | x = reveal_type(1) # prints "Runtime type is int" print(x) # prints "1"
Note that the runtime type may be different from (more or less specific
than) the type statically inferred by a type checker. | x = reveal_type(1) # prints "Runtime type is int" print(x) # prints "1"
Note that the runtime type may be different from (more or less specific
than) the type statically inferred by a type checker. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
57037f94-a080-487d-8665-3ea7bc3d811a | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,577 | supabase-export-v2 | dc7a27663484c79b | - :class:`classmethod`\s that are used as alternative constructors and return instances of the ``cls`` parameter. - Annotating an :meth:`~object.__enter__` method which returns self.
You should not use ``Self`` as the return annotation if the method is not
guaranteed to return an instance of a subclass when the class ... | trusted_official_docs | CPython Docs | - :class:`classmethod`\s that are used as alternative constructors and return instances of the ``cls`` parameter. - Annotating an :meth:`~object.__enter__` method which returns self.
You should not use ``Self`` as the return annotation if the method is not
guaranteed to return an instance of a subclass when the class ... | - :class:`classmethod`\s that are used as alternative constructors and return instances of the ``cls`` parameter. - Annotating an :meth:`~object.__enter__` method which returns self.
You should not use ``Self`` as the return annotation if the method is not
guaranteed to return an instance of a subclass when the class ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5829e581-1761-41ee-acfe-ebed236ad3e9 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,717 | supabase-export-v2 | 9d1b0648486bd863 | where ``T1``, ``T2``, ... are :class:`TypeVars <TypeVar>`. This is invalid as only one type should be passed to Annotated.
By default, :func:`get_type_hints` strips the metadata from annotations. Pass ``include_extras=True`` to have the metadata preserved: | trusted_official_docs | CPython Docs | where ``T1``, ``T2``, ... are :class:`TypeVars <TypeVar>`. This is invalid as only one type should be passed to Annotated.
By default, :func:`get_type_hints` strips the metadata from annotations. Pass ``include_extras=True`` to have the metadata preserved: | where ``T1``, ``T2``, ... are :class:`TypeVars <TypeVar>`. This is invalid as only one type should be passed to Annotated.
By default, :func:`get_type_hints` strips the metadata from annotations. Pass ``include_extras=True`` to have the metadata preserved: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
582dfd5f-240c-4500-b0b1-922713d41a1d | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,689 | supabase-export-v2 | 4c99e3759133d76d | Special typing form to add context-specific metadata to an annotation.
Add metadata ``x`` to a given type ``T`` by using the annotation
``Annotated[T, x]``. Metadata added using ``Annotated`` can be used by
static analysis tools or at runtime. At runtime, the metadata is stored
in a :attr:`!__metadata__` attribute. | trusted_official_docs | CPython Docs | Special typing form to add context-specific metadata to an annotation.
Add metadata ``x`` to a given type ``T`` by using the annotation
``Annotated[T, x]``. Metadata added using ``Annotated`` can be used by
static analysis tools or at runtime. At runtime, the metadata is stored
in a :attr:`!__metadata__` attribute. | Special typing form to add context-specific metadata to an annotation.
Add metadata ``x`` to a given type ``T`` by using the annotation
``Annotated[T, x]``. Metadata added using ``Annotated`` can be used by
static analysis tools or at runtime. At runtime, the metadata is stored
in a :attr:`!__metadata__` attribute. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5979bf71-672d-40d3-ab74-65dae0c8186e | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,345 | supabase-export-v2 | d65ebca8aef81bb4 | def fun(arg: expensive_mod.SomeType) -> None: local_var: expensive_mod.AnotherType = other_fun()
If you occasionally need to examine type annotations at runtime
which may contain undefined symbols, use
:meth:`annotationlib.get_annotations` with a ``format`` parameter
of :attr:`annotationlib.Format.STRING` or
:attr:... | trusted_official_docs | CPython Docs | def fun(arg: expensive_mod.SomeType) -> None: local_var: expensive_mod.AnotherType = other_fun()
If you occasionally need to examine type annotations at runtime
which may contain undefined symbols, use
:meth:`annotationlib.get_annotations` with a ``format`` parameter
of :attr:`annotationlib.Format.STRING` or
:attr:... | def fun(arg: expensive_mod.SomeType) -> None: local_var: expensive_mod.AnotherType = other_fun()
If you occasionally need to examine type annotations at runtime
which may contain undefined symbols, use
:meth:`annotationlib.get_annotations` with a ``format`` parameter
of :attr:`annotationlib.Format.STRING` or
:attr:... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5a665a9a-6cbf-4547-b69d-93b16a18e629 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,495 | supabase-export-v2 | 9d1bedc8cac8adcb | of type is :data:`Any`. A static type checker will treat every type as being compatible with :data:`Any` and :data:`Any` as being compatible with every type.
This means that it is possible to perform any operation or method call on a
value of type :data:`Any` and assign it to any variable:: | trusted_official_docs | CPython Docs | of type is :data:`Any`. A static type checker will treat every type as being compatible with :data:`Any` and :data:`Any` as being compatible with every type.
This means that it is possible to perform any operation or method call on a
value of type :data:`Any` and assign it to any variable:: | of type is :data:`Any`. A static type checker will treat every type as being compatible with :data:`Any` and :data:`Any` as being compatible with every type.
This means that it is possible to perform any operation or method call on a
value of type :data:`Any` and assign it to any variable:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5b64384b-6d46-4555-80da-e77647f0ef9b | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,735 | supabase-export-v2 | b5ae6aba263b046f | must be a valid type expression. ``TypeForm[T]`` describes the set of all type form objects that represent the type ``T`` or types assignable to ``T``.
``TypeForm(obj)`` simply returns ``obj`` unchanged. This is useful for
explicitly marking a value as a type form for static type checkers. | trusted_official_docs | CPython Docs | must be a valid type expression. ``TypeForm[T]`` describes the set of all type form objects that represent the type ``T`` or types assignable to ``T``.
``TypeForm(obj)`` simply returns ``obj`` unchanged. This is useful for
explicitly marking a value as a type form for static type checkers. | must be a valid type expression. ``TypeForm[T]`` describes the set of all type form objects that represent the type ``T`` or types assignable to ``T``.
``TypeForm(obj)`` simply returns ``obj`` unchanged. This is useful for
explicitly marking a value as a type form for static type checkers. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5bcbc611-b659-4730-bddb-b677307477d0 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,625 | supabase-export-v2 | 7eb2546c3eda8b92 | :ref:`Callable <annotating-callables>` type hints and when instantiating user-defined generic classes with :class:`ParamSpec` parameters. The last parameter to ``Concatenate`` must be a :class:`ParamSpec` or ellipsis (``...``).
For example, to annotate a decorator ``with_lock`` which provides a
:class:`threading.Lock`... | trusted_official_docs | CPython Docs | :ref:`Callable <annotating-callables>` type hints and when instantiating user-defined generic classes with :class:`ParamSpec` parameters. The last parameter to ``Concatenate`` must be a :class:`ParamSpec` or ellipsis (``...``).
For example, to annotate a decorator ``with_lock`` which provides a
:class:`threading.Lock`... | :ref:`Callable <annotating-callables>` type hints and when instantiating user-defined generic classes with :class:`ParamSpec` parameters. The last parameter to ``Concatenate`` must be a :class:`ParamSpec` or ellipsis (``...``).
For example, to annotate a decorator ``with_lock`` which provides a
:class:`threading.Lock`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5c683b60-f52a-474b-9c36-922c1a698a1a | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,755 | supabase-export-v2 | 6e1befb04a40b5c0 | ``TypeIs`` function is a class or instance method, then the type in ``TypeIs`` maps to the type of the second parameter (after ``cls`` or ``self``).
In short, the form ``def foo(arg: TypeA) -> TypeIs[TypeB]: ...``,
means that if ``foo(arg)`` returns ``True``, then ``arg`` is an instance
of ``TypeB``, and if it return... | trusted_official_docs | CPython Docs | ``TypeIs`` function is a class or instance method, then the type in ``TypeIs`` maps to the type of the second parameter (after ``cls`` or ``self``).
In short, the form ``def foo(arg: TypeA) -> TypeIs[TypeB]: ...``,
means that if ``foo(arg)`` returns ``True``, then ``arg`` is an instance
of ``TypeB``, and if it return... | ``TypeIs`` function is a class or instance method, then the type in ``TypeIs`` maps to the type of the second parameter (after ``cls`` or ``self``).
In short, the form ``def foo(arg: TypeA) -> TypeIs[TypeB]: ...``,
means that if ``foo(arg)`` returns ``True``, then ``arg`` is an instance
of ``TypeB``, and if it return... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5c918c77-2ff2-4110-b9fc-49fc39a05678 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,868 | supabase-export-v2 | d7b2d6bbbb5fe913 | # T is bound to int, Ts is bound to () # Return value is (1,), which has type tuple[int] move_first_element_to_last(tup=(1,))
# T is bound to int, Ts is bound to (str,)
# Return value is ('spam', 1), which has type tuple[str, int]
move_first_element_to_last(tup=(1, 'spam')) | trusted_official_docs | CPython Docs | # T is bound to int, Ts is bound to () # Return value is (1,), which has type tuple[int] move_first_element_to_last(tup=(1,))
# T is bound to int, Ts is bound to (str,)
# Return value is ('spam', 1), which has type tuple[str, int]
move_first_element_to_last(tup=(1, 'spam')) | # T is bound to int, Ts is bound to () # Return value is (1,), which has type tuple[int] move_first_element_to_last(tup=(1,))
# T is bound to int, Ts is bound to (str,)
# Return value is ('spam', 1), which has type tuple[str, int]
move_first_element_to_last(tup=(1, 'spam')) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5e19c712-10df-47bd-a78f-45820077865c | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,745 | supabase-export-v2 | 7b8cdd6a8c9fd7c9 | type predicate if isinstance(val, str): # Type of ``val`` is narrowed to ``str`` ... else: # Else, type of ``val`` is narrowed to ``float``. ...
Sometimes it would be convenient to use a user-defined boolean function
as a type predicate. Such a function should use ``TypeIs[...]`` or
:data:`TypeGuard` as its return ty... | trusted_official_docs | CPython Docs | type predicate if isinstance(val, str): # Type of ``val`` is narrowed to ``str`` ... else: # Else, type of ``val`` is narrowed to ``float``. ...
Sometimes it would be convenient to use a user-defined boolean function
as a type predicate. Such a function should use ``TypeIs[...]`` or
:data:`TypeGuard` as its return ty... | type predicate if isinstance(val, str): # Type of ``val`` is narrowed to ``str`` ... else: # Else, type of ``val`` is narrowed to ``float``. ...
Sometimes it would be convenient to use a user-defined boolean function
as a type predicate. Such a function should use ``TypeIs[...]`` or
:data:`TypeGuard` as its return ty... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5e8766de-ab6a-4c70-aac7-d5803c04e672 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,055 | supabase-export-v2 | b15ec3651501174e | import threading assert isinstance(threading.Thread(name='Bob'), Named)
Runtime checkability of protocols is not inherited. A subclass of a runtime-checkable protocol
is only runtime-checkable if it is explicitly marked as such, regardless of class hierarchy:: | trusted_official_docs | CPython Docs | import threading assert isinstance(threading.Thread(name='Bob'), Named)
Runtime checkability of protocols is not inherited. A subclass of a runtime-checkable protocol
is only runtime-checkable if it is explicitly marked as such, regardless of class hierarchy:: | import threading assert isinstance(threading.Thread(name='Bob'), Named)
Runtime checkability of protocols is not inherited. A subclass of a runtime-checkable protocol
is only runtime-checkable if it is explicitly marked as such, regardless of class hierarchy:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5fdedf55-51f9-4542-bd92-ba6dbac3347b | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,699 | supabase-export-v2 | 1220ac04563d658c | type. Multiple metadata elements can be supplied as ``Annotated`` supports variadic arguments. The order of the metadata elements is preserved and matters for equality checks::
@dataclass
class ctype:
kind: str | trusted_official_docs | CPython Docs | type. Multiple metadata elements can be supplied as ``Annotated`` supports variadic arguments. The order of the metadata elements is preserved and matters for equality checks::
@dataclass
class ctype:
kind: str | type. Multiple metadata elements can be supplied as ``Annotated`` supports variadic arguments. The order of the metadata elements is preserved and matters for equality checks::
@dataclass
class ctype:
kind: str | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6002d615-faa8-4471-9750-c48900a9ff24 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,396 | supabase-export-v2 | d8781788d18e8167 | which are not all of the same type. For this reason, tuples are special-cased in Python's typing system. :class:`tuple` accepts *any number* of type arguments::
# OK: ``x`` is assigned to a tuple of length 1 where the sole element is an int
x: tuple[int] = (5,) | trusted_official_docs | CPython Docs | which are not all of the same type. For this reason, tuples are special-cased in Python's typing system. :class:`tuple` accepts *any number* of type arguments::
# OK: ``x`` is assigned to a tuple of length 1 where the sole element is an int
x: tuple[int] = (5,) | which are not all of the same type. For this reason, tuples are special-cased in Python's typing system. :class:`tuple` accepts *any number* of type arguments::
# OK: ``x`` is assigned to a tuple of length 1 where the sole element is an int
x: tuple[int] = (5,) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
61d831d9-53e3-40f8-b980-a4ecdece601b | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,326 | supabase-export-v2 | 7d4f54098fe4539d | For example, ``List["SomeClass"]`` is implicitly transformed into ``List[ForwardRef("SomeClass")]``. :class:`!ForwardRef` should not be instantiated by a user, but may be used by introspection tools.
.. note::
:pep:`585` generic types such as ``list["SomeClass"]`` will not be
implicitly transformed into ``list[Forwar... | trusted_official_docs | CPython Docs | For example, ``List["SomeClass"]`` is implicitly transformed into ``List[ForwardRef("SomeClass")]``. :class:`!ForwardRef` should not be instantiated by a user, but may be used by introspection tools.
.. note::
:pep:`585` generic types such as ``list["SomeClass"]`` will not be
implicitly transformed into ``list[Forwar... | For example, ``List["SomeClass"]`` is implicitly transformed into ``List[ForwardRef("SomeClass")]``. :class:`!ForwardRef` should not be instantiated by a user, but may be used by introspection tools.
.. note::
:pep:`585` generic types such as ``list["SomeClass"]`` will not be
implicitly transformed into ``list[Forwar... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
62709554-2fc9-463f-ac31-3657bc351900 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,882 | supabase-export-v2 | b85a2186147623a7 | float_array_1d: Array[float, Height] = Array() # Totally fine int_array_2d: Array[int, Height, Width] = Array() # Yup, fine too
However, note that at most one type variable tuple may appear in a single
list of type arguments or type parameters:: | trusted_official_docs | CPython Docs | float_array_1d: Array[float, Height] = Array() # Totally fine int_array_2d: Array[int, Height, Width] = Array() # Yup, fine too
However, note that at most one type variable tuple may appear in a single
list of type arguments or type parameters:: | float_array_1d: Array[float, Height] = Array() # Totally fine int_array_2d: Array[int, Height, Width] = Array() # Yup, fine too
However, note that at most one type variable tuple may appear in a single
list of type arguments or type parameters:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
637420ab-a0fb-4928-9987-ed81a98d6f12 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,329 | supabase-export-v2 | ba36afc9784ceb7d | # fails type checking; an int is not a UserId user_b = get_user_name(-1)
You may still perform all ``int`` operations on a variable of type ``UserId``,
but the result will always be of type ``int``. This lets you pass in a
``UserId`` wherever an ``int`` might be expected, but will prevent you from
accidentally creating... | trusted_official_docs | CPython Docs | # fails type checking; an int is not a UserId user_b = get_user_name(-1)
You may still perform all ``int`` operations on a variable of type ``UserId``,
but the result will always be of type ``int``. This lets you pass in a
``UserId`` wherever an ``int`` might be expected, but will prevent you from
accidentally creating... | # fails type checking; an int is not a UserId user_b = get_user_name(-1)
You may still perform all ``int`` operations on a variable of type ``UserId``,
but the result will always be of type ``int``. This lets you pass in a
``UserId`` wherever an ``int`` might be expected, but will prevent you from
accidentally creating... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
648b6c99-5393-4011-8b02-f77538fdb485 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 30,624 | supabase-export-v2 | 82c693a97ebb29e9 | .. index:: single: ...; ellipsis literal
``Concatenate`` can be used in conjunction with :ref:`Callable <annotating-callables>` and
:class:`ParamSpec` to annotate a higher-order callable which adds, removes,
or transforms parameters of another
callable. Usage is in the form
``Concatenate[Arg1Type, Arg2Type, ..., Pa... | trusted_official_docs | CPython Docs | .. index:: single: ...; ellipsis literal
``Concatenate`` can be used in conjunction with :ref:`Callable <annotating-callables>` and
:class:`ParamSpec` to annotate a higher-order callable which adds, removes,
or transforms parameters of another
callable. Usage is in the form
``Concatenate[Arg1Type, Arg2Type, ..., Pa... | .. index:: single: ...; ellipsis literal
``Concatenate`` can be used in conjunction with :ref:`Callable <annotating-callables>` and
:class:`ParamSpec` to annotate a higher-order callable which adds, removes,
or transforms parameters of another
callable. Usage is in the form
``Concatenate[Arg1Type, Arg2Type, ..., Pa... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
65d0e2a2-a1f5-45f8-8f15-11aa5ecf68b5 | CPython Docs | file://datasets/cpython/Doc/library/typing.rst | unknown | 761dcd07-e75b-4e99-a2c4-881ccac2b544 | 31,526 | supabase-export-v2 | be2d197428a449b4 | Deprecation Timeline of Major Features ======================================
Certain features in ``typing`` are deprecated and may be removed in a future
version of Python. The following table summarizes major deprecations for your
convenience. This is subject to change, and not all deprecations are listed. | trusted_official_docs | CPython Docs | Deprecation Timeline of Major Features ======================================
Certain features in ``typing`` are deprecated and may be removed in a future
version of Python. The following table summarizes major deprecations for your
convenience. This is subject to change, and not all deprecations are listed. | Deprecation Timeline of Major Features ======================================
Certain features in ``typing`` are deprecated and may be removed in a future
version of Python. The following table summarizes major deprecations for your
convenience. This is subject to change, and not all deprecations are listed. | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.