summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2021-09-26 16:32:18 (GMT)
committerGitHub <noreply@github.com>2021-09-26 16:32:18 (GMT)
commitf56268a2cd38b3fe2be1e4361d3d8b581e73559b (patch)
treef0b993e5791006e84f550bcceb980b38c31e575a
parent7834ff26cbcd4d8394d64d80d9f51a364d38b1c6 (diff)
downloadcpython-f56268a2cd38b3fe2be1e4361d3d8b581e73559b.zip
cpython-f56268a2cd38b3fe2be1e4361d3d8b581e73559b.tar.gz
cpython-f56268a2cd38b3fe2be1e4361d3d8b581e73559b.tar.bz2
bpo-45280: Add test for empty `NamedTuple` in `test_typing` (GH-28559)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
-rw-r--r--Lib/test/test_typing.py13
-rw-r--r--Misc/NEWS.d/next/Tests/2021-09-25-11-05-31.bpo-45280.3MA6lC.rst1
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index d1887f7..38397a0 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -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
index 0000000..71691f5
--- /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`.