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, 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 ? Any thoughts ? _______________________________________________ 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/HYGUIAYR5OGACHUHOIXN22YJWFMCE7IG/ Code of Conduct: http://python.org/psf/codeofconduct/