On Sun, Aug 16, 2020 at 12:07:47PM -0700, Guido van Rossum wrote:
So I probably would be okay with allowing `obj` syntactically, as long as the dict type could be made to reject it.
I don't absolutely hate the idea, but I do feel that it's semantically rather dubious. `obj` with no subscript is just `obj`. It's not like an empty list, or string, so I'm still going to argue that there should be *something* in the subscript. Writing `obj` is, in my opinion, more likely to be an error than an intentional "subscript the default index".
But if we did allow empty subscripts syntactically, surely they would only be valid if the `__getitem__` method defines a default?
def __getitem__(self, index="right here"):
Otherwise we should get a TypeError.
The same would apply to subscript assignment:
obj = value
would only be allowed if the object defined setitem with a default for the index. Otherwise it would be a TypeError.
In any case, we could punt on this and leave the empty subscript question for another day:
Now is better than never. Although never is often better than *right* now.
I would hate for the keyword question to be derailed because we can't reach a consensus on what empty subscripts mean.