[Python-checkins] bpo-43766: Fix TypeGuard docs (#25660)

gvanrossum webhook-mailer at python.org
Tue Apr 27 11:55:23 EDT 2021


https://github.com/python/cpython/commit/99fdd782007db86f20aeb302b2ceaf79ce1ae2ba
commit: 99fdd782007db86f20aeb302b2ceaf79ce1ae2ba
branch: master
author: Ken Jin <28750310+Fidget-Spinner at users.noreply.github.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2021-04-27T08:55:08-07:00
summary:

bpo-43766: Fix TypeGuard docs (#25660)

files:
M Doc/library/typing.rst
M Doc/tools/susp-ignored.csv

diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index cb9ba4599d7ea..8b1ce34d98ec6 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -974,10 +974,10 @@ These can be used as types in annotations using ``[]``, each having a unique syn
 
          def func1(val: List[object]):
              if is_str_list(val):
-                 # Type of ``val`` is narrowed to List[str]
+                 # Type of ``val`` is narrowed to ``List[str]``.
                  print(" ".join(val))
              else:
-                 # Type of ``val`` remains as List[object]
+                 # Type of ``val`` remains as ``List[object]``.
                  print("Not a list of strings!")
 
    If ``is_str_list`` is a class or instance method, then the type in
@@ -994,12 +994,7 @@ These can be used as types in annotations using ``[]``, each having a unique syn
       wider form. The main reason is to allow for things like
       narrowing ``List[object]`` to ``List[str]`` even though the latter
       is not a subtype of the former, since ``List`` is invariant.
-      The responsibility of
-      writing type-safe type guards is left to the user.  Even if
-      the type guard function passes type checks, it may still fail at runtime.
-      The type guard function may perform erroneous checks and return wrong
-      booleans.  Consequently, the type it promises in ``TypeGuard[TypeB]`` may
-      not hold.
+      The responsibility of writing type-safe type guards is left to the user.
 
    ``TypeGuard`` also works with type variables.  For more information, see
    :pep:`647` (User-Defined Type Guards).
diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv
index b9e10678d4648..5a2d85d262b2e 100644
--- a/Doc/tools/susp-ignored.csv
+++ b/Doc/tools/susp-ignored.csv
@@ -370,3 +370,7 @@ library/importlib.metadata,,:main,"EntryPoint(name='wheel', value='wheel.cli:mai
 library/importlib.metadata,,`,loading the metadata for packages for the indicated ``context``.
 library/re,,`,"`"
 using/configure,84,:db2,=db1:db2:...
+library/typing,1004,`,# Type of ``val`` is narrowed to ``str``
+library/typing,1004,`,"# Else, type of ``val`` is narrowed to ``float``."
+library/typing,1004,`,# Type of ``val`` is narrowed to ``List[str]``.
+library/typing,1004,`,# Type of ``val`` remains as ``List[object]``.



More information about the Python-checkins mailing list