Ugh. It is becoming gradually clear to me that obj[] should be a syntax error. We should definitely not indulge in obj[-] or {-}.
On Mon, Aug 17, 2020 at 11:41 AM Jonathan Fine <jfine2...@gmail.com> wrote: > Here's a few words on whether we should allow and whether we can forbid: > >>> something[] > > First, in > >>> something[x=1] > what I call the argv is empty, as it is with > >>> something[] > > If we represent an empty argv by passing the empty tuple () to > __getitem__, then how are > >>> something[(), x=1] > >>> something[x=1] > to be distinguished from each other? Or perhaps they shouldn't be. > > Next, if > >>> something[*argv] > is allowed, then what was a syntax error becomes a run-time error. Put > another way, an optimising compiler might want to raise syntax error for > >>> something[*()] > although I think that would be wrong. Compare with > >>> 1 if True else 1 / 0 > 1 > as its possible that something[*()] won't be called. > > Finally, even if we forbid > >>> something[*argv] > in order to prevent the empty key, the door is still open. We can use > >>> something[**dict()] > to access something with the empty key (assuming ** arguments are allowed). > > And one more thing. There's rightly a strong association between [] and an > empty list literal. To my mind, this makes > >>> d[] > look very odd. We're expecting something, but there's nothing there. > Perhaps > >>> d[-] > would work better for signifying an empty key. Here, '[-]' is a special > syntactic token. > > Aside: Consistent with this, we could use > >>> {-} > for the empty set literal. At present the closest we can do for an empty > set literal is > >>> {0} - {0} > set() > > I hope all this helps. > > -- > Jonathan > _______________________________________________ > 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/QOBONXUPUMC3ULCGJU6FVHOCIZQDT45W/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --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/VPAKH2DD3JN5QHD3D4UCGGQQFUNBU67W/ Code of Conduct: http://python.org/psf/codeofconduct/