summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Doc/library/typing.rst7
-rw-r--r--Lib/typing.py7
2 files changed, 8 insertions, 6 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 409a95d528..c22fc0b28a 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -2484,15 +2484,16 @@ Functions and decorators
Ask a static type checker to confirm that *val* has an inferred type of *typ*.
- When the type checker encounters a call to ``assert_type()``, it
+ 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, inferred type of `name` is `str`
assert_type(name, int) # type checker error
- 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::
diff --git a/Lib/typing.py b/Lib/typing.py
index 1a1c989dba..0dacdd9031 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -2319,15 +2319,16 @@ def cast(typ, val):
def assert_type(val, typ, /):
"""Ask a static type checker to confirm that the value is of the given type.
- When the type checker encounters a call to assert_type(), it
+ 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
- At runtime this returns the first argument unchanged and otherwise
- does nothing.
"""
return val