A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-August/103134.html below:

[Python-Dev] Oddity in AST for 3-argument slices

[Python-Dev] Oddity in AST for 3-argument slicesGreg Ewing greg.ewing at canterbury.ac.nz
Thu Aug 19 10:36:54 CEST 2010
I've discovered a slightly surprising thing about the way
AST objects for slices are constructed. According to
Python.asdl, all three parts of a slice are optional:

    slice = Slice(expr? lower, expr? upper, expr? step)

But that's not quite the way the parser sees things:

Python 3.1.2 (r312:79147, Aug 19 2010, 20:26:20)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import ast
 >>> t = ast.parse("x[::]", mode='eval')
 >>> ast.dump(t)
"Expression(body=Subscript(value=Name(id='x', ctx=Load()), 
slice=Slice(lower=None, upper=None, step=Name(id='None', ctx=Load())), ctx=Load()))"

In other words,

    x[::]

is being parsed as though it had been written

    x[::None]

Is there a good reason for an omitted third slice
argument being treated differently from the others?

-- 
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4