[Python-ideas] namedtuple literals [Was: RE a new namedtuple]
Ethan Furman
ethan at stoneleaf.us
Wed Jul 26 13:44:01 EDT 2017
On 07/26/2017 09:05 AM, Nick Coghlan wrote:
> On 26 July 2017 at 11:05, Steven D'Aprano <steve at pearwood.info> wrote:
>> I don't see any way that this proposal can be anything by a subtle
>> source of bugs. We have two *incompatible* requirements:
>>
>> - we want to define the order of the fields according to the
>> order we give keyword arguments;
>>
>> - we want to give keyword arguments in any order without
>> caring about the field order.
>>
>> We can't have both, and we can't give up either without being a
>> surprising source of annoyance and bugs.
>
> I think the second stated requirement isn't a genuine requirement, as
> that *isn't* a general expectation.
I have to agree with D'Aprano on this one. I certainly do not *expect* keyword argument position to matter, and it
seems to me the primary reason to make it matter was not for dicts, but because a class name space is implemented by dicts.
Tuples, named or otherwise, are positional first -- order matters. Specifying
point = ntuple(y=2, x=-3)
and having point[0] == 3 is going to be bizarre. This will be a source for horrible bugs.
--
~Ethan~
More information about the Python-ideas
mailing list