On Wed, Aug 26, 2020 at 9:46 AM David Mertz <me...@gnosis.cx> wrote:

> In my mind, *anything* other than the straightforward and obvious
> signature `__getitem__(self, index, **kws)` is a pointless distraction.
>
> ...

> Yes, it's slightly funny that square brackets convert to `index` rather
> than `*index`, but that ship sailed very long ago, and it's no big deal.
> There's no problem that needs solving and no need for code churn.
>

I disagree here -- sure, for full backwards compatibility and preservation
of performance, we'll probably have to live with it. But the fact that the
square brackets don't create a tuple makes it fundamentally odd and
confusing to work with -- not too big a deal when [] only accepted a single
expression, and therefor passed a single value on to the dunders, but it
gets very odd when you have something that looks a lot like a function
call, but is different. And it gets worse for __setitem__, which I guess
will be:

thing[ind1, ind2, kwd1=v1, kw2=v2] = value

Translating to:

thing.__setitem__(self, (ind1, ind2), value, kwd1=v1, kw2=v2)

which is pretty darn weird -- particularly if you try to write the handler
this way:

def __setitem__(self, *args, **kwargs):

so: args would always be a 2-tuple, something like: ((ind1, ind2), value)

At least **kwargs would be "normal", yes?

On the plus side, this weirdness is only really exposed to folks writing
classes with complex custom indexing behavior, and would still look like
the same semantics as a function call to the users of that class.

well, almost -- it would not support [*args] -- would it support [**kwargs]
?

And this kind of thing is very much a write once, use a lot situation.

TL;DR -- let's watch the strong language here -- these proposals do attempt
to address a real problem -- probably not worth the downsides, but this
"doesn't solve any problem", "no one asked for it", etc, is really
dismissive.

-CHB


>
> _______________________________________________
> 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
> https://mail.python.org/archives/list/python-ideas@python.org/message/IXGZNYZEKHBNE6E52WKTENNGOIKXOVV6/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/YSQMO4ZLYI3OUGYL254ZIX6MK2CQ3DCU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to