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 728: Revise proposal to spec the 'extra_items=T' idea #4066

Merged
merged 6 commits into from
Oct 19, 2024

Conversation

PIG208
Copy link
Contributor

@PIG208 PIG208 commented Oct 17, 2024

  • Change is either:
    • To a Draft PEP
    • To an Accepted or Final PEP, with Steering Council approval
    • To fix an editorial issue (markup, typo, link, header, etc)
  • PR title prefixed with PEP number (e.g. PEP 123: Summary of changes)

Change summary

  • Move away from __extra_items__: T to extra_items=T
  • Repurpose the 'closed' class parameter to make 'closed=True' an alias of 'extra_items=Never'
  • Include references to the typing spec
  • Normalize terms like "assignability" and "consistent" to match the typing glossary (https://typing.readthedocs.io/en/latest/spec/glossary.html)
  • Update sections that contain documentation quotes to match the up-to-date version
  • Add new sections about other ideas
  • Bump the target version to 3.14

📚 Documentation preview 📚: https://pep-previews--4066.org.readthedocs.build/

@PIG208 PIG208 changed the title Revise proposal to spec the 'extra_items=T' idea PEP 728: Revise proposal to spec the 'extra_items=T' idea Oct 17, 2024
@PIG208 PIG208 force-pushed the pep-0728 branch 2 times, most recently from 2482267 to f5a5e90 Compare October 17, 2024 23:40
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thank you!

peps/pep-0728.rst Outdated Show resolved Hide resolved
peps/pep-0728.rst Outdated Show resolved Hide resolved
peps/pep-0728.rst Outdated Show resolved Hide resolved
peps/pep-0728.rst Outdated Show resolved Hide resolved
peps/pep-0728.rst Show resolved Hide resolved
peps/pep-0728.rst Outdated Show resolved Hide resolved
peps/pep-0728.rst Outdated Show resolved Hide resolved
peps/pep-0728.rst Outdated Show resolved Hide resolved
<https://discuss.python.org/t/pep-728-typeddict-with-typed-extra-items/45443/115>`__.

This will allow us to deprecate the functional syntax of defining TypedDict
types altogether, but adapting to this proposal will make this PEP heavier.
Copy link
Member

Choose a reason for hiding this comment

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

I feel this isn't a strong argument; if this PEP is accepted, we'll be stuck with its behavior for at least many years, so we need to make sure we get it right the first time.

This proposal is nice because it also unlocks some other things that are currently awkward or impossible (keys that aren't valid identifiers), it has a few disadvantages:

  • It's less apparent to a reader that _: bool makes the TypedDict special, relative to adding a class argument like extra_items=bool.
  • It's backwards incompatible with existing TypedDicts using the _: bool key. While such users have a way to get around the issue, it's still a problem for them if they upgrade Python (or typing-extensions).
  • The types don't appear in an annotation context, so their evaluation will not be deferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the bullet points to this section in commit d146b98. Thanks!

PIG208 added a commit to PIG208/peps that referenced this pull request Oct 18, 2024
- Move away from '__extra_items__: T' to 'extra_items=T'

- Repurpose the 'closed' class parameter to make 'closed=True'
  an alias of 'extra_items=Never'

- Include references to the typing spec

- Normalize terms like "assignability" and "consistent" to match the
  typing glossary (https://typing.readthedocs.io/en/latest/spec/glossary.html)

- Update sections that contain documentation quotes to match the
  up-to-date version

- Add new sections about other ideas

- Bump the target version to 3.14
Some of the linked sections do not expose the label, otherwise we should
be able to use intersphinx references.

Signed-off-by: Zixuan James Li <[email protected]>
peps/pep-0728.rst Outdated Show resolved Hide resolved
@JelleZijlstra JelleZijlstra merged commit 5e67f84 into python:main Oct 19, 2024
6 checks passed
@PIG208 PIG208 deleted the pep-0728 branch October 19, 2024 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants