Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 647: Mark as Final (take 2) #3737

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions peps/pep-0647.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: User-Defined Type Guards
Author: Eric Traut <erictr at microsoft.com>
Sponsor: Guido van Rossum <[email protected]>
Discussions-To: [email protected]
Status: Accepted
Status: Final
Type: Standards Track
Topic: Typing
Created: 07-Oct-2020
Expand Down Expand Up @@ -94,7 +94,7 @@ are supported by type checkers.
Using this new mechanism, the ``is_str_list`` function in the above example
would be modified slightly. Its return type would be changed from ``bool``
to ``TypeGuard[List[str]]``. This promises not merely that the return value
is boolean, but that a true indicates the input to the function was of the
is boolean, but that a true indicates the input to the function was of the
specified type.

::
Expand Down Expand Up @@ -200,9 +200,9 @@ allows for cases like the example above where ``List[str]`` is not assignable
to ``List[object]``.

When a conditional statement includes a call to a user-defined type guard
function, and that function returns true, the expression passed as the first
positional argument to the type guard function should be assumed by a static
type checker to take on the type specified in the TypeGuard return type,
function, and that function returns true, the expression passed as the first
positional argument to the type guard function should be assumed by a static
type checker to take on the type specified in the TypeGuard return type,
unless and until it is further narrowed within the conditional code block.

Some built-in type guards provide narrowing for both positive and negative
Expand All @@ -223,7 +223,7 @@ is not narrowed in the negative case.
else:
reveal_type(val) # OneOrTwoStrs
...

if not is_two_element_tuple(val):
reveal_type(val) # OneOrTwoStrs
...
Expand Down
Loading