@@ -3,7 +3,7 @@ Title: User-Defined Type Guards
3
3
Author: Eric Traut <erictr at microsoft.com>
4
4
Sponsor: Guido van Rossum <
[email protected] >
5
5
6
- Status: Accepted
6
+ Status: Final
7
7
Type: Standards Track
8
8
Topic: Typing
9
9
Created: 07-Oct-2020
@@ -94,7 +94,7 @@ are supported by type checkers.
94
94
Using this new mechanism, the ``is_str_list `` function in the above example
95
95
would be modified slightly. Its return type would be changed from ``bool ``
96
96
to ``TypeGuard[List[str]] ``. This promises not merely that the return value
97
- is boolean, but that a true indicates the input to the function was of the
97
+ is boolean, but that a true indicates the input to the function was of the
98
98
specified type.
99
99
100
100
::
@@ -200,9 +200,9 @@ allows for cases like the example above where ``List[str]`` is not assignable
200
200
to ``List[object] ``.
201
201
202
202
When a conditional statement includes a call to a user-defined type guard
203
- function, and that function returns true, the expression passed as the first
204
- positional argument to the type guard function should be assumed by a static
205
- type checker to take on the type specified in the TypeGuard return type,
203
+ function, and that function returns true, the expression passed as the first
204
+ positional argument to the type guard function should be assumed by a static
205
+ type checker to take on the type specified in the TypeGuard return type,
206
206
unless and until it is further narrowed within the conditional code block.
207
207
208
208
Some built-in type guards provide narrowing for both positive and negative
@@ -223,7 +223,7 @@ is not narrowed in the negative case.
223
223
else:
224
224
reveal_type(val) # OneOrTwoStrs
225
225
...
226
-
226
+
227
227
if not is_two_element_tuple(val):
228
228
reveal_type(val) # OneOrTwoStrs
229
229
...
0 commit comments