[Python-ideas] Anonymous namedtuples, revisited

2022-03-24 Thread michael
Back in early 2016 there was an idea submitted[1] by Joseph Martinot-Lagarde in regard to anonymous namedtuples. The crux of the submission was the idea of instantiating a namedtuple using only Python's generic tuple syntax plus keyword arguments. At the time, the major rebuttal against this ide

[Python-ideas] Re: Anonymous namedtuples, revisited

2022-03-24 Thread Andrew Svetlov
The proposal doesn't work well with type hints: atuple(a=1, b=2) and atuple(a="a", b="b") generates the same type. Also, the automatic creation of a new type on-demand can lead to uncontrollable memory growth. On Thu, Mar 24, 2022 at 6:15 PM wrote: > Back in early 2016 there was an idea submitt

[Python-ideas] Re: Anonymous namedtuples, revisited

2022-03-24 Thread Michael Green
Well you have the values as they're passed in; just (optionally?) include the type in the signature if you want type differentiation >>> def anamedtuple(**kwargs): ... signature = " ".join([f"{k}: {type(v)}" for k, v in kwargs.items()]) ... _type = anamedtuple.__dict__.get(signatu

[Python-ideas] Re: Anonymous namedtuples, revisited

2022-03-24 Thread Eric V. Smith
On 3/23/2022 5:03 PM, [email protected] wrote: Back in early 2016 there was an idea submitted[1] by Joseph Martinot-Lagarde in regard to anonymous namedtuples. The crux of the submission was the idea of instantiating a namedtuple using only Python's generic tuple syntax plus keyword arg

[Python-ideas] Re: Anonymous namedtuples, revisited

2022-03-24 Thread Christopher Barker
On Thu, Mar 24, 2022 at 4:44 PM Eric V. Smith wrote: > I don't think this is justifiable as built-in behavior. Just rename your > function "t", then you can write t(x=12, y=16). If nothing else, a good way to prototype it and see if folks like it. I agree that there may be little reason to make

[Python-ideas] Re: Anonymous namedtuples, revisited

2022-03-24 Thread Brendan Barnwell
On 2022-03-24 10:43, Andrew Svetlov wrote: The proposal doesn't work well with type hints: atuple(a=1, b=2) and atuple(a="a", b="b") generates the same type. I'm neither here nor there on the original proposal, but I just want to push back against this reasoning. Type hints are an entirely o