mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
Add __asdict__() to NamedTuple and refine the docs.
Add maxlen support to deque() and fixup docs. Partially fix __reduce__(). The None as a third arg was no longer supported. Still needs work on __reduce__() to handle recursive inputs.
This commit is contained in:
parent
c9b7163da5
commit
a7fc4b13e0
6 changed files with 228 additions and 162 deletions
|
@ -13,6 +13,7 @@ class TestNamedTuple(unittest.TestCase):
|
|||
self.assertEqual(Point.__getitem__, tuple.__getitem__)
|
||||
self.assertRaises(ValueError, NamedTuple, 'abc%', 'def ghi')
|
||||
self.assertRaises(ValueError, NamedTuple, 'abc', 'def g%hi')
|
||||
self.assertRaises(ValueError, NamedTuple, 'abc', '__def__ ghi')
|
||||
NamedTuple('Point0', 'x1 y2') # Verify that numbers are allowed in names
|
||||
|
||||
def test_instance(self):
|
||||
|
@ -32,6 +33,7 @@ class TestNamedTuple(unittest.TestCase):
|
|||
self.assert_('__weakref__' not in dir(p))
|
||||
self.assertEqual(p.__fields__, ('x', 'y')) # test __fields__ attribute
|
||||
self.assertEqual(p.__replace__('x', 1), (1, 22)) # test __replace__ method
|
||||
self.assertEqual(p.__asdict__(), dict(x=11, y=22)) # test __dict__ method
|
||||
|
||||
# verify that field string can have commas
|
||||
Point = NamedTuple('Point', 'x, y')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue