From 4936b0dda5a5c64b39d51a938d37b2c304ea30a3 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Tue, 22 Mar 2022 23:15:50 -0700 Subject: [PATCH] bpo-46480: rephrase typing.assert_type docs The goal here is to reduce potential confusion between `assert_type(val, type)` and `assert isinstance(val, typ)`. The former is meant to ask a type checker to confirm a fact, the latter is meant to tell a type checker a fact. The behaviour of the latter more closely resembles what I'd expect from the prior phrasing of "assert [something] to the type checker". --- Doc/library/typing.rst | 2 +- Lib/typing.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 57979cbb08e69a..4d833dc497f177 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2150,7 +2150,7 @@ Functions and decorators .. function:: assert_type(val, typ, /) - Assert (to the type checker) that *val* has an inferred type of *typ*. + 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 emits an error if the value is not of the specified type:: diff --git a/Lib/typing.py b/Lib/typing.py index f0e84900d7f80a..64b348e0b9d5ca 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -2085,7 +2085,7 @@ def cast(typ, val): def assert_type(val, typ, /): - """Assert (to the type checker) that the value is of the given type. + """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 emits an error if the value is not of the specified type::