PyDocs

Nav

Development Tools

assert_type

typing

function · Added in 3.11 (source)
  • assert_type(val, typ, /)
Ask a static type checker to confirm that the value is of the given 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::

    def greet(name: str) -> None:
        assert_type(name, str)  # OK
        assert_type(name, int)  # type checker error
0 Examples
No examples for typing/assert_type.
See Also
No see-alsos for typing/assert_type
0 Notes
No notes for assert_type