This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Deprecate keyword args syntax for TypedDict definition
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: 97littleleaf11, AlexWaygood, JelleZijlstra, gvanrossum, kj, sobolevn, xtreak
Priority: normal Keywords: patch

Created on 2021-12-13 15:36 by 97littleleaf11, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31126 merged 97littleleaf11, 2022-02-04 07:55
PR 31428 merged JelleZijlstra, 2022-02-19 06:02
Messages (11)
msg408458 - (view) Author: 97littleleaf11 (97littleleaf11) * Date: 2021-12-13 15:36
According 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 `total` keyword arg for TypedDict. In addition, PEP589(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.
msg408476 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-12-13 19:47
This is not really just a doc issue then, is it? Maybe we should just deprecate the feature?
msg408547 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-12-14 16:43
I recommend opening an issue here: https://github.com/python/typing/issues/new/choose
msg412990 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2022-02-10 10:48
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: https://github.com/python/typing/issues/981
- The initial impetus for this change was this mypy bug report: https://github.com/python/mypy/issues/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: https://github.com/python/mypy/issues/2492#issuecomment-579500959
msg413013 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-02-10 17:22
Go ahead and send a or to deprecate it.--
--Guido (mobile)
msg413014 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-02-10 17:31
"PR"
msg413016 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2022-02-10 17:34
@Guido, OP already has — Jelle and I have both reviewed and approved it :)
msg413379 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-02-17 03:26
New changeset de6043e596492201cc1a1eb28038970bb69f3107 by 97littleleaf11 in branch 'main':
bpo-46066: Deprecate kwargs syntax for TypedDict definitions (GH-31126)
https://github.com/python/cpython/commit/de6043e596492201cc1a1eb28038970bb69f3107
msg413531 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2022-02-19 05:25
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)
msg413535 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-02-19 05:57
Thanks, I'll send a PR.
msg413562 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-02-20 01:44
New changeset 0a8a8e7454c6565cf1554d5f23314e4c70960bcd by Jelle Zijlstra in branch 'main':
bpo-46066: Check DeprecationWarning in test_typing (GH-31428)
https://github.com/python/cpython/commit/0a8a8e7454c6565cf1554d5f23314e4c70960bcd
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90224
2022-02-20 01:44:58JelleZijlstrasetmessages: + msg413562
2022-02-19 06:02:02JelleZijlstrasetpull_requests: + pull_request29563
2022-02-19 05:57:51JelleZijlstrasetmessages: + msg413535
2022-02-19 05:25:14xtreaksetnosy: + xtreak
messages: + msg413531
2022-02-17 03:26:40JelleZijlstrasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-02-17 03:26:17JelleZijlstrasetmessages: + msg413379
2022-02-10 17:34:52AlexWaygoodsetmessages: + msg413016
2022-02-10 17:31:40gvanrossumsetmessages: + msg413014
2022-02-10 17:22:25gvanrossumsetmessages: + msg413013
2022-02-10 10:48:23AlexWaygoodsetmessages: + msg412990
2022-02-08 09:05:18AlexWaygoodsetnosy: - docs@python
title: Remove keyword args syntax for TypedDict definition -> Deprecate keyword args syntax for TypedDict definition
assignee: docs@python ->
versions: + Python 3.11, - Python 3.8, Python 3.9, Python 3.10
components: + Library (Lib), - Documentation
type: behavior
2022-02-04 12:24:59AlexWaygoodsetnosy: + JelleZijlstra, sobolevn, AlexWaygood
2022-02-04 07:55:5897littleleaf11setkeywords: + patch
stage: patch review
pull_requests: + pull_request29305
2022-02-04 07:52:5697littleleaf11settitle: TypedDict alternative definition syntax with keyword args is confusing -> Remove keyword args syntax for TypedDict definition
2021-12-14 16:43:02gvanrossumsetmessages: + msg408547
2021-12-14 12:39:0197littleleaf11settitle: [doc] TypedDict alternative definition syntax with keyword args is confusing -> TypedDict alternative definition syntax with keyword args is confusing
2021-12-13 19:47:07gvanrossumsetmessages: + msg408476
2021-12-13 17:36:57AlexWaygoodsetnosy: + gvanrossum, kj
2021-12-13 15:38:0897littleleaf11settitle: Docs: TypedDict alternative definition syntax with keyword args is confusing -> [doc] TypedDict alternative definition syntax with keyword args is confusing
2021-12-13 15:36:5797littleleaf11create