On Mon, Aug 31, 2020, at 00:28, Guido van Rossum wrote:
> On Sun, Aug 30, 2020 at 8:36 PM Random832 <random...@fastmail.com> wrote:
> > The thing that bothers me with new dunders is - can it be done in such a 
> > way that *all* possible ways of calling it with only positional arguments 
> > behave the same as presently when the old one is defined, and an intuitive 
> > way with the new one, without requiring the calling bytecode to know which 
> > signature is going to be used?
> 
> Probably not. (And knowing the signature is impossible -- there are too 
> many layers of C code between the bytecode and the function object 
> being called.) This is why I ended up with the simplest proposal 
> possible -- keyword args get added to the end of `__getitem__` and 
> `__setitem__`, ensuring that `d[1, k=3]` is like `d[1]` + keyword, not 
> like `d[1,]` + keyword.

perhaps, but I did have a thought after making that post.

A new bytecode operation (we'll need one anyway, right?) which, in addition to 
passing in the positionals and the keywords, also passes along the information 
of whether or not the subscript contents consisted of precisely a single 
expression without a trailing comma (or with one, if that'd work better... i 
believe flagging either one of these cases provides enough information to 
determine what form of argument should be passed to the single-argument 
__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/6KOU2FWQZX7YGINZYESMVDA3MJWSWWS3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to