On Mon, Aug 31, 2020, at 00:26, Chris Angelico wrote:
> Maybe I'm misreading this, but my understanding is that the definition
> of the dunder is actually how it's called, not what its signature is.
> The simplest and most obvious way to do it would be to have the
> interpreter pass the value positionally, and then keyword arguments
> separately. You can use whatever name you like for the value, and if
> you want, you can mandate that it be positional-only:
> 
> def __setitem__(self, key, value, /, **kw):
> 
> and then you can accept any arguments you like by keyword, even
> "self", "key", or "value".

Keep in mind that I am responding to a post that seems to call for new dunder 
methods that are passed multiple positional "key" arguments instead of a single 
one.

Passing the value last [i.e. in between the passed-as-positional and 
passed-as-keyword arguments] seems like a non-starter:

a[1, 2] = 3: f(self, 1, 2, 3)
a[1, y=2] = 3: f(self, 1, 3, y=2)
a[2, x=1] = 3: f(self, 2, 3, x=1)

There's no possible function signature that can reasonably deal with those.

essentially, by being a named argument that is not an intended keyword 
argument, value acts like / in the argument list, preventing any arguments 
before it from being passed in as keywords without causing errors. But since it 
is passed in positionally, it also prevents any arguments after it from being 
passed in as positional at all.

passing the value *first* might be reasonable (it may be the only viable way), 
but it would be a change from how it's currently done, and I do think this 
needs to be discussed for any proposal around passing in multiple positional 
keys.

passing the value in as a keyword called __value__ might be another possible 
way.

> This doesn't change the issue of tuplification, but it does mean that
> the issue is no worse for setitem than for getitem.
_______________________________________________
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/YOQAOJDES4AQPAFCNYFM4KYIGOCK5LYV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to