]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46480: rephrase typing.assert_type docs (GH-32069)
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>
Thu, 24 Mar 2022 02:15:06 +0000 (19:15 -0700)
committerGitHub <noreply@github.com>
Thu, 24 Mar 2022 02:15:06 +0000 (19:15 -0700)
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
Lib/typing.py

index 57979cbb08e69a87052ab4c94552cd72370eec10..4d833dc497f177e01895157064b1f1c9ca3413a4 100644 (file)
@@ -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::
index f0e84900d7f80abaa58b2624c422e6f704dded94..64b348e0b9d5ca47d8d3e3d486c4e1d2b62cfef7 100644 (file)
@@ -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::