mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Accept Issac Morland's suggestion for __replace__ to allow multiple replacements
(suprisingly, this simplifies the signature, improves clarity, and is comparably fast). Update the docs to reflect a previous change to the function name. Add an example to the docs showing how to override the default __repr__ method.
This commit is contained in:
parent
b5e5d0741a
commit
eeeb9c4445
3 changed files with 33 additions and 18 deletions
|
|
@ -40,7 +40,7 @@ class TestNamedTuple(unittest.TestCase):
|
|||
self.assert_('__dict__' not in dir(p)) # verify instance has no dict
|
||||
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.__replace__(x=1), (1, 22)) # test __replace__ method
|
||||
self.assertEqual(p.__asdict__(), dict(x=11, y=22)) # test __dict__ method
|
||||
|
||||
# Verify that __fields__ is read-only
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue