On Sat, Sep 26, 2020 at 7:44 PM Ricky Teachey <ricky@teachey.org> wrote:
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__((), "foo")  # [Correction by Guido after Ricky's email]

...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.

As I said there clearly are problems with your solution, because there's no way to call a function with the first positional argument omitted and the second positional argument given (and as I have argued, in the presence of `**kwargs`, index and value *must* be positional-only arguments).

And honestly, if you want to shoot yourself in the foot (or have some use for it!), you can write
```
d[()] = "foo"
```
in today's Python. Presumably someone who uses `obj[**kwargs]` is doing it for an object that takes keyword args, so that object must already be prepared for index being `()`.

PS. Maybe we can just stop debating this PEP? I have a feeling that we're going around in circles. I think Stefano has some changes that he would like to see vetted, but the best way to signal an empty index is not one of them.

--
--Guido van Rossum (python.org/~guido)