Hello, 2006/6/10, Nick Coghlan <[EMAIL PROTECTED]>: > The closest parallel would be with return/yield, as those actually create real > tuples the same way subscripts do, and allow the expression to be omitted > entirely. > > By that parallel, however, an implicit subscript (if adopted) should be None > rather than (). > > Adapting the table from the pre-PEP to describe return statements (and yield > expressions): > > return i, j, k <--> return (i, j, k) > return i, j <--> return (i, j) > return i, <--> return (i, ) > return i <--> return (i) > return () # (No implicit equivalent) > return <--> return None > > With the status quo, however, subscripts are simply equivalent to the RHS of > an assignment statement in *requiring* that the expression be non-empty: > > x = i, j, k <--> x = (i, j, k) > x = i, j <--> x = (i, j) > x = i, <--> x = (i, ) > x = i <--> x = (i) > x = () # (No implicit equivalent) > x = None # (No implicit equivalent) > > The PEP doesn't make a sufficiently compelling case for introducing > yet-another-variant on the implicit behaviour invoked when a particular > subexpression is missing from a construct. > I hope that my (hopefully) better explanation made the use case more compelling, but I want to add two points in favour of an empty tuple:
1. If you want, you can ignore the x[(i, j, k)] equivalence completely, since it doesn't work all the times - for example, you can write "x[1:2, 3:4]", but you can't write "x[(1:2, 3:4)]". You can think of x[i, j, k] as a syntax for specifying a cell in a 3-dimensional array, resulting in a call to x.__getitem__ with a 3-tuple describing the subscript for each dimension. In that view, "x[]", which is a syntax for specifying the cell of a 0-dimensional, should result in a __getitem__ call with an empty tuple, as there are no subscripts to be described. 2. My equivalencies are better than yours :-), since they are dealing with equivalencies for this specific syntax, while yours are dealing with similar properies of a syntax for doing something completely different. > I guess I could have gone with my initial instinct of -1 and saved myself some > mental exercise ;) Why? Mental exercise is a good way to keep you mental ;) Noam _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com