]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45280: Add test for empty `NamedTuple` in `test_typing` (GH-28559)
authorNikita Sobolev <mail@sobolevn.me>
Sun, 26 Sep 2021 16:32:18 +0000 (19:32 +0300)
committerGitHub <noreply@github.com>
Sun, 26 Sep 2021 16:32:18 +0000 (18:32 +0200)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Lib/test/test_typing.py
Misc/NEWS.d/next/Tests/2021-09-25-11-05-31.bpo-45280.3MA6lC.rst [new file with mode: 0644]

index d1887f7eee4437b11ecd956482b4d2d453177e99..38397a07e5717957f005376937d98158a31659c8 100644 (file)
@@ -4115,6 +4115,19 @@ class NamedTupleTests(BaseTestCase):
         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 (file)
index 0000000..71691f5
--- /dev/null
@@ -0,0 +1 @@
+Add a test case for empty :class:`typing.NamedTuple`.