On Sun, Aug 30, 2020 at 4:58 PM Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> On 31/08/20 3:37 am, Guido van Rossum wrote: > > I recall a law from evolutionary biology that went something like “once > > a feature is gone it won’t evolve a second time (in the same species)”. > > I have no interest in restoring argument unpacking. > > That can't be an absolute law. If a species loses a feature, it's > because the environment has changed so as to make it no longer > advantageous. If there is another environmental change that makes > it advantageous again, I can't see why it couldn't come back. > Maybe not exactly the same, but something very similar. > I'm sure it's not an absolute law. But it's an apt observation. > Here we have a situation where the environment has changed. I'd > like to propose bringing back something that is superficially > similar, but with some differences. > > def __getitem__(self, (i, j, k)): > > The differences are: > > 1. There can only be one set of parens, and they must enclose all > except the first positional argument. > > 2. Arguments within the parens can be specified by keyword. > How would this even work? Can I write a.__getitem__((1, 2), k=3) and the function will see (i, j, k) == (1, 2, 3)? Okay, and if I write a.__getitem__((1, 3), k=2) will the function see the same thing? I've got the feeling you're pranking me here, and I'm falling for it hook, line and sinker. > Difference 2 is what makes this more than just syntactic sugar > for taking one argument and unpacking it later, which was the > reason for eliminating argument unpacking originally. > > If you're worried about people abusing this for purposes other > than the one intended, another restriction could be added: > > 3. (Optional) It can only be used in functions named > __getitem__, __setitem__ or __delitem__. > Let's define a decorator or other helper to do this instead. -- --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/P27D5S73VKM42G6FGWM2VTAK6SLRUZJ5/ Code of Conduct: http://python.org/psf/codeofconduct/