-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Right now only collections.namedtuple
is tested:
Lines 937 to 946 in b1aebf1
def test_namedtuple(self): | |
from collections import namedtuple | |
Point = namedtuple('Point', 'x y', defaults=(0,)) | |
p = Point(11, 22) | |
self.assertEqual(copy.replace(p), (11, 22)) | |
self.assertEqual(copy.replace(p, x=1), (1, 22)) | |
self.assertEqual(copy.replace(p, y=2), (11, 2)) | |
self.assertEqual(copy.replace(p, x=1, y=2), (1, 2)) | |
with self.assertRaisesRegex(ValueError, 'unexpected field name'): | |
copy.replace(p, x=1, error=2) |
@serhiy-storchaka noted in #108752 (comment) that only named tuples created by collections.namedtuple()
are supported. But, since typing.NamedTuple
uses collections.namedtuple
inside:
Lines 2695 to 2696 in b1aebf1
nm_tpl = collections.namedtuple(name, fields, | |
defaults=defaults, module=module) |
>>> import typing
>>>
>>> class N(typing.NamedTuple):
... x: int
... y: int
...
>>> N.__replace__
<function N._replace at 0x10580a210>
>>> import copy
>>> copy.replace(N(1, 2), x=3)
N(x=3, y=2)
I have a PR ready with extra tests.
Linked PRs
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error