mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Issue #24931: Resolve __dict__ conflict in namedtuple subclasses.
This commit is contained in:
parent
1a83746418
commit
7a3602e7cf
4 changed files with 19 additions and 14 deletions
|
|
@ -225,7 +225,6 @@ class TestNamedTuple(unittest.TestCase):
|
|||
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 _asdict method
|
||||
self.assertEqual(vars(p), p._asdict()) # verify that vars() works
|
||||
|
||||
try:
|
||||
p._replace(x=1, error=2)
|
||||
|
|
@ -380,6 +379,17 @@ class TestNamedTuple(unittest.TestCase):
|
|||
globals().pop('NTColor', None) # clean-up after this test
|
||||
|
||||
|
||||
def test_namedtuple_subclass_issue_24931(self):
|
||||
class Point(namedtuple('_Point', ['x', 'y'])):
|
||||
pass
|
||||
|
||||
a = Point(3, 4)
|
||||
self.assertEqual(a._asdict(), OrderedDict([('x', 3), ('y', 4)]))
|
||||
|
||||
a.w = 5
|
||||
self.assertEqual(a.__dict__, {'w': 5})
|
||||
|
||||
|
||||
################################################################################
|
||||
### Abstract Base Classes
|
||||
################################################################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue