On 2021-08-13 at 23:18:29 +1100, Matsuoka Takuo <motogeom...@gmail.com> wrote:
> Given a subscriptable object s, the intended rule for the notation for > getting an item of s seems that, for any expression {e}, such as > "x, ", > s[{e}] > (i.e., s[x, ] if {e} is "x, ") means the same as > s[({e})] If e is an expression, then s[e] means s[e]. Sometimes, e happens to be a tuple, but Python doesn't create a tuple just to call __getitem__. The following expression: x, is a tuple all by itself. Also: (x,) is that same tuple. > (i.e., s[(x, )] in the considered case), namely, should be evaluated > as s.__getitem__(({e})) (or s.__class_getitem__(({e})) when that > applies). If this is the rule, then it looks simple and hence > friendly to the user. However, there are at least two exceptions: > > (1) The case where {e} is the empty expression "": There is no such thing as an "empty expression." "" is a string containing no characters. > The expression > s[] > raises SyntaxError ... Because there is no expression (which is different from a hypothetical "empty expression." > ... instead of being evaluated in the same way as > s[()] is. () is a tuple with no elements, just as [] is a list with no elements, and "" is a string with no elements. _______________________________________________ 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/ZCSPKRQMVJ5RCR4WD62QIGLPYPJOFE4P/ Code of Conduct: http://python.org/psf/codeofconduct/