Suggested feature: slice syntax within tuples (or even more generally)?

stephenwlin at gmail.com stephenwlin at gmail.com
Thu Feb 14 23:01:39 CET 2013


On Thursday, February 14, 2013 1:58:06 PM UTC-5, Ian wrote:
> 
> That's not ambiguous, because the former is simply invalid syntax.
> 
> However, consider the following.
> 
> 
> 
> if 1: 2:
> 
> 
> 
> That could be either a one-line if statement where the condition is 1
> 
> and the body is slice(2, None), or it could be the beginning of a
> 
> multi-line if block where the condition is slice(1, 2).  If the parser
> 
> sees that, should it expect the next line to be indented or not?  If
> 
> it relies on indentation to determine this, then it loses some ability
> 
> to warn the user of incorrect indentation.
> 
> 
> 
> Then we have dictionary literals:
> 
> 
> 
> {1:2:3}
> 
> 
> 
> Should that be read as dict([(slice(1, 2), 3)]) or dict([(1, slice(2,
> 
> 3))])?  Or even set([slice(1, 2, 3)])?
>

Restricting this to within the top level of ()-enclosed expressions would be sufficient to eliminate all ambiguities, though, right? Basically all that needs to change is for expressions within '()' to be parsed identically as are currently parsed in '[]'.

-Stephen




More information about the Python-list mailing list