Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> For named tuples, you are better off using the typed version typing.NamedTuple [1] instead of the classical one suggested in the article. Aside from providing typing, the typed version has a much nicer syntax to define it and lets you add methods (like dataclasses but unlike classical named tuples)

It's been a while since I worked in python, but aren't the original namedtuples populated with __slots__ instead of a __dict__ which makes them a much better choice for very very large datasets? Albeit at the cost of duck typing.



As an aside, my preference for a class container is dataclass(slots=True) for typing. I’d normally used dataclasses as np array containers vs serialized tuple row objects.


@dataclass(slots=True) works too


typing.NamedTuple also sets `__slots__ = ()`, just like collections.namedtuple.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: