Of course I have tried:
class PdfContentRecord(NamedTuple):
filename: str
page: int
cache: dict
data: dict = dict()
accessed: str = None
def __new__(cls, *args, **kwargs):
self = super().__new__(*args, **kwargs)
self.accessed = datetime.now().isoformat()
return self
But I get exactly the same error as How to provide additional initialization for a subclass of namedtuple?
I can't tell if attrs
can help me (too difficult to comprehend). dataclasses.dataclass
probably can help, but it only supports Python 3.7.
Or I could write my Class, probably also with __slots__
...
Edit:
Did you read the answer in the question you linked?
works with from collection import namedtuple
, but not from typing import NamedTuple
.