PEP 655: Add Discussions-To link to the `typing-sig` thread (#2344)

This commit is contained in:
CAM Gerlach 2022-02-21 17:47:19 -06:00 committed by GitHub
parent d54740c33b
commit f8717b6055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -2,7 +2,7 @@ PEP: 655
Title: Marking individual TypedDict items as required or potentially-missing Title: Marking individual TypedDict items as required or potentially-missing
Author: David Foster <david at dafoster.net> Author: David Foster <david at dafoster.net>
Sponsor: Guido van Rossum <guido at python.org> Sponsor: Guido van Rossum <guido at python.org>
Discussions-To: typing-sig at python.org Discussions-To: https://mail.python.org/archives/list/typing-sig@python.org/thread/53XVOD5ZUKJ263MWA6AUPEA6J7LBBLNV/
Status: Draft Status: Draft
Type: Standards Track Type: Standards Track
Content-Type: text/x-rst Content-Type: text/x-rst
@ -315,7 +315,7 @@ Usage in Python <3.11
If your code supports Python <3.11 and wishes to use ``Required[]`` or If your code supports Python <3.11 and wishes to use ``Required[]`` or
``NotRequired[]`` then it should use ``typing_extensions.TypedDict`` rather ``NotRequired[]`` then it should use ``typing_extensions.TypedDict`` rather
than ``typing.TypedDict`` because the latter will not understand than ``typing.TypedDict`` because the latter will not understand
``(Not)Required[]``. In particular ``__required_keys__`` and ``(Not)Required[]``. In particular ``__required_keys__`` and
``__optional_keys__`` on the resulting TypedDict type will not be correct: ``__optional_keys__`` on the resulting TypedDict type will not be correct:
Yes (Python 3.11+ only): Yes (Python 3.11+ only):
@ -346,11 +346,11 @@ No (Python <3.11 and 3.11+):
from typing import TypedDict # oops: should import from typing_extensions instead from typing import TypedDict # oops: should import from typing_extensions instead
from typing_extensions import NotRequired from typing_extensions import NotRequired
class Movie(TypedDict): class Movie(TypedDict):
title: str title: str
year: NotRequired[int] year: NotRequired[int]
assert Movie.__required_keys__ == frozenset({'title', 'year'}) # yikes assert Movie.__required_keys__ == frozenset({'title', 'year'}) # yikes
assert Movie.__optional_keys__ == frozenset() # yikes assert Movie.__optional_keys__ == frozenset() # yikes
@ -464,7 +464,7 @@ as the type of a variable which is only conditionally defined:
class MyClass: class MyClass:
attr: int|Missing attr: int|Missing
def __init__(self, set_attr: bool) -> None: def __init__(self, set_attr: bool) -> None:
if set_attr: if set_attr:
self.attr = 10 self.attr = 10
@ -533,7 +533,7 @@ or a check against ``locals()`` for local variables:
packet_bytes: Union[str, Missing] packet_bytes: Union[str, Missing]
if packet_data is not None: if packet_data is not None:
packet_bytes = packet.data.encode('utf-8') packet_bytes = packet.data.encode('utf-8')
if 'packet_bytes' in locals(): if 'packet_bytes' in locals():
reveal_type(packet_bytes) # bytes reveal_type(packet_bytes) # bytes
socket.send(packet_bytes) socket.send(packet_bytes)