Repository navigation
Deprecate keyword args syntax for TypedDict definition #90224
Description
Activity
97littleleaf11 commented
on Dec 13, 2021 97littleleaf11mannequinMannequinAuthorMore actionsAccording to the docs: https://docs.python.org/3/library/typing.html?#typing.TypedDict, there are two additional equivalent syntax for TypedDict definition.
Point2D = TypedDict('Point2D', x=int, y=int, label=str) Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})
However, the former one is quite confusing since we have the
totalkeyword arg for TypedDict. In addition, PEP-589(https://www.python.org/dev/peps/pep-0589/#id19) doesn't have this.I think we could discard the definition syntax using keyword args in the doc.
- added3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dir
on Dec 13, 2021 - added3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dir
on Dec 13, 2021 - changed the title
[-]Docs: TypedDict alternative definition syntax with keyword args is confusing[/-][+][doc] TypedDict alternative definition syntax with keyword args is confusing[/+]on Dec 13, 2021 - changed the title
[-]Docs: TypedDict alternative definition syntax with keyword args is confusing[/-][+][doc] TypedDict alternative definition syntax with keyword args is confusing[/+]on Dec 13, 2021 This is not really just a doc issue then, is it? Maybe we should just deprecate the feature?
- changed the title
[-][doc] TypedDict alternative definition syntax with keyword args is confusing[/-][+]TypedDict alternative definition syntax with keyword args is confusing[/+]on Dec 14, 2021 20 remaining items
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Feb 8, 2022 Just so that all the discussion related to this issue can be found in one place, here's a summary:
- After opening this ticket, OP opened an issue in the python/typing repository, where the idea of deprecating this syntax received many thumbs-up reactions, and where there were no dissenting voices: TypedDict alternative definition syntax with keyword args is confusing typing#981
- The initial impetus for this change was this mypy bug report: TypedDict using keywords causes "error: Too many arguments for TypedDict()" mypy#11555
- Mypy's policy since January 2020 has been that it would be more trouble than it's worth to attempt to support the kwargs-based syntax: TypedDict syntax variant with keyword arguments mypy#2492 (comment)
Go ahead and send a or to deprecate it.--
--Guido (mobile)"PR"
@guido, OP already has — Jelle and I have both reviewed and approved it :)
This change has introduced deprecation warning in tests
PYTHONWARNINGS=always ./python -Wall -X dev -m test.test_typing ........................................................................................................................................................................................................................s................................................................................................................................................................................................./home/karthikeyan/stuff/python/cpython/Lib/test/test_typing.py:4589: DeprecationWarning: 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. TypedDict('Emp', _fields={'name': str, 'id': int}) ./home/karthikeyan/stuff/python/cpython/Lib/test/test_typing.py:4602: DeprecationWarning: 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. TypedDict('Hi', x=1) ........................................
Ran 451 tests in 0.105s
OK (skipped=1)
Thanks, I'll send a PR.
Doesn't this cause issues for keys that are valid as keys but not as identifiers?
To the contrary, the deprecated syntax caused issues for such keys. The syntax that isn't deprecated works fine, e.g.
Point2D = TypedDict('Point2D', {'x': int, 'y': int, '$label$': str})
Reacted by Jelle Zijlstra@gvanrossum Thanks for the quick response. I deleted my previous comment right after I posted it realizing I had entirely misread it as if the kwargs method was the one being retained.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: