On this page
  1. typing.assert_type
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

typing.assert_type

Prev: typing.assert_never | Up: typing | Next: typing.AsyncContextManager
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.assert_type
Tags: #public #python3 #stdlib #typing


Import

import typing
from typing import assert_type

Signature & Overview

typing.assert_type(val, typ, /)

Ask a static type checker to confirm that the value is of the given type.

Usage

from typing import assert_type

x: int = 42
assert assert_type(x, int) == 42

Gotchas

REPL Inspect

from typing import assert_type
help(assert_type)

Linked from

Related notes