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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/QOBONXUPUMC3ULCGJU6FVHOCIZQDT45W/
Code of Conduct: http://python.org/psf/codeofconduct/