[issue42765] Introduce new data model method __iter_items__

2021-01-06 Thread Richard Neumann
Richard Neumann added the comment: Okay, I found the solution. Not using super() works: from typing import NamedTuple class Spamm(NamedTuple): foo: int bar: str def __getitem__(self, index_or_key): if isinstance(index_or_key, str): try:

[issue42765] Introduce new data model method __iter_items__

2021-01-06 Thread Richard Neumann
Richard Neumann added the comment: Thank you all for your input. I had a look at aforementioned discussion and learned something new. So I tried to implement the dict data model by implementing keys() and __getitem__() accordingly: from typing import NamedTuple class Spamm(NamedTuple):

[issue42765] Introduce new data model method __iter_items__

2020-12-28 Thread Eric V. Smith
Change by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue42765] Introduce new data model method __iter_items__

2020-12-28 Thread Steven D'Aprano
Steven D'Aprano added the comment: Hi Richard, > Also, using _asdict() seems strange as an exposed API, since it's an > underscore method and users hence might not be inclined to use it. I don't consider this a strong argument. Named tuple in general has to use a naming convention for

[issue42765] Introduce new data model method __iter_items__

2020-12-28 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +bob.ippolito ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue42765] Introduce new data model method __iter_items__

2020-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: This core of this idea is plausible. It is a common problem for people to want to teach a class how to convert itself to and from JSON. Altering the API for dicts is a major step, so you would need to take this to python-ideas to start getting buy-in.

[issue42765] Introduce new data model method __iter_items__

2020-12-28 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue42765] Introduce new data model method __iter_items__

2020-12-28 Thread Richard Neumann
New submission from Richard Neumann : I have use cases in which I use named tuples to represent data sets, e.g: class BasicStats(NamedTuple): """Basic statistics response packet.""" type: Type session_id: BigEndianSignedInt32 motd: str game_type: str map: str