On Sun, Aug 30, 2020 at 8:44 AM Joseph Martinot-Lagarde < contreba...@gmail.com> wrote:
> Guido van Rossum wrote: > > > > Do we want to support d[**kwargs]? It can be done, alternatively we could > > just ask the user to write the __getitem__/__setitem__ call explicitly. > > I think we should say no to d[*args], because that will just become > > d[(args)], with awkward questions around what if args == (1,). Maybe then > > for consistency we needn't bother with **kwargs, though the case for that > > is definitely stronger. > > Sorry for telegraphing this -- I am way past my bedtime but looking at > this > > from the C API POV definitely made some things clear to me. I'm probably > > posting this in the wrong thread -- I can't keep up (and GMail splits > > threads after 100 messages, which doesn't help). > > I hope I understood correctly because Mailman eats the * signs for > formatting, Sorry about that. Yes, where Mailman shows `args` and following text suddenly in italics, it ate a single `*`. Until the next `args` where it ended the italics, that was another `*args`. > but is it possible (and desirable) to have a different behaviour for *args > and index when there is only one positional value ? Using "index" would > keep the current behaviour : pass a tuple except when there is only one > value, in that case the value is passes as-is. On the other hand if *args > is passed in the signature, it always gets the positional arguments in a > tuple, whatever their number. It would avoid the classical > isinstance(index, tuple) check. Here are some examples of what I mean: > > # Usual signature > class Simple: > def __getitem__(self, index): > print(index) > simple = Simple() > simple[0] # 0 > simple[0, 1] # (0, 1) > > # This is valid python, but useless ? > class Star: > def __getitem__(self, *index): > print(index) > star = Star() > star[0] # (0,) > star[0, 1] # ((0, 1),) > > # I propose this breaking change > class NewStar: > def __getitem__(self, *index): > print(index) > star = Star() > star[0] # (0,) > star[0, 1] # (0, 1) > > This is theoretically a breaking change, but who in his right mind would > write such a Star class with the current python ? > This cannot be done, because the signature of the function definition is thoroughly hidden from the call site. -- --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/>
_______________________________________________ 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/KSE4PODPQZBFZOWFC4KZONUGCS3OUU2S/ Code of Conduct: http://python.org/psf/codeofconduct/