nanoutils.typing_utils

Types related to the builtin typing module.

Contains aliases for python >= 3.8 exclusive objects related to typing.

See also

https://badge.fury.io/py/typing-extensions.svg

The typing module: Support for gradual typing as defined by PEP 484.

At large scale, the structure of the module is following:

  • Imports and exports, all public names should be explicitly added to __all__.

  • Internal helper functions: these should never be used in code outside this module.

  • _SpecialForm and its instances (special forms): Any, NoReturn, ClassVar, Union and Optional.

  • Two classes whose instances can be type arguments in addition to types: ForwardRef and TypeVar.

  • The core of internal generics API: _GenericAlias and _VariadicGenericAlias, the latter is currently only used by Tuple and Callable. All subscripted types like X[int], Union[int, str], etc., are instances of either of these classes.

  • The public counterpart of the generics API consists of two classes: Generic and Protocol.

  • Public helper functions: get_type_hints(), overload(), cast(), no_type_check(), no_type_check_decorator().

  • Generic aliases for collections.abc ABCs and few additional protocols.

  • Special types: NewType(), NamedTuple and TypedDict.

  • Wrapper submodules for re and io related types.

Index

Literal

Special typing form to define literal types (a.k.a. value types).

Final

Special typing construct to indicate final names to type checkers.

final()

A decorator to indicate final methods and final classes.

Protocol

Base class for protocol classes.

SupportsIndex

An ABC with one abstract method __index__().

TypedDict

A simple typed name space. At runtime it is equivalent to a plain dict.

runtime_checkable()

Mark a protocol class as a runtime protocol, so that it an be used with isinstance() and issubclass().

PathType

An annotation for path-like objects.

ArrayLike

Objects that can be converted to arrays (see numpy.ndarray).

DTypeLike

Objects that can be converted to dtypes (see numpy.dtype).

ShapeLike

Objects that can serve as valid array shapes.

API

nanoutils.PathType = typing.Union[str, bytes, os.PathLike]

An annotation for path-like objects.