mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
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 f56268a2cd)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
c523022ba8
commit
d452b2963b
2 changed files with 14 additions and 0 deletions
|
|
@ -4081,6 +4081,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__()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue