Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
11 commits Select commit Hold shift + click to select a range
0c12774 Remove kwargs syntax for TypedDict
97littleleaf11 f3588ac Add deprecation flag and warning
97littleleaf11 4d988a8 Add blurb and address reviews
97littleleaf11 f21c30a Change docs
97littleleaf11 3f60fb0 Add name
97littleleaf11 033cf07 Fix
97littleleaf11 eea168f Modify docs
97littleleaf11 15a7930 Use bullet list
97littleleaf11 b9badea Fix
97littleleaf11 a6a870c Fix
97littleleaf11 8b113dd reverse
97littleleaf11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2399,9 +2399,8 @@ class Point2D(TypedDict): | ||
| The type info can be accessed via the Point2D.__annotations__ dict, and | ||
| the Point2D.__required_keys__ and Point2D.__optional_keys__ frozensets. | ||
| TypedDict supports two additional equivalent forms:: | ||
| TypedDict supports an additional equivalent form:: | ||
| Point2D = TypedDict('Point2D', x=int, y=int, label=str) | ||
| Point2D = TypedDict('Point2D',{'x': int, 'y': int, 'label': str}) | ||
| By default, all keys must be present in a TypedDict. It is possible | ||
| @@ -2417,14 +2416,22 @@ class point2D(TypedDict, total=False): | ||
| the total argument. True is the default, and makes all items defined in the | ||
| class body be required. | ||
| The class syntax is only supported in Python 3.6+, while two other | ||
| syntax forms work for Python 2.7 and 3.2+ | ||
| The class syntax is only supported in Python 3.6+, while the other | ||
| syntax form works for Python 2.7 and 3.2+ | ||
| """ | ||
| if fields is None: | ||
| fields = kwargs | ||
| elif kwargs: | ||
| raise TypeError("TypedDict takes either a dict or keyword arguments," | ||
| " but not both") | ||
| if kwargs: | ||
97littleleaf11 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| warnings.warn( | ||
| "The kwargs-based syntax for TypedDict definitions is deprecated " | ||
| "in Python 3.11, will be removed in Python 3.13, and may not be " | ||
| "understood by third-party type checkers.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| ns ={'__annotations__': dict(fields)} | ||
| module = _caller() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions 3 Misc/NEWS.d/next/Library/2022-02-08-16-42-20.bpo-46066.m32Hl0.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Deprecate kwargs-based syntax for :class:`typing.TypedDict` definitions. | ||
| It had confusing semantics when specifying totality, and was largely unused. | ||
| Patch by Jingchen Ye. |
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.
Uh oh!
There was an error while loading. Please reload this page.