mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-45280: Add test for empty NamedTuple
in test_typing
(GH-28559)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
This commit is contained in:
parent
7834ff26cb
commit
f56268a2cd
2 changed files with 14 additions and 0 deletions
|
@ -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__()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Add a test case for empty :class:`typing.NamedTuple`.
|
Loading…
Add table
Add a link
Reference in a new issue