[Python-checkins] bpo-45280: Add test for empty `NamedTuple` in `test_typing` (GH-28559) (GH-28570)

ambv webhook-mailer at python.org
Sun Sep 26 13:09:34 EDT 2021


https://github.com/python/cpython/commit/08e387ab82331230d7f6608e949723d8a8e09229
commit: 08e387ab82331230d7f6608e949723d8a8e09229
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-09-26T19:09:29+02:00
summary:

bpo-45280: Add test for empty `NamedTuple` in `test_typing` (GH-28559) (GH-28570)

Co-authored-by: Dong-hee Na <donghee.na92 at gmail.com>
(cherry picked from commit f56268a2cd38b3fe2be1e4361d3d8b581e73559b)

Co-authored-by: Nikita Sobolev <mail at sobolevn.me>

files:
A Misc/NEWS.d/next/Tests/2021-09-25-11-05-31.bpo-45280.3MA6lC.rst
M Lib/test/test_typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index df6b3b76d6ddf..1163d6f70aef1 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -3818,6 +3818,19 @@ def test_namedtuple_special_keyword_names(self):
         self.assertEqual(a.typename, 'foo')
         self.assertEqual(a.fields, [('bar', tuple)])
 
+    def test_empty_namedtuple(self):
+        NT = NamedTuple('NT')
+
+        class CNT(NamedTuple):
+            pass  # empty body
+
+        for struct in [NT, CNT]:
+            with self.subTest(struct=struct):
+                self.assertEqual(struct._fields, ())
+                self.assertEqual(struct._field_defaults, {})
+                self.assertEqual(struct.__annotations__, {})
+                self.assertIsInstance(struct(), struct)
+
     def test_namedtuple_errors(self):
         with self.assertRaises(TypeError):
             NamedTuple.__new__()
diff --git a/Misc/NEWS.d/next/Tests/2021-09-25-11-05-31.bpo-45280.3MA6lC.rst b/Misc/NEWS.d/next/Tests/2021-09-25-11-05-31.bpo-45280.3MA6lC.rst
new file mode 100644
index 0000000000000..71691f5ba2b89
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2021-09-25-11-05-31.bpo-45280.3MA6lC.rst
@@ -0,0 +1 @@
+Add a test case for empty :class:`typing.NamedTuple`.



More information about the Python-checkins mailing list