[Python-ideas] Delegating `BoundArguments.__getitem__` to `BoundArguments.arguments.__getitem__`

Nick Coghlan ncoghlan at gmail.com
Sat Oct 4 13:39:07 CEST 2014


On 4 October 2014 07:34, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
> You'll also need to delegate __setitem__, keys(), __len__ and all other
> Mapping methods. And to be honest, I see absolutely no point in doing this.

I don't see a benefit either.

Ram,  please try to remember that shorter isn't better if it comes at
a cost in clarity, and that *every single change to Python* comes at a
substantial cost in terms of the long term ripple effect it has on the
ecosystem.

This is at the heart of the "one - and preferably only one - obvious
way to do it" philosophy - avoiding redundancy wherever possible
promotes consistency, which reduces the number of things that folks
need to learn how to *read*.

As a result, adding a redundant spelling of an existing feature has to
offer an *extraordinarily* compelling readability benefit for it to
ever be worthwhile. Saving a few characters when typing is almost
never going to be sufficiently compelling.

In this particular case, it's also worth noting that we explicitly
moved *away* from a similar "implicit subcontainer access" model for
exception arguments in order to eliminate the redundancy:

# Python 2
>>> Exception(1, 2, 3).args[2]
3
>>> Exception(1, 2, 3)[2]
3

# Python 3
>>> Exception(1, 2, 3).args[2]
3
>>> Exception(1, 2, 3)[2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Exception' object is not subscriptable

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list