On Sat, Sep 26, 2020 at 11:49 PM Guido van Rossum <guido@python.org> wrote:
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).
Ok I do understand, my suggestion was just to go ahead and let them be bound to the wrong arguments when someone makes what is a mistake.
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 `()`.
Yeah good point, people can make mistakes as things stand. My desire was to prevent creation of specific new possibility of mistake that leads to side effects that might be hard to uncover/debug. 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) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
Ok I'll refrain from responding on this topic anymore. Sorry Guido just trying to help since the assumption that a sentinel is needed at all didn't really make sense to me (still doesn't). --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler On Sat, Sep 26, 2020 at 11:49 PM Guido van Rossum <guido@python.org> wrote:
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) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>