Skip to content

bpo-45280: Add test for empty NamedTuple in test_typing #28559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4099,6 +4099,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__()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a test case for empty :class:`typing.NamedTuple`.