Closed
Description
Following code should work as expected
In [1]: from typing import NamedTuple
In [2]: class X(NamedTuple):
...: x: int
...: def double(self):
...: return 2 * x
...:
In [3]: X(1).double()
At the moment it throws AttributeError
as there is no double
method on the constructed namedtuple.
The workaround is to define methods on subclass and set __slots__ = ()
. But unless I'm missing something, there is no reason why methods shouldn't work as expected.
Metadata
Metadata
Assignees
Labels
No labels