Suggested feature: slice syntax within tuples (or even more generally)?
ian.g.kelly at gmail.com
Thu Feb 14 19:58:06 CET 2013
On Thu, Feb 14, 2013 at 1:03 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> if x:
> Is that intended as "if slice(x, None, None)" with a missing colon, or
> "if x" with colon supplied?
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:
Should that be read as dict([(slice(1, 2), 3)]) or dict([(1, slice(2,
3))])? Or even set([slice(1, 2, 3)])?
More information about the Python-list