GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-46066: Deprecate kwargs syntax for TypedDict definitions by 97littleleaf11 · Pull Request #31126 · python/cpython

Conversation

@97littleleaf11

@97littleleaf11 97littleleaf11 commented Feb 4, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Closes python/typing#981

https://bugs.python.org/issue46066

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@97littleleaf11
Remove kwargs syntax for TypedDict
0c12774
@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Feb 4, 2022
@the-knights-who-say-ni

This comment was marked as resolved.

Sign in to view
@bedevere-bot bedevere-bot added the awaiting review label Feb 4, 2022
@AlexWaygood

AlexWaygood commented Feb 4, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Surely this is a breaking change — even if type-checkers only understand the literal-dict assignment-based syntax, I'm not sure we can change the runtime behaviour like this without a deprecation period.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@97littleleaf11

97littleleaf11 commented Feb 4, 2022

Copy link
Copy Markdown
Contributor Author

Yeah, it changes the typing module. However I seldom see this syntax in real-world projects since we already have class based one.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@97littleleaf11

97littleleaf11 commented Feb 4, 2022

Copy link
Copy Markdown
Contributor Author

I am not really familiar with the cpython developing period. It's not a big deal since neither mypy nor other widely-used type checkers implement this feature and I barely see this syntax in real world projects.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Feb 4, 2022

Copy link
Copy Markdown
Member

Yeah, it changes the typing module. However I seldom see this syntax in real-world projects since we already have class based one.

I appreciate that — but given that this is a change to the stdlib, I think the standard deprecation policy probably still applies :)

97littleleaf11 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@97littleleaf11

97littleleaf11 commented Feb 4, 2022

Copy link
Copy Markdown
Contributor Author

I think the standard deprecation policy probably still applies :)

Thanks for pointing out!

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Feb 4, 2022

Copy link
Copy Markdown
Member

For now, I think I would:

  • Change the docs to state that this is deprecated in 3.11, will be removed in 3.13, and probably won't be understood by type checkers like mypy.
  • Change the runtime behaviour to emit a warning if a user tries to construct a TypedDict with the kwargs-based syntax.

Here's an example of a previous PR deprecating features, that you could look to as an example: #23064

JelleZijlstra and 97littleleaf11 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added CLA signed and removed CLA not signed labels Feb 5, 2022
@97littleleaf11
Add deprecation flag and warning
f3588ac
@97littleleaf11
97littleleaf11 marked this pull request as ready for review February 7, 2022 17:59
@97littleleaf11
97littleleaf11 requested review from Fidget-Spinner and gvanrossum as code owners February 7, 2022 17:59
@gvanrossum
gvanrossum requested a review from JelleZijlstra February 7, 2022 18:14
JelleZijlstra
JelleZijlstra reviewed Feb 7, 2022
View reviewed changes
Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood
AlexWaygood self-requested a review February 7, 2022 21:17
@97littleleaf11
Add blurb and address reviews
4d988a8
AlexWaygood
AlexWaygood reviewed Feb 8, 2022
View reviewed changes
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Library/2022-02-08-16-42-20.bpo-46066.m32Hl0.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

97littleleaf11 and others added 2 commits February 8, 2022 23:46
@97littleleaf11 @AlexWaygood
Change docs
f21c30a
Co-authored-by: AlexWaygood <[email protected]>
@97littleleaf11
Add name
3f60fb0
@97littleleaf11 97littleleaf11 changed the title bpo-46066: Remove kwargs syntax for TypedDict definition bpo-46066: Deprecate kwargs syntax for TypedDict definitions Feb 8, 2022
AlexWaygood
AlexWaygood reviewed Feb 8, 2022
View reviewed changes
Comment thread Misc/ACKS Outdated
Ka-Ping Yee
Chi Hsuan Yen
Jason Yeo
Jingchen Ye

@AlexWaygood AlexWaygood Feb 8, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It feels absurd to bring this up (sorry!!), but: I think "Jingchen Ye" should go before "Ka-Ping Yee", if we're keeping this list alphabetised.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AlexWaygood

AlexWaygood commented Feb 8, 2022

Copy link
Copy Markdown
Member

Also, it looks like there's some trailing whitespace in some of the documentation changes you've made, which is making the documentation-related tests fail -- could you possibly fix those issues?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@97littleleaf11
Fix
033cf07
@97littleleaf11

97littleleaf11 commented Feb 8, 2022

Copy link
Copy Markdown
Contributor Author

@AlexWaygood Thanks for your reviews! btw, it seems that CI reports wrong line number about the trailing whitespace.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Feb 8, 2022

Copy link
Copy Markdown
Member

@AlexWaygood Thanks for your reviews!

No worries, it's a good PR!

btw, it seems that CI reports wrong line number about the trailing whitespace.

Huh — no idea what might be causing that :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood
AlexWaygood approved these changes Feb 8, 2022
View reviewed changes

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@97littleleaf11
Modify docs
eea168f
@AlexWaygood

AlexWaygood commented Feb 9, 2022

Copy link
Copy Markdown
Member

As this is a deprecation of an existing feature, I think it probably warrants a mention in "What's New in Python 3.11". I think @JelleZijlstra is planning on doing a PR for that document mentioning a bunch of recent changes to typing, though, so perhaps he'll be kind enough to include a mention of this as well :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood
AlexWaygood requested a review from JelleZijlstra February 10, 2022 10:39
JelleZijlstra
JelleZijlstra approved these changes Feb 10, 2022
View reviewed changes
@AlexWaygood

AlexWaygood commented Feb 10, 2022

Copy link
Copy Markdown
Member

@gvanrossum, could we possibly get the full test suite run on this PR, please? :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum
gvanrossum reviewed Feb 10, 2022
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I can't stand "firstly" and "secondly" for some reason. :-(

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@97littleleaf11

97littleleaf11 commented Feb 12, 2022

Copy link
Copy Markdown
Contributor Author

I can't stand "firstly" and "secondly" for some reason. :-(

How about "The first one" and "The other one"?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arhadthedev

arhadthedev commented Feb 12, 2022

Copy link
Copy Markdown
Member

How about "The first one" and "The other one"?

Probably, a bullet list will be better. Like this:

[...] syntactic forms:

  • using a literal dict as the second argument:

    Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})
    
  • using keyword arguments:

    Point2D = TypedDict('Point2D', x=int, y=int, label=str)
    
97littleleaf11 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra
JelleZijlstra reviewed Feb 12, 2022
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Here's a concrete wording suggestion that avoids "Firstly" and "Secondly"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood and 97littleleaf11 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
Comment thread Doc/library/typing.rst Outdated
Comment on lines +1391 to +1393
support :pep:`526`, ``TypedDict`` supports two additional equivalent
syntactic forms::
syntactic forms. Firstly, using a literal :class:`dict` as the
second argument::

@JelleZijlstra JelleZijlstra Feb 12, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'd suggest just writing "a TypedDict may be created using a functional form". This parallels https://docs.python.org/3.10/library/enum.html#functional-api

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

97littleleaf11 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@97littleleaf11 97littleleaf11 Feb 13, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for this!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/typing.rst Outdated
Point2D = TypedDict('Point2D', x=int, y=int, label=str)
Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})

Secondly, using keyword arguments::

@JelleZijlstra JelleZijlstra Feb 12, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
Secondly, using keyword arguments::
Keyword arguments may also be used::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gvanrossum

gvanrossum commented Feb 12, 2022

Copy link
Copy Markdown
Member

I was just hoping to see “first“ and “second”. No “ly” needed, these are flat adverbs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

97littleleaf11 added 2 commits February 13, 2022 15:16
@97littleleaf11
Use bullet list
15a7930
@97littleleaf11
Fix
b9badea
AlexWaygood
AlexWaygood reviewed Feb 13, 2022
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2022-02-08-16-42-20.bpo-46066.m32Hl0.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@97littleleaf11
Fix
a6a870c
@97littleleaf11
97littleleaf11 requested review from AlexWaygood and gvanrossum February 14, 2022 16:24
@gvanrossum

gvanrossum commented Feb 14, 2022

Copy link
Copy Markdown
Member

In a few days Jelle can likely merge this himself. :-)

AlexWaygood reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood
AlexWaygood reviewed Feb 14, 2022
View reviewed changes
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@97littleleaf11
reverse
8b113dd
AlexWaygood
AlexWaygood approved these changes Feb 15, 2022
View reviewed changes
gvanrossum
gvanrossum approved these changes Feb 15, 2022
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Feb 15, 2022
@JelleZijlstra
JelleZijlstra merged commit de6043e into python:main Feb 17, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Feb 17, 2022
@gvanrossum

gvanrossum commented Feb 17, 2022

Copy link
Copy Markdown
Member

Congrats Jelle!

JelleZijlstra, AlexWaygood, and 97littleleaf11 reacted with hooray emoji
All reactions
  • 🎉 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Feb 17, 2022

Copy link
Copy Markdown
Member

And congrats @97littleleaf11 on your first CPython contribution!

97littleleaf11 reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra JelleZijlstra mentioned this pull request Apr 13, 2022
Add typing to 3.11 What's New #91491
Closed
@97littleleaf11 97littleleaf11 mannequin mentioned this pull request Dec 22, 2022
Deprecate keyword args syntax for TypedDict definition #90224
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@gvanrossum gvanrossum gvanrossum approved these changes
@AlexWaygood AlexWaygood AlexWaygood approved these changes
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

TypedDict alternative definition syntax with keyword args is confusing

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@97littleleaf11 @the-knights-who-say-ni @AlexWaygood @arhadthedev @gvanrossum @JelleZijlstra @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.