Skip to content
Merged
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
JelleZijlstra and AlexWaygood authored Mar 12, 2022
commit 49765d3e478886dc687af3abb025150f9f39e254
7 changes: 3 additions & 4 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2116,17 +2116,16 @@ Functions and decorators

.. function:: assert_type(val, typ, /)

Assert (to the type checker) that the value is of the given type.
Assert (to the type checker) that *value* has an inferred type of *type*.

When the 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, str) # OK, inferred type of `name` is `str`
assert_type(name, int) # type checker error

At runtime this returns the first argument unchanged and otherwise
does nothing.
At runtime this returns the first argument unchanged with no side effects.

This function is useful for ensuring the type checker's understanding of a
script is in line with the developer's intentions::
Expand Down