Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-46066: Deprecate kwargs syntax for TypedDict definitions#31126

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JelleZijlstra merged 11 commits intopython:mainfrom97littleleaf11:bpo-46066
Feb 17, 2022

Conversation

97littleleaf11
Copy link
Contributor

@97littleleaf1197littleleaf11 commentedFeb 4, 2022
edited
Loading

@the-knights-who-say-ni

This comment was marked as resolved.

@AlexWaygood
Copy link
Member

AlexWaygood commentedFeb 4, 2022
edited
Loading

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.

@97littleleaf11
Copy link
ContributorAuthor

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

@97littleleaf11
Copy link
ContributorAuthor

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.

@AlexWaygood
Copy link
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 thestandard deprecation policy probably still applies :)

97littleleaf11 reacted with thumbs up emoji

@97littleleaf11
Copy link
ContributorAuthor

I think thestandard deprecation policy probably still applies :)

Thanks for pointing out!

AlexWaygood reacted with thumbs up emoji

@AlexWaygood
Copy link
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 aTypedDict 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

@AlexWaygoodAlexWaygood self-requested a reviewFebruary 7, 2022 21:17
97littleleaf11and others added2 commitsFebruary 8, 2022 23:46
Co-authored-by: AlexWaygood <Alex.Waygood@Gmail.com>
@97littleleaf1197littleleaf11 changed the titlebpo-46066: Remove kwargs syntax for TypedDict definitionbpo-46066: Deprecate kwargs syntax for TypedDict definitionsFeb 8, 2022
Misc/ACKS Outdated
@@ -1976,6 +1976,7 @@ Masayuki Yamamoto
Ka-Ping Yee
Chi Hsuan Yen
Jason Yeo
Jingchen Ye
Copy link
Member

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.

@AlexWaygood
Copy link
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?

@97littleleaf11
Copy link
ContributorAuthor

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

@AlexWaygood
Copy link
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 :)

Copy link
Member

@AlexWaygoodAlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM

@AlexWaygood
Copy link
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 totyping, though, so perhaps he'll be kind enough to include a mention of this as well :)

@AlexWaygood
Copy link
Member

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

Copy link
Member

@gvanrossumgvanrossum left a 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. :-(

@97littleleaf11
Copy link
ContributorAuthor

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

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

@arhadthedev
Copy link
Member

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

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

[...] syntactic forms:

  • using a literaldict 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

Copy link
Member

@JelleZijlstraJelleZijlstra left a 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"

AlexWaygood and 97littleleaf11 reacted with thumbs up emoji
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::

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 "aTypedDict may be created using a functional form". This parallelshttps://docs.python.org/3.10/library/enum.html#functional-api

97littleleaf11 reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks for this!

Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})

Secondly, using keyword arguments::

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::

@gvanrossum
Copy link
Member

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

@gvanrossum
Copy link
Member

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

AlexWaygood reacted with hooray emoji

@gvanrossum
Copy link
Member

Congrats Jelle!

JelleZijlstra, AlexWaygood, and 97littleleaf11 reacted with hooray emoji

@AlexWaygood
Copy link
Member

And congrats@97littleleaf11 on your first CPython contribution!

97littleleaf11 reacted with hooray emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

@gvanrossumgvanrossumgvanrossum approved these changes

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-Spinner

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
7 participants
@97littleleaf11@the-knights-who-say-ni@AlexWaygood@arhadthedev@gvanrossum@JelleZijlstra@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp