[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Eric V. Smith
In dataclasses, support for __slots__ is being added in 3.10. Adding optional support for iteration would be easy. -- Eric V. Smith > On Jul 28, 2021, at 7:29 PM, Paul Bryan wrote: > >  > I'm with you; since dataclasses were introduced, namedtuple has not see any > use from me, though none

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread pavel
I like this idea! It's true that deprecating the namedtuple we lose important semantics of order - however, if its use as a weaker dataclass is explicitly discouraged in the documentation, then much of the problem (i.e., people that want to have a simple data object use two incompatible things d

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread David Mertz
I frequently use each of namedtuples and data classes in contexts where the other one would not be appropriate. Yes, I also sometimes use an object where either would serve... In those cases, mostly SimpleNamespace would likewise be fine. So would a one line class definition. On Wed, Jul 28, 2021,

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Chris Angelico
On Thu, Jul 29, 2021 at 10:00 AM wrote: > > I'm with you on the backwards-compatibility front. Changing Python fast and > for no particular reason incurs a big cost. Is the reason good enough to > justify removing a chunk of the interface? Good question. > Answer: Almost never. Case in point:

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Jack DeVries
>From https://death.andgravity.com/namedtuples linked to above by Titus: > pairs of things, like HTTP headers (a dict is not always appropriate, since > the same header can appear more than once, and the order does matter in some cases) To me, this is a perfect case of behavior that namedtuples a

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread pavel
I'm with you on the backwards-compatibility front. Changing Python fast and for no particular reason incurs a big cost. Is the reason good enough to justify removing a chunk of the interface? Good question. To your dict argument: if there was a native Pythonic way to make a frozen list, what wo

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread pavel
It's not actually that, although that's a good point you are making. I found myself using both of them not because one is more useful in certain cases and the other in others in small and niche ways. Both of the times I just used the latest one that came to mind. The fact that two different clas

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Thomas Grainger
I've thing I still use NamedTuple for is when I want type safe heterogeneous iterable unpacking, which is only possible for tuples (and NamedTuple) eg I'd like to be able to express both: tx, rx = trio.MemoryChanel[int]() And: with trio.MemoryChannel[int]() as channel: n.start_soon(worker, c

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Chris Angelico
On Thu, Jul 29, 2021 at 9:37 AM wrote: > > I was writing some code the other day, and it needed a quick-and-dirty data > structure definition for a set of related variables. I looked back at other > code to try be consistent, and found that I used dataclasses in some parts > and namedtuples in

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread pavel
I was writing some code the other day, and it needed a quick-and-dirty data structure definition for a set of related variables. I looked back at other code to try be consistent, and found that I used dataclasses in some parts and namedtuples in others. Both seemed the right thing to do at the t

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Chris Angelico
On Thu, Jul 29, 2021 at 9:28 AM Paul Bryan wrote: > > I'm with you; since dataclasses were introduced, namedtuple has not see any > use from me, though none of my uses have demanded ultra-high efficiency > either. > > I wonder how many users are currently relying on namedtuple __getitem__ > sem

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Paul Bryan
I'm with you; since dataclasses were introduced, namedtuple has not see any use from me, though none of my uses have demanded ultra-high efficiency either. I wonder how many users are currently relying on namedtuple __getitem__ semantics though. that's functionality dataclasses do not (currently)

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Titus Brown
Hi, I ran across this nice article a few days ago - https://death.andgravity.com/namedtuples which provides some answers as to why you might consider using named tuples. best, —titus > On Jul 28, 2021, at 3:22 PM, pa...@lexyr.com wrote: > > [Migrating the discussion from https://bugs.python.or

[Python-ideas] Re: Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread Chris Angelico
On Thu, Jul 29, 2021 at 9:07 AM wrote: > > [Migrating the discussion from https://bugs.python.org/issue44768.] > > PEP 20 says: > > > There should be one-- and preferably only one --obvious way to do it. > > There are two ways to create a simple named type to store data: > collections.namedtuple

[Python-ideas] Why do we have two obvious ways to create a simple data structure? Let's deprecate one.

2021-07-28 Thread pavel
[Migrating the discussion from https://bugs.python.org/issue44768.] PEP 20 says: > There should be one-- and preferably only one --obvious way to do it. There are two ways to create a simple named type to store data: collections.namedtuple and dataclasses.dataclass. I propose deprecating named

[Python-ideas] Re: More natural type hints for built-in containers

2021-07-28 Thread Ignacio Pickering
Ahh, I see, yes, that actually makes a lot of sense. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at

[Python-ideas] Re: More natural type hints for built-in containers

2021-07-28 Thread Jelle Zijlstra
I suggested this before in some typing meetup, but there are a few problems with it. One is that annotating arguments as "list" or "dict" is often the wrong thing to do: instead, people should use broader, immutable types like Iterable, Sequence, or Mapping, to avoid variance problems ( https://myp