On Sat, Sep 26, 2020 at 10:30 PM Ben Rudiak-Gould <benrud...@gmail.com>
wrote:

> I don't understand the problem here.
>
>     d[p=q]  -->  d.__{get,set,del}item__((), ..., p=q)
>     d[1, p=q]  -->  d.__{get,set,del}item__((1), ..., p=q)
>     d[1, 2, p=q]  -->  d.__{get,set,del}item__((1, 2), ..., p=q)
>     d[1, 2, 3, p=q]  -->  d.__{get,set,del}item__((1, 2, 3), ..., p=q)
>     d[1, 2, ..., n, p=q]  -->  d.__{get,set,del}item__((1, 2, ..., n),
> ..., p=q)
>
> Now obviously the n=1 case is a wart. But the n=0 case isn't a wart. It's
> just like n=2, n=3, etc.
>
> You can't tell the difference between a single tuple argument and n
> arguments for any n≠1. As far as I can tell the problem when n=0 is no more
> or less serious than the problem when n≥2. I don't see the point of adding
> another special case to the spec when it doesn't even solve the general
> problem.
>

The problem is that there is lots of existing code like this:

def __setitem__(self, index, value): ...

But the new features will almost certainly lead people to write new code
like this:

d={}
obj[**d] = "foo"  # no kwd arguments provided here

...which, if someone does this arbitrarily against classes that use the
existing kind of code I gave at the first, will call (if the sentinel is ()
):

obj.__setitem__(())

...which could have all kinds of weird effects rather than giving an error,
as I think would be better.

Steven's response to that was essentially "well then, don't unpack
dictionaries against arbitrary subscriptable types" which I fully agree is
a perfectly legitimate response. But I think having no sentinel at all and
instead telling people "either provide a default argument for both index
AND value in your __setitem__ method, or neither" is also a perfectly
legitimate way forward.

Not sure which is better.

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
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/YMELT4Y7EYPRXY6XKQA72AULIBVGQQJR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to