diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-06-14 12:38:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-14 12:38:49 (GMT) |
commit | ad56340b665c5d8ac1f318964f71697bba41acb7 (patch) | |
tree | 85e07e09edb9ae29c96bcd4fcdf01b5378765f60 /Doc/whatsnew | |
parent | fc8037d84c5f886849a05ec993dd0f79a356d372 (diff) | |
download | cpython-ad56340b665c5d8ac1f318964f71697bba41acb7.zip cpython-ad56340b665c5d8ac1f318964f71697bba41acb7.tar.gz cpython-ad56340b665c5d8ac1f318964f71697bba41acb7.tar.bz2 |
gh-105566: Deprecate unusual ways of creating `typing.NamedTuple` classes (#105609)
Deprecate creating a typing.NamedTuple class using keyword arguments to denote the fields (`NT = NamedTuple("NT", x=int, y=str)`). This will be disallowed in Python 3.15. Use the class-based syntax or the functional syntax instead.
Two methods of creating `NamedTuple` classes with 0 fields using the functional syntax are also deprecated, and will be disallowed in Python 3.15: `NT = NamedTuple("NT")` and `NT = NamedTuple("NT", None)`. To create a `NamedTuple` class with 0 fields, either use `class NT(NamedTuple): pass` or `NT = NamedTuple("NT", [])`.
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.13.rst | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index fcd10e5..cf7c2ca 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -141,6 +141,17 @@ Deprecated methods of the :class:`wave.Wave_read` and :class:`wave.Wave_write` classes. They will be removed in Python 3.15. (Contributed by Victor Stinner in :gh:`105096`.) +* Creating a :class:`typing.NamedTuple` class using keyword arguments to denote + the fields (``NT = NamedTuple("NT", x=int, y=int)``) is deprecated, and will + be disallowed in Python 3.15. Use the class-based syntax or the functional + syntax instead. (Contributed by Alex Waygood in :gh:`105566`.) +* When using the functional syntax to create a :class:`typing.NamedTuple` + class, failing to pass a value to the 'fields' parameter + (``NT = NamedTuple("NT")``) is deprecated. Passing ``None`` to the 'fields' + parameter (``NT = NamedTuple("NT", None)``) is also deprecated. Both will be + disallowed in Python 3.15. To create a NamedTuple class with 0 fields, use + ``class NT(NamedTuple): pass`` or ``NT = NamedTuple("NT", [])``. + (Contributed by Alex Waygood in :gh:`105566`.) * :mod:`array`'s ``'u'`` format code, deprecated in docs since Python 3.3, emits :exc:`DeprecationWarning` since 3.13 |