Skip to content

Reference

Various type aliases.

AnyAsyncCallable = DynamicAsyncCallable[Any] module-attribute

Represents any async callables async (...) -> Any.

AnyAsyncContextManager = AsyncContextManager[Any] module-attribute

Represents any async context managers.

AnyCallable = DynamicCallable[Any] module-attribute

Represents any callables (...) -> Any.

AnyContextManager = ContextManager[Any] module-attribute

Represents any context managers.

AnyError = BaseException module-attribute

Represents any errors.

AnyErrorType = Type[AnyError] module-attribute

Represents any error types.

AnyErrorTypes = DynamicTuple[AnyErrorType] module-attribute

Represents tuples of any error types (AnyErrorType, ...).

AnyIterable = Union[AsyncIterable[T], Iterable[T]] module-attribute

Represents any iterable, async or not.

AnyIterator = Union[AsyncIterator[T], Iterator[T]] module-attribute

Represents any iterator, async or not.

AnySelectors = AnyIterable[bool] module-attribute

Represents any selectors, async or not.

AnySet = AbstractSet[T] module-attribute

Represents any sets.

AnyTuple = DynamicTuple[Any] module-attribute

Represents any tuples (Any, ...).

AnyType = Type[Any] module-attribute

Represents any types.

AsyncBinary = Binary[T, U, Awaitable[R]] module-attribute

Represents async binary functions async (T, U) -> R.

AsyncCallable = Callable[P, Awaitable[R]] module-attribute

Represents async callables async (P) -> R.

AsyncCompare = AsyncBinary[T, U, bool] module-attribute

Represents async comparison functions async (T, U) -> bool.

AsyncForEach = AsyncUnary[T, None] module-attribute

Represents async for-each functions async (T).

AsyncGenericPredicate = AsyncCallable[P, bool] module-attribute

Represents async generic predicates async (P) -> bool.

AsyncIdentity = AsyncUnary[T, T] module-attribute

Represents async identity functions async (T) -> T.

AsyncInspect = AsyncUnary[T, None] module-attribute

Represents async inspect functions async (T).

AsyncNullary = Nullary[Awaitable[R]] module-attribute

Represents async nullary functions async () -> R.

AsyncParse = AsyncUnary[str, T] module-attribute

Represents parsing functions async (str) -> T.

AsyncPredicate = AsyncUnary[T, bool] module-attribute

Represents async predicates async (T) -> bool.

AsyncQuaternary = Quaternary[T, U, V, W, Awaitable[R]] module-attribute

Represents async quaternary functions async (T, U, V, W) -> R.

AsyncSelectors = AsyncIterable[bool] module-attribute

Represents async selectors.

AsyncTernary = Ternary[T, U, V, Awaitable[R]] module-attribute

Represents async ternary functions async (T, U, V) -> R.

AsyncUnary = Unary[T, Awaitable[R]] module-attribute

Represents async unary functions async (T) -> R.

AsyncValidate = AsyncUnary[T, None] module-attribute

Represents async validation functions async (T).

Attributes = StringDict[Any] module-attribute

Represents attributes.

Binary = Callable[[T, U], R] module-attribute

Represents binary functions (T, U) -> R.

Compare = Binary[T, U, bool] module-attribute

Represents comparison functions (T, U) -> bool.

Decorator = Unary[F, G] module-attribute

Represents decorators (F) -> G.

DecoratorIdentity = Identity[F] module-attribute

Represents identity decorators (F) -> F.

DynamicAsyncCallable = Callable[..., Awaitable[R]] module-attribute

Represents dynamic async callables async (...) -> R.

DynamicCallable = Callable[..., R] module-attribute

Represents dynamic callables (...) -> R.

DynamicTuple = Tuple[T, ...] module-attribute

Represents homogeneous tuples of any length (T, ...).

EmptyTuple = Tuple[] module-attribute

Represents empty tuples ().

ForEach = Unary[T, None] module-attribute

Represents for-each functions (T).

GenericPredicate = Callable[P, bool] module-attribute

Represents generic predicates (P) -> bool.

Headers = StringMapping[Any] module-attribute

Represents headers.

Identity = Unary[T, T] module-attribute

Represents identity functions (T) -> T.

Inspect = Unary[T, None] module-attribute

Represents inspect functions (T).

IntoAttributes = IntoStringDict[Any] module-attribute

Represents types that can be converted into attributes.

IntoDict = Union[Mapping[Q, T], Pairs[Q, T]] module-attribute

Represents types that can be converted into dictionaries.

IntoHeaders = IntoStringMapping[Any] module-attribute

Represents types that can be converted into headers.

IntoMapping = Union[Mapping[T, U], Pairs[T, U]] module-attribute

Represents types that can be converted into mappings.

IntoNamespace = IntoStringDict[Any] module-attribute

Represents types that can be converted into namespaces.

IntoParameters = IntoStringMapping[Any] module-attribute

Represents types that can be converted into parameters.

IntoPath = Union[str, PathLike[str]] module-attribute

Represents types that can be converted into Path.

IntoStringDict = IntoDict[str, T] module-attribute

Represents types that can be converted into string dictionaries.

IntoStringMapping = IntoMapping[str, T] module-attribute

Represents types that can be converted into string mappings.

Namespace = StringDict[Any] module-attribute

Represents namespaces.

NormalError = Exception module-attribute

Represents normal errors.

NormalErrorType = Type[NormalError] module-attribute

Represents normal error types.

NormalErrorTypes = DynamicTuple[NormalErrorType] module-attribute

Represents tuples of normal error types (NormalErrorType, ...).

Nullary = Callable[[], R] module-attribute

Represents nullary functions () -> R.

Pair = Tuple[T, T] module-attribute

Represents homogeneous pairs (T, T).

Pairs = Iterable[Tuple[T, U]] module-attribute

Represents iterables of pairs (T, U).

Parameters = StringMapping[Any] module-attribute

Represents parameters.

Parse = Unary[str, T] module-attribute

Represents parsing functions (str) -> T.

Payload = Union[Primitive, List['Payload'], StringDict['Payload']] module-attribute

Represents payloads.

Predicate = Unary[T, bool] module-attribute

Represents predicates (T) -> bool.

Primitive = Optional[Union[bool, int, float, str]] module-attribute

Represents primitive types.

Quaternary = Callable[[T, U, V, W], R] module-attribute

Represents quaternary functions (T, U, V, W) -> R.

RecursiveAnyIterable = Union[T, AnyIterable['RecursiveAnyIterable[T]']] module-attribute

Represents recursive iterables, async or not.

RecursiveAsyncIterable = Union[T, AsyncIterable['RecursiveAsyncIterable[T]']] module-attribute

Represents recursive async iterables.

RecursiveIterable = Union[T, Iterable['RecursiveIterable[T]']] module-attribute

Represents recursive iterables.

Selectors = Iterable[bool] module-attribute

Represents selectors.

SimpleAsyncContextManager = AsyncContextManager[None] module-attribute

Represents simple async context managers that do not return anything on entering.

SimpleContextManager = ContextManager[None] module-attribute

Represents simple context managers that do not return anything on entering.

StrictPayload = Union[StrictPrimitive, List['StrictPayload'], StringDict['StrictPayload']] module-attribute

Represents strict payloads (which exclude None).

StrictPrimitive = Union[bool, int, float, str] module-attribute

Represents strict pritimive types (which exclude None).

StringDict = Dict[str, T] module-attribute

Represents string dictionaries.

StringMapping = Mapping[str, T] module-attribute

Represents string mappings.

Ternary = Callable[[T, U, V], R] module-attribute

Represents ternary functions (T, U, V) -> R.

Tuple1 = Tuple[T] module-attribute

Represents homogeneous 1-tuples (T).

Tuple2 = Tuple[T, T] module-attribute

Represents homogeneous 2-tuples (T, T).

Tuple3 = Tuple[T, T, T] module-attribute

Represents homogeneous 3-tuples (T, T, T).

Tuple4 = Tuple[T, T, T, T] module-attribute

Represents homogeneous 4-tuples (T, T, T, T).

Tuple5 = Tuple[T, T, T, T, T] module-attribute

Represents homogeneous 5-tuples (T, T, T, T, T).

Tuple6 = Tuple[T, T, T, T, T, T] module-attribute

Represents homogeneous 6-tuples (T, T, T, T, T, T).

Tuple7 = Tuple[T, T, T, T, T, T, T] module-attribute

Represents homogeneous 7-tuples (T, T, T, T, T, T, T).

Tuple8 = Tuple[T, T, T, T, T, T, T, T] module-attribute

Represents homogeneous 8-tuples (T, T, T, T, T, T, T, T).

TypeDecorator = Unary[C, D] module-attribute

Represents type decorators (C) -> D.

TypeDecoratorIdentity = Identity[C] module-attribute

Represents identity type decorators (C) -> C.

Unary = Callable[[T], R] module-attribute

Represents unary functions (T) -> R.

UnpackBinary = Unary[Tuple[T, U], R] module-attribute

Represents unpacking binary functions ((T, U)) -> R.

UnpackNullary = Unary[EmptyTuple, R] module-attribute

Represents unpacking nullary functions (()) -> R.

UnpackQuaternary = Unary[Tuple[T, U, V, W], R] module-attribute

Represents unpacking quaternary functions ((T, U, V, W)) -> R.

UnpackTernary = Unary[Tuple[T, U, V], R] module-attribute

Represents unpacking ternary functions ((T, U, V)) -> R.

UnpackUnary = Unary[Tuple[T], R] module-attribute

Represents unpacking unary functions ((T)) -> R.

Validate = Unary[T, None] module-attribute

Represents validation functions (T).

is_async_iterable(iterable: AnyIterable[T]) -> TypeIs[AsyncIterable[T]]

Checks if an AnyIterable[T] is an AsyncIterable[T].

Parameters:

Name Type Description Default
iterable AnyIterable[T]

The iterable to check.

required

Returns:

Type Description
TypeIs[AsyncIterable[T]]

Whether the iterable is an AsyncIterable[T].

Source code in typing_aliases/typing.py
463
464
465
466
467
468
469
470
471
472
473
def is_async_iterable(iterable: AnyIterable[T]) -> TypeIs[AsyncIterable[T]]:
    """Checks if an [`AnyIterable[T]`][typing_aliases.typing.AnyIterable] is an
    [`AsyncIterable[T]`][typing.AsyncIterable].

    Arguments:
        iterable: The iterable to check.

    Returns:
        Whether the iterable is an [`AsyncIterable[T]`][typing.AsyncIterable].
    """
    return is_instance(iterable, AsyncIterable)

is_async_iterator(iterator: AnyIterator[T]) -> TypeIs[AsyncIterator[T]]

Checks if an AnyIterator[T] is an AsyncIterator[T].

Parameters:

Name Type Description Default
iterator AnyIterator[T]

The iterator to check.

required

Returns:

Type Description
TypeIs[AsyncIterator[T]]

Whether the iterator is an AsyncIterator[T].

Source code in typing_aliases/typing.py
489
490
491
492
493
494
495
496
497
498
499
def is_async_iterator(iterator: AnyIterator[T]) -> TypeIs[AsyncIterator[T]]:
    """Checks if an [`AnyIterator[T]`][typing_aliases.typing.AnyIterator] is an
    [`AsyncIterator[T]`][typing.AsyncIterator].

    Arguments:
        iterator: The iterator to check.

    Returns:
        Whether the iterator is an [`AsyncIterator[T]`][typing.AsyncIterator].
    """
    return is_instance(iterator, AsyncIterator)

is_bool(item: Any) -> TypeIs[bool]

Checks if the given item is of type bool.

This is equivalent to:

is_true(item) or is_false(item)

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[bool]

Whether the given item is of type bool.

Source code in typing_aliases/typing.py
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
def is_bool(item: Any) -> TypeIs[bool]:
    """Checks if the given item is of type [`bool`][bool].

    This is equivalent to:

    ```python
    is_true(item) or is_false(item)
    ```

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is of type [`bool`][bool].
    """
    return is_true(item) or is_false(item)

is_bytes(item: Any) -> TypeIs[bytes]

Checks if the given item is of type bytes.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[bytes]

Whether the given item is of type bytes.

Source code in typing_aliases/typing.py
557
558
559
560
561
562
563
564
565
566
def is_bytes(item: Any) -> TypeIs[bytes]:
    """Checks if the given item is of type [`bytes`][bytes].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is of type [`bytes`][bytes].
    """
    return is_instance(item, bytes)

is_false(item: Any) -> TypeIs[Literal[False]]

Checks if the given item is False.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[Literal[False]]

Whether the given item is False.

Source code in typing_aliases/typing.py
617
618
619
620
621
622
623
624
625
626
def is_false(item: Any) -> TypeIs[Literal[False]]:
    """Checks if the given `item` is [`False`][False].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is [`False`][False].
    """
    return item is False

is_float(item: Any) -> TypeIs[float]

Checks if the given item is of type float.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[float]

Whether the given item is of type float.

Source code in typing_aliases/typing.py
545
546
547
548
549
550
551
552
553
554
def is_float(item: Any) -> TypeIs[float]:
    """Checks if the given item is of type [`float`][float].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is of type [`float`][float].
    """
    return is_instance(item, float)

is_hashable(item: Any) -> TypeIs[Hashable]

Checks if the given item is hashable.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[Hashable]

Whether the given item is hashable.

Source code in typing_aliases/typing.py
662
663
664
665
666
667
668
669
670
671
def is_hashable(item: Any) -> TypeIs[Hashable]:
    """Checks if the given item is hashable.

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is hashable.
    """
    return is_instance(item, Hashable)

is_int(item: Any) -> TypeIs[int]

Checks if the given item is of type int.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[int]

Whether the given item is of type int.

Source code in typing_aliases/typing.py
533
534
535
536
537
538
539
540
541
542
def is_int(item: Any) -> TypeIs[int]:
    """Checks if the given item is of type [`int`][int].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is of type [`int`][int].
    """
    return is_instance(item, int)

is_iterable(iterable: AnyIterable[T]) -> TypeIs[Iterable[T]]

Checks if an AnyIterable[T] is an Iterable[T].

Parameters:

Name Type Description Default
iterable AnyIterable[T]

The iterable to check.

required

Returns:

Type Description
TypeIs[Iterable[T]]

Whether the iterable is an Iterable[T].

Source code in typing_aliases/typing.py
476
477
478
479
480
481
482
483
484
485
486
def is_iterable(iterable: AnyIterable[T]) -> TypeIs[Iterable[T]]:
    """Checks if an [`AnyIterable[T]`][typing_aliases.typing.AnyIterable] is an
    [`Iterable[T]`][typing.Iterable].

    Arguments:
        iterable: The iterable to check.

    Returns:
        Whether the iterable is an [`Iterable[T]`][typing.Iterable].
    """
    return is_instance(iterable, Iterable)

is_iterator(iterator: AnyIterator[T]) -> TypeIs[Iterator[T]]

Checks if an AnyIterator[T] is an Iterator[T].

Parameters:

Name Type Description Default
iterator AnyIterator[T]

The iterator to check.

required

Returns:

Type Description
TypeIs[Iterator[T]]

Whether the iterator is an Iterator[T].

Source code in typing_aliases/typing.py
502
503
504
505
506
507
508
509
510
511
512
def is_iterator(iterator: AnyIterator[T]) -> TypeIs[Iterator[T]]:
    """Checks if an [`AnyIterator[T]`][typing_aliases.typing.AnyIterator] is an
    [`Iterator[T]`][typing.Iterator].

    Arguments:
        iterator: The iterator to check.

    Returns:
        Whether the iterator is an [`Iterator[T]`][typing.Iterator].
    """
    return is_instance(iterator, Iterator)

is_none(item: Optional[T]) -> TypeIs[None]

Checks if the given item is None.

Parameters:

Name Type Description Default
item Optional[T]

The item to check.

required

Returns:

Type Description
TypeIs[None]

Whether the given item is None.

Source code in typing_aliases/typing.py
518
519
520
521
522
523
524
525
526
527
def is_none(item: Optional[T]) -> TypeIs[None]:
    """Checks if the given `item` is [`None`][None].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is [`None`][None].
    """
    return item is None

is_range(item: Any) -> TypeIs[range]

Checks if the given item is of type range.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[range]

Whether the given item is of type range.

Source code in typing_aliases/typing.py
593
594
595
596
597
598
599
600
601
602
def is_range(item: Any) -> TypeIs[range]:
    """Checks if the given item is of type [`range`][range].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is of type [`range`][range].
    """
    return is_instance(item, range)

is_same_or_sub_type(item: Any, other: T) -> TypeIs[T]

Checks if the item is of the sub- or same type T as the other item.

Parameters:

Name Type Description Default
item Any

The item to check.

required
other T

The other item to check against.

required

Returns:

Type Description
TypeIs[T]

Whether the item is of the sub- or same type T as the other item.

Source code in typing_aliases/typing.py
690
691
692
693
694
695
696
697
698
699
700
def is_same_or_sub_type(item: Any, other: T) -> TypeIs[T]:
    """Checks if the item is of the sub- or same type `T` as the other item.

    Arguments:
        item: The item to check.
        other: The other item to check against.

    Returns:
        Whether the item is of the sub- or same type `T` as the other item.
    """
    return is_instance(item, type(other))

is_same_type(item: Any, other: T) -> TypeIs[T]

Checks if the item is of the same type T as the other item.

Parameters:

Name Type Description Default
item Any

The item to check.

required
other T

The other item to check against.

required

Returns:

Type Description
TypeIs[T]

Whether the item is of the same type T as the other item.

Source code in typing_aliases/typing.py
677
678
679
680
681
682
683
684
685
686
687
def is_same_type(item: Any, other: T) -> TypeIs[T]:
    """Checks if the item is of the same type `T` as the other item.

    Arguments:
        item: The item to check.
        other: The other item to check against.

    Returns:
        Whether the item is of the same type `T` as the other item.
    """
    return type(item) is type(other)

is_sized(item: Any) -> TypeIs[Sized]

Checks if the given item is sized.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[Sized]

Whether the given item is sized.

Source code in typing_aliases/typing.py
650
651
652
653
654
655
656
657
658
659
def is_sized(item: Any) -> TypeIs[Sized]:
    """Checks if the given item is sized.

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is sized.
    """
    return is_instance(item, Sized)

is_slice(item: Any) -> TypeIs[slice]

Checks if the given item is of type slice.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[slice]

Whether the given item is of type slice.

Source code in typing_aliases/typing.py
581
582
583
584
585
586
587
588
589
590
def is_slice(item: Any) -> TypeIs[slice]:
    """Checks if the given item is of type [`slice`][slice].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is of type [`slice`][slice].
    """
    return is_instance(item, slice)

is_string(item: Any) -> TypeIs[str]

Checks if the given item is of type str.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[str]

Whether the given item is of type str.

Source code in typing_aliases/typing.py
569
570
571
572
573
574
575
576
577
578
def is_string(item: Any) -> TypeIs[str]:
    """Checks if the given item is of type [`str`][str].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is of type [`str`][str].
    """
    return is_instance(item, str)

is_true(item: Any) -> TypeIs[Literal[True]]

Checks if the given item is True.

Parameters:

Name Type Description Default
item Any

The item to check.

required

Returns:

Type Description
TypeIs[Literal[True]]

Whether the given item is True.

Source code in typing_aliases/typing.py
605
606
607
608
609
610
611
612
613
614
def is_true(item: Any) -> TypeIs[Literal[True]]:
    """Checks if the given `item` is [`True`][True].

    Arguments:
        item: The item to check.

    Returns:
        Whether the given item is [`True`][True].
    """
    return item is True