Skip to content

Commit 3354245

Browse files
authored
bpo-46480: rephrase typing.assert_type docs (GH-32069)
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".
1 parent 366c546 commit 3354245

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Doc/library/typing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ Functions and decorators
21502150

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

2153-
Assert (to the type checker) that *val* has an inferred type of *typ*.
2153+
Ask a static type checker to confirm that *val* has an inferred type of *typ*.
21542154

21552155
When the type checker encounters a call to ``assert_type()``, it
21562156
emits an error if the value is not of the specified type::

Lib/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ def cast(typ, val):
20852085

20862086

20872087
def assert_type(val, typ, /):
2088-
"""Assert (to the type checker) that the value is of the given type.
2088+
"""Ask a static type checker to confirm that the value is of the given type.
20892089
20902090
When the type checker encounters a call to assert_type(), it
20912091
emits an error if the value is not of the specified type::

0 commit comments

Comments
 (0)