https://github.com/python/cpython/commit/17ab556e39e9b40c7d4308664de42f0564048044
commit: 17ab556e39e9b40c7d4308664de42f0564048044
branch: main
author: bkap123 <[email protected]>
committer: AlexWaygood <[email protected]>
date: 2026-02-11T12:44:22Z
summary:
gh-144321: Fix named tuple bug when input is a non-sequence iterable (#144600)
files:
A Misc/NEWS.d/next/Library/2026-02-08-17-09-10.gh-issue-144321.w58PhQ.rst
M Lib/test/test_typing.py
M Lib/typing.py
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 72ae7776ab9062..50938eadc8f9f3 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -8532,6 +8532,15 @@ class ThisWontWorkEither(NamedTuple):
def name(self):
return __class__.__name__
+ def test_named_tuple_non_sequence_input(self):
+ field_names = ["x", "y"]
+ field_values = [int, int]
+ Point = NamedTuple("Point", zip(field_names, field_values))
+ p = Point(1, 2)
+ self.assertEqual(p.x, 1)
+ self.assertEqual(p.y, 2)
+ self.assertEqual(repr(p),"Point(x=1, y=2)")
+
class TypedDictTests(BaseTestCase):
def test_basics_functional_syntax(self):
diff --git a/Lib/typing.py b/Lib/typing.py
index 71a08a5f1df811..2dfa6d3b1499ca 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -3075,8 +3075,7 @@ class Employee(NamedTuple):
"""
types = {n: _type_check(t, f"field {n} annotation must be a type")
for n, t in fields}
- field_names = [n for n, _ in fields]
- nt = _make_nmtuple(typename, field_names, _make_eager_annotate(types),
module=_caller())
+ nt = _make_nmtuple(typename, types, _make_eager_annotate(types),
module=_caller())
nt.__orig_bases__ = (NamedTuple,)
return nt
diff --git
a/Misc/NEWS.d/next/Library/2026-02-08-17-09-10.gh-issue-144321.w58PhQ.rst
b/Misc/NEWS.d/next/Library/2026-02-08-17-09-10.gh-issue-144321.w58PhQ.rst
new file mode 100644
index 00000000000000..45561898e2e1e9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-02-08-17-09-10.gh-issue-144321.w58PhQ.rst
@@ -0,0 +1,3 @@
+The functional syntax for creating :class:`typing.NamedTuple`
+classes now supports passing any :term:`iterable` of fields and types.
+Previously, only sequences were supported.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]