doc_content stringlengths 1 386k | doc_id stringlengths 5 188 |
|---|---|
types.FunctionType
types.LambdaType
The type of user-defined functions and functions created by lambda expressions. Raises an auditing event function.__new__ with argument code. The audit event only occurs for direct instantiation of function objects, and is not raised for normal compilation. | python.library.types#types.FunctionType |
types.GeneratorType
The type of generator-iterator objects, created by generator functions. | python.library.types#types.GeneratorType |
class types.GenericAlias(t_origin, t_args)
The type of parameterized generics such as list[int]. t_origin should be a non-parameterized generic class, such as list, tuple or dict. t_args should be a tuple (possibly of length 1) of types which parameterize t_origin: >>> from types import GenericAlias
>>> list[int] ==... | python.library.types#types.GenericAlias |
types.GetSetDescriptorType
The type of objects defined in extension modules with PyGetSetDef, such as FrameType.f_locals or array.array.typecode. This type is used as descriptor for object attributes; it has the same purpose as the property type, but for classes defined in extension modules. | python.library.types#types.GetSetDescriptorType |
types.FunctionType
types.LambdaType
The type of user-defined functions and functions created by lambda expressions. Raises an auditing event function.__new__ with argument code. The audit event only occurs for direct instantiation of function objects, and is not raised for normal compilation. | python.library.types#types.LambdaType |
class types.MappingProxyType(mapping)
Read-only proxy of a mapping. It provides a dynamic view on the mapping’s entries, which means that when the mapping changes, the view reflects these changes. New in version 3.3. Changed in version 3.9: Updated to support the new union (|) operator from PEP 584, which simply d... | python.library.types#types.MappingProxyType |
copy()
Return a shallow copy of the underlying mapping. | python.library.types#types.MappingProxyType.copy |
get(key[, default])
Return the value for key if key is in the underlying mapping, else default. If default is not given, it defaults to None, so that this method never raises a KeyError. | python.library.types#types.MappingProxyType.get |
items()
Return a new view of the underlying mapping’s items ((key, value) pairs). | python.library.types#types.MappingProxyType.items |
keys()
Return a new view of the underlying mapping’s keys. | python.library.types#types.MappingProxyType.keys |
values()
Return a new view of the underlying mapping’s values. | python.library.types#types.MappingProxyType.values |
types.MemberDescriptorType
The type of objects defined in extension modules with PyMemberDef, such as datetime.timedelta.days. This type is used as descriptor for simple C data members which use standard conversion functions; it has the same purpose as the property type, but for classes defined in extension modules. ... | python.library.types#types.MemberDescriptorType |
types.MethodDescriptorType
The type of methods of some built-in data types such as str.join(). New in version 3.7. | python.library.types#types.MethodDescriptorType |
types.MethodType
The type of methods of user-defined class instances. | python.library.types#types.MethodType |
types.MethodWrapperType
The type of bound methods of some built-in data types and base classes. For example it is the type of object().__str__. New in version 3.7. | python.library.types#types.MethodWrapperType |
class types.ModuleType(name, doc=None)
The type of modules. The constructor takes the name of the module to be created and optionally its docstring. Note Use importlib.util.module_from_spec() to create a new module if you wish to set the various import-controlled attributes.
__doc__
The docstring of the module.... | python.library.types#types.ModuleType |
__doc__
The docstring of the module. Defaults to None. | python.library.types#types.ModuleType.__doc__ |
__loader__
The loader which loaded the module. Defaults to None. This attribute is to match importlib.machinery.ModuleSpec.loader as stored in the attr:__spec__ object. Note A future version of Python may stop setting this attribute by default. To guard against this potential change, preferrably read from the __spec... | python.library.types#types.ModuleType.__loader__ |
__name__
The name of the module. Expected to match importlib.machinery.ModuleSpec.name. | python.library.types#types.ModuleType.__name__ |
__package__
Which package a module belongs to. If the module is top-level (i.e. not a part of any specific package) then the attribute should be set to '', else it should be set to the name of the package (which can be __name__ if the module is a package itself). Defaults to None. This attribute is to match importlib... | python.library.types#types.ModuleType.__package__ |
__spec__
A record of the the module’s import-system-related state. Expected to be an instance of importlib.machinery.ModuleSpec. New in version 3.4. | python.library.types#types.ModuleType.__spec__ |
types.new_class(name, bases=(), kwds=None, exec_body=None)
Creates a class object dynamically using the appropriate metaclass. The first three arguments are the components that make up a class definition header: the class name, the base classes (in order), the keyword arguments (such as metaclass). The exec_body argu... | python.library.types#types.new_class |
types.prepare_class(name, bases=(), kwds=None)
Calculates the appropriate metaclass and creates the class namespace. The arguments are the components that make up a class definition header: the class name, the base classes (in order) and the keyword arguments (such as metaclass). The return value is a 3-tuple: metacl... | python.library.types#types.prepare_class |
types.resolve_bases(bases)
Resolve MRO entries dynamically as specified by PEP 560. This function looks for items in bases that are not instances of type, and returns a tuple where each such object that has an __mro_entries__ method is replaced with an unpacked result of calling this method. If a bases item is an ins... | python.library.types#types.resolve_bases |
class types.SimpleNamespace
A simple object subclass that provides attribute access to its namespace, as well as a meaningful repr. Unlike object, with SimpleNamespace you can add and remove attributes. If a SimpleNamespace object is initialized with keyword arguments, those are directly added to the underlying names... | python.library.types#types.SimpleNamespace |
class types.TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
The type of traceback objects such as found in sys.exc_info()[2]. See the language reference for details of the available attributes and operations, and guidance on creating tracebacks dynamically. | python.library.types#types.TracebackType |
types.WrapperDescriptorType
The type of methods of some built-in data types and base classes such as object.__init__() or object.__lt__(). New in version 3.7. | python.library.types#types.WrapperDescriptorType |
typing — Support for type hints New in version 3.5. Source code: Lib/typing.py Note The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers, IDEs, linters, etc. This module provides runtime support for type hints as specified by PEP 484... | python.library.typing |
class typing.AbstractSet(Sized, Collection[T_co])
A generic version of collections.abc.Set. Deprecated since version 3.9: collections.abc.Set now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.AbstractSet |
typing.Annotated
A type, introduced in PEP 593 (Flexible function and variable
annotations), to decorate existing types with context-specific metadata (possibly multiple pieces of it, as Annotated is variadic). Specifically, a type T can be annotated with metadata x via the typehint Annotated[T, x]. This metadata can... | python.library.typing#typing.Annotated |
typing.Any
Special type indicating an unconstrained type. Every type is compatible with Any.
Any is compatible with every type. | python.library.typing#typing.Any |
typing.AnyStr
AnyStr is a type variable defined as AnyStr = TypeVar('AnyStr', str, bytes). It is meant to be used for functions that may accept any kind of string without allowing different kinds of strings to mix. For example: def concat(a: AnyStr, b: AnyStr) -> AnyStr:
return a + b
concat(u"foo", u"bar") # Ok... | python.library.typing#typing.AnyStr |
class typing.AsyncContextManager(Generic[T_co])
A generic version of contextlib.AbstractAsyncContextManager. New in version 3.5.4. New in version 3.6.2. Deprecated since version 3.9: contextlib.AbstractAsyncContextManager now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.AsyncContextManager |
class typing.AsyncGenerator(AsyncIterator[T_co], Generic[T_co, T_contra])
An async generator can be annotated by the generic type AsyncGenerator[YieldType, SendType]. For example: async def echo_round() -> AsyncGenerator[int, float]:
sent = yield 0
while sent >= 0.0:
rounded = await round(sent)
... | python.library.typing#typing.AsyncGenerator |
class typing.AsyncIterable(Generic[T_co])
A generic version of collections.abc.AsyncIterable. New in version 3.5.2. Deprecated since version 3.9: collections.abc.AsyncIterable now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.AsyncIterable |
class typing.AsyncIterator(AsyncIterable[T_co])
A generic version of collections.abc.AsyncIterator. New in version 3.5.2. Deprecated since version 3.9: collections.abc.AsyncIterator now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.AsyncIterator |
class typing.Awaitable(Generic[T_co])
A generic version of collections.abc.Awaitable. New in version 3.5.2. Deprecated since version 3.9: collections.abc.Awaitable now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Awaitable |
class typing.IO
class typing.TextIO
class typing.BinaryIO
Generic type IO[AnyStr] and its subclasses TextIO(IO[str]) and BinaryIO(IO[bytes]) represent the types of I/O streams such as returned by open(). These types are also in the typing.io namespace. | python.library.typing#typing.BinaryIO |
class typing.ByteString(Sequence[int])
A generic version of collections.abc.ByteString. This type represents the types bytes, bytearray, and memoryview of byte sequences. As a shorthand for this type, bytes can be used to annotate arguments of any of the types mentioned above. Deprecated since version 3.9: collectio... | python.library.typing#typing.ByteString |
typing.Callable
Callable type; Callable[[int], str] is a function of (int) -> str. The subscription syntax must always be used with exactly two values: the argument list and the return type. The argument list must be a list of types or an ellipsis; the return type must be a single type. There is no syntax to indicate... | python.library.typing#typing.Callable |
typing.cast(typ, val)
Cast a value to a type. This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don’t check anything (we want this to be as fast as possible). | python.library.typing#typing.cast |
class typing.ChainMap(collections.ChainMap, MutableMapping[KT, VT])
A generic version of collections.ChainMap. New in version 3.5.4. New in version 3.6.1. Deprecated since version 3.9: collections.ChainMap now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.ChainMap |
typing.ClassVar
Special type construct to mark class variables. As introduced in PEP 526, a variable annotation wrapped in ClassVar indicates that a given attribute is intended to be used as a class variable and should not be set on instances of that class. Usage: class Starship:
stats: ClassVar[dict[str, int]] =... | python.library.typing#typing.ClassVar |
class typing.Collection(Sized, Iterable[T_co], Container[T_co])
A generic version of collections.abc.Collection New in version 3.6.0. Deprecated since version 3.9: collections.abc.Collection now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Collection |
class typing.Container(Generic[T_co])
A generic version of collections.abc.Container. Deprecated since version 3.9: collections.abc.Container now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Container |
class typing.ContextManager(Generic[T_co])
A generic version of contextlib.AbstractContextManager. New in version 3.5.4. New in version 3.6.0. Deprecated since version 3.9: contextlib.AbstractContextManager now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.ContextManager |
class typing.Coroutine(Awaitable[V_co], Generic[T_co, T_contra, V_co])
A generic version of collections.abc.Coroutine. The variance and order of type variables correspond to those of Generator, for example: from collections.abc import Coroutine
c = None # type: Coroutine[list[str], str, int]
...
x = c.send('hi') # ty... | python.library.typing#typing.Coroutine |
class typing.Counter(collections.Counter, Dict[T, int])
A generic version of collections.Counter. New in version 3.5.4. New in version 3.6.1. Deprecated since version 3.9: collections.Counter now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Counter |
class typing.DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
A generic version of collections.defaultdict. New in version 3.5.2. Deprecated since version 3.9: collections.defaultdict now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.DefaultDict |
class typing.Deque(deque, MutableSequence[T])
A generic version of collections.deque. New in version 3.5.4. New in version 3.6.1. Deprecated since version 3.9: collections.deque now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Deque |
class typing.Dict(dict, MutableMapping[KT, VT])
A generic version of dict. Useful for annotating return types. To annotate arguments it is preferred to use an abstract collection type such as Mapping. This type can be used as follows: def count_words(text: str) -> Dict[str, int]:
...
Deprecated since version 3.... | python.library.typing#typing.Dict |
typing.Final
A special typing construct to indicate to type checkers that a name cannot be re-assigned or overridden in a subclass. For example: MAX_SIZE: Final = 9000
MAX_SIZE += 1 # Error reported by type checker
class Connection:
TIMEOUT: Final[int] = 10
class FastConnector(Connection):
TIMEOUT = 1 # E... | python.library.typing#typing.Final |
@typing.final
A decorator to indicate to type checkers that the decorated method cannot be overridden, and the decorated class cannot be subclassed. For example: class Base:
@final
def done(self) -> None:
...
class Sub(Base):
def done(self) -> None: # Error reported by type checker
...
... | python.library.typing#typing.final |
class typing.ForwardRef
A class used for internal typing representation of string forward references. For example, List["SomeClass"] is implicitly transformed into List[ForwardRef("SomeClass")]. This class should not be instantiated by a user, but may be used by introspection tools. Note PEP 585 generic types such a... | python.library.typing#typing.ForwardRef |
class typing.FrozenSet(frozenset, AbstractSet[T_co])
A generic version of builtins.frozenset. Deprecated since version 3.9: builtins.frozenset now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.FrozenSet |
class typing.Generator(Iterator[T_co], Generic[T_co, T_contra, V_co])
A generator can be annotated by the generic type Generator[YieldType, SendType, ReturnType]. For example: def echo_round() -> Generator[int, float, str]:
sent = yield 0
while sent >= 0:
sent = yield round(sent)
return 'Done'
No... | python.library.typing#typing.Generator |
class typing.Generic
Abstract base class for generic types. A generic type is typically declared by inheriting from an instantiation of this class with one or more type variables. For example, a generic mapping type might be defined as: class Mapping(Generic[KT, VT]):
def __getitem__(self, key: KT) -> VT:
... | python.library.typing#typing.Generic |
typing.get_args(tp) | python.library.typing#typing.get_args |
typing.get_origin(tp)
Provide basic introspection for generic types and special typing forms. For a typing object of the form X[Y, Z, ...] these functions return X and (Y, Z, ...). If X is a generic alias for a builtin or collections class, it gets normalized to the original class. If X is a Union or Literal containe... | python.library.typing#typing.get_origin |
typing.get_type_hints(obj, globalns=None, localns=None, include_extras=False)
Return a dictionary containing type hints for a function, method, module or class object. This is often the same as obj.__annotations__. In addition, forward references encoded as string literals are handled by evaluating them in globals an... | python.library.typing#typing.get_type_hints |
class typing.Hashable
An alias to collections.abc.Hashable | python.library.typing#typing.Hashable |
class typing.IO
class typing.TextIO
class typing.BinaryIO
Generic type IO[AnyStr] and its subclasses TextIO(IO[str]) and BinaryIO(IO[bytes]) represent the types of I/O streams such as returned by open(). These types are also in the typing.io namespace. | python.library.typing#typing.IO |
class typing.ItemsView(MappingView, Generic[KT_co, VT_co])
A generic version of collections.abc.ItemsView. Deprecated since version 3.9: collections.abc.ItemsView now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.ItemsView |
class typing.Iterable(Generic[T_co])
A generic version of collections.abc.Iterable. Deprecated since version 3.9: collections.abc.Iterable now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Iterable |
class typing.Iterator(Iterable[T_co])
A generic version of collections.abc.Iterator. Deprecated since version 3.9: collections.abc.Iterator now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Iterator |
class typing.KeysView(MappingView[KT_co], AbstractSet[KT_co])
A generic version of collections.abc.KeysView. Deprecated since version 3.9: collections.abc.KeysView now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.KeysView |
class typing.List(list, MutableSequence[T])
Generic version of list. Useful for annotating return types. To annotate arguments it is preferred to use an abstract collection type such as Sequence or Iterable. This type may be used as follows: T = TypeVar('T', int, float)
def vec2(x: T, y: T) -> List[T]:
return [x... | python.library.typing#typing.List |
typing.Literal
A type that can be used to indicate to type checkers that the corresponding variable or function parameter has a value equivalent to the provided literal (or one of several literals). For example: def validate_simple(data: Any) -> Literal[True]: # always returns True
...
MODE = Literal['r', 'rb',... | python.library.typing#typing.Literal |
class typing.Mapping(Sized, Collection[KT], Generic[VT_co])
A generic version of collections.abc.Mapping. This type can be used as follows: def get_position_in_index(word_list: Mapping[str, int], word: str) -> int:
return word_list[word]
Deprecated since version 3.9: collections.abc.Mapping now supports []. See... | python.library.typing#typing.Mapping |
class typing.MappingView(Sized, Iterable[T_co])
A generic version of collections.abc.MappingView. Deprecated since version 3.9: collections.abc.MappingView now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.MappingView |
class typing.Pattern
class typing.Match
These type aliases correspond to the return types from re.compile() and re.match(). These types (and the corresponding functions) are generic in AnyStr and can be made specific by writing Pattern[str], Pattern[bytes], Match[str], or Match[bytes]. These types are also in the t... | python.library.typing#typing.Match |
class typing.MutableMapping(Mapping[KT, VT])
A generic version of collections.abc.MutableMapping. Deprecated since version 3.9: collections.abc.MutableMapping now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.MutableMapping |
class typing.MutableSequence(Sequence[T])
A generic version of collections.abc.MutableSequence. Deprecated since version 3.9: collections.abc.MutableSequence now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.MutableSequence |
class typing.MutableSet(AbstractSet[T])
A generic version of collections.abc.MutableSet. Deprecated since version 3.9: collections.abc.MutableSet now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.MutableSet |
class typing.NamedTuple
Typed version of collections.namedtuple(). Usage: class Employee(NamedTuple):
name: str
id: int
This is equivalent to: Employee = collections.namedtuple('Employee', ['name', 'id'])
To give a field a default value, you can assign to it in the class body: class Employee(NamedTuple):
... | python.library.typing#typing.NamedTuple |
typing.NewType(name, tp)
A helper function to indicate a distinct type to a typechecker, see NewType. At runtime it returns a function that returns its argument. Usage: UserId = NewType('UserId', int)
first_user = UserId(1)
New in version 3.5.2. | python.library.typing#typing.NewType |
typing.NoReturn
Special type indicating that a function never returns. For example: from typing import NoReturn
def stop() -> NoReturn:
raise RuntimeError('no way')
New in version 3.5.4. New in version 3.6.2. | python.library.typing#typing.NoReturn |
@typing.no_type_check
Decorator to indicate that annotations are not type hints. This works as class or function decorator. With a class, it applies recursively to all methods defined in that class (but not to methods defined in its superclasses or subclasses). This mutates the function(s) in place. | python.library.typing#typing.no_type_check |
@typing.no_type_check_decorator
Decorator to give another decorator the no_type_check() effect. This wraps the decorator with something that wraps the decorated function in no_type_check(). | python.library.typing#typing.no_type_check_decorator |
typing.Optional
Optional type. Optional[X] is equivalent to Union[X, None]. Note that this is not the same concept as an optional argument, which is one that has a default. An optional argument with a default does not require the Optional qualifier on its type annotation just because it is optional. For example: def ... | python.library.typing#typing.Optional |
class typing.OrderedDict(collections.OrderedDict, MutableMapping[KT, VT])
A generic version of collections.OrderedDict. New in version 3.7.2. Deprecated since version 3.9: collections.OrderedDict now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.OrderedDict |
@typing.overload
The @overload decorator allows describing functions and methods that support multiple different combinations of argument types. A series of @overload-decorated definitions must be followed by exactly one non-@overload-decorated definition (for the same function/method). The @overload-decorated defini... | python.library.typing#typing.overload |
class typing.Pattern
class typing.Match
These type aliases correspond to the return types from re.compile() and re.match(). These types (and the corresponding functions) are generic in AnyStr and can be made specific by writing Pattern[str], Pattern[bytes], Match[str], or Match[bytes]. These types are also in the t... | python.library.typing#typing.Pattern |
class typing.Protocol(Generic)
Base class for protocol classes. Protocol classes are defined like this: class Proto(Protocol):
def meth(self) -> int:
...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example: class C:
def meth(... | python.library.typing#typing.Protocol |
class typing.Reversible(Iterable[T_co])
A generic version of collections.abc.Reversible. Deprecated since version 3.9: collections.abc.Reversible now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Reversible |
@typing.runtime_checkable
Mark a protocol class as a runtime protocol. Such a protocol can be used with isinstance() and issubclass(). This raises TypeError when applied to a non-protocol class. This allows a simple-minded structural check, very similar to “one trick ponies” in collections.abc such as Iterable. For e... | python.library.typing#typing.runtime_checkable |
class typing.Sequence(Reversible[T_co], Collection[T_co])
A generic version of collections.abc.Sequence. Deprecated since version 3.9: collections.abc.Sequence now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Sequence |
class typing.Set(set, MutableSet[T])
A generic version of builtins.set. Useful for annotating return types. To annotate arguments it is preferred to use an abstract collection type such as AbstractSet. Deprecated since version 3.9: builtins.set now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.Set |
class typing.Sized
An alias to collections.abc.Sized | python.library.typing#typing.Sized |
class typing.SupportsAbs
An ABC with one abstract method __abs__ that is covariant in its return type. | python.library.typing#typing.SupportsAbs |
class typing.SupportsBytes
An ABC with one abstract method __bytes__. | python.library.typing#typing.SupportsBytes |
class typing.SupportsComplex
An ABC with one abstract method __complex__. | python.library.typing#typing.SupportsComplex |
class typing.SupportsFloat
An ABC with one abstract method __float__. | python.library.typing#typing.SupportsFloat |
class typing.SupportsIndex
An ABC with one abstract method __index__. New in version 3.8. | python.library.typing#typing.SupportsIndex |
class typing.SupportsInt
An ABC with one abstract method __int__. | python.library.typing#typing.SupportsInt |
class typing.SupportsRound
An ABC with one abstract method __round__ that is covariant in its return type. | python.library.typing#typing.SupportsRound |
class typing.Text
Text is an alias for str. It is provided to supply a forward compatible path for Python 2 code: in Python 2, Text is an alias for unicode. Use Text to indicate that a value must contain a unicode string in a manner that is compatible with both Python 2 and Python 3: def add_unicode_checkmark(text: T... | python.library.typing#typing.Text |
class typing.IO
class typing.TextIO
class typing.BinaryIO
Generic type IO[AnyStr] and its subclasses TextIO(IO[str]) and BinaryIO(IO[bytes]) represent the types of I/O streams such as returned by open(). These types are also in the typing.io namespace. | python.library.typing#typing.TextIO |
typing.Tuple
Tuple type; Tuple[X, Y] is the type of a tuple of two items with the first item of type X and the second of type Y. The type of the empty tuple can be written as Tuple[()]. Example: Tuple[T1, T2] is a tuple of two elements corresponding to type variables T1 and T2. Tuple[int, float, str] is a tuple of an... | python.library.typing#typing.Tuple |
class typing.Type(Generic[CT_co])
A variable annotated with C may accept a value of type C. In contrast, a variable annotated with Type[C] may accept values that are classes themselves – specifically, it will accept the class object of C. For example: a = 3 # Has type 'int'
b = int # Has type 'Type[int]... | python.library.typing#typing.Type |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.