From 5bf8126a9455886226a670e35bb31d974c85acdd Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 9 Apr 2024 06:17:21 -0400 Subject: [PATCH] More PR feedback --- Doc/library/typing.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 534ae7882b197f..19dbd376c80d51 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1476,7 +1476,7 @@ These can be used as types in annotations. They all support subscription using Type predicate functions are user-defined functions that return whether their argument is an instance of a particular type. ``TypeGuard`` works similarly to :data:`TypeIs`, but has subtly different - effects on type checking behavior. + effects on type checking behavior (see below). Using ``-> TypeGuard`` tells the static type checker that for a given function: @@ -1485,6 +1485,8 @@ These can be used as types in annotations. They all support subscription using 2. If the return value is ``True``, the type of its argument is the type inside ``TypeGuard``. + ``TypeGuard`` also works with type variables. See :pep:`647` for more details. + For example:: def is_str_list(val: list[object]) -> TypeGuard[list[str]]: @@ -1513,8 +1515,6 @@ These can be used as types in annotations. They all support subscription using the variable at all. When a ``TypeIs`` function returns ``False``, type checkers can narrow the type of the variable to exclude the ``TypeIs`` type. - ``TypeGuard`` also works with type variables. See :pep:`647` for more details. - .. versionadded:: 3.10