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 655: Add Discussions-To link to the actual thread #2344

Merged
merged 1 commit into from
Feb 21, 2022
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 pep-0655.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PEP: 655
Title: Marking individual TypedDict items as required or potentially-missing
Author: David Foster <david at dafoster.net>
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
Type: Standards Track
Content-Type: text/x-rst
Expand Down Expand Up @@ -315,7 +315,7 @@ Usage in Python <3.11
If your code supports Python <3.11 and wishes to use ``Required[]`` or
``NotRequired[]`` then it should use ``typing_extensions.TypedDict`` rather
than ``typing.TypedDict`` because the latter will not understand
``(Not)Required[]``. In particular ``__required_keys__`` and
``(Not)Required[]``. In particular ``__required_keys__`` and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why these extra formatting changes are here. Perhaps your editor is autoformatting whitespace?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Ditto for additional formatting changes below in the diff.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my editor automatically cleans up stray trailing whitespace on save, which it looks like this PEP had. I didn't see anything else in flight touching on this PEP and expected a fairly quick merge, so when I noticed it I didn't immediately go back and rewrite the commit without the whitespace changes. But if you are currently working on additional changes that this might cause a merge conflict with, I can go ahead and do that—just let me know.

``__optional_keys__`` on the resulting TypedDict type will not be correct:

Yes (Python 3.11+ only):
Expand Down Expand Up @@ -346,11 +346,11 @@ No (Python <3.11 and 3.11+):

from typing import TypedDict # oops: should import from typing_extensions instead
from typing_extensions import NotRequired

class Movie(TypedDict):
title: str
year: NotRequired[int]

assert Movie.__required_keys__ == frozenset({'title', 'year'}) # yikes
assert Movie.__optional_keys__ == frozenset() # yikes

Expand Down Expand Up @@ -464,7 +464,7 @@ as the type of a variable which is only conditionally defined:

class MyClass:
attr: int|Missing

def __init__(self, set_attr: bool) -> None:
if set_attr:
self.attr = 10
Expand Down Expand Up @@ -533,7 +533,7 @@ or a check against ``locals()`` for local variables:
packet_bytes: Union[str, Missing]
if packet_data is not None:
packet_bytes = packet.data.encode('utf-8')

if 'packet_bytes' in locals():
reveal_type(packet_bytes) # bytes
socket.send(packet_bytes)
Expand Down