summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-09-26 17:09:50 (GMT)
committerGitHub <noreply@github.com>2021-09-26 17:09:50 (GMT)
commitd452b2963ba91d6bce29bb96733ed8bd1c0448b0 (patch)
tree193269ec2963027de89966801903a81cc47d4dd3 /Lib
parentc523022ba8f81a3661b4ac8be81706ed095d5769 (diff)
downloadcpython-d452b2963ba91d6bce29bb96733ed8bd1c0448b0.zip
cpython-d452b2963ba91d6bce29bb96733ed8bd1c0448b0.tar.gz
cpython-d452b2963ba91d6bce29bb96733ed8bd1c0448b0.tar.bz2
bpo-45280: Add test for empty `NamedTuple` in `test_typing` (GH-28559) (GH-28571)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com> (cherry picked from commit f56268a2cd38b3fe2be1e4361d3d8b581e73559b) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_typing.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 4f250f2..762c0cc 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -4081,6 +4081,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__()