[Python-Dev] Assign(expr* targets, expr value) (original) (raw)
Benjamin Peterson benjamin at python.org
Tue Nov 12 15:08:34 CET 2013
- Previous message: [Python-Dev] Assign(expr* targets, expr value) - why targetS?
- Next message: [Python-Dev] Assign(expr* targets, expr value) - why targetS?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2013/11/12 anatoly techtonik <techtonik at gmail.com>:
On Sun, Nov 10, 2013 at 8:34 AM, Benjamin Peterson <benjamin at python.org> wrote:
2013/11/10 anatoly techtonik <techtonik at gmail.com>:
http://hg.python.org/cpython/file/1ee45eb6aab9/Parser/Python.asdl
In Assign(expr* targets, expr value), why the first argument is a list? x = y = 42 Thanks. Speaking of this ASDL.
expr* targets
means that multiple entities ofexpr
under the name 'targets' can be passed to Assign statement. Assign uses them as left value. Butexpr
definition contains things that can not be used as left side assignment targets: expr = BoolOp(boolop op, expr* values) | BinOp(expr left, operator op, expr right) ... | Str(string s) -- need to specify raw, unicode, etc? | Bytes(bytes s) | NameConstant(singleton value) | Ellipsis -- the following expression can appear in assignment context | Attribute(expr value, identifier attr, exprcontext ctx) | Subscript(expr value, slice slice, exprcontext ctx) | Starred(expr value, exprcontext ctx) | Name(identifier id, exprcontext ctx) | List(expr* elts, exprcontext ctx) | Tuple(expr* elts, exprcontext ctx) If I understand correctly, this is compiled into C struct definitions (Python-ast.c), and there is a code to traverse the structure, but where is code that validates that the structure is correct? Is it done on the first level - text file parsing, before ASDL is built? If so, then what is the role of this ADSL exactly that the first step is unable to solve?
Only valid expression targets are allowed during AST construction. See set_expr_context in ast.c.
Is it possible to fix ADSL to move
expr
that are allowed in Assign intoexpr
subset? What effect will it achieve? I mean - will ADSL compiler complain about wrong stuff on the left side, or it will still be a role of some other component. Which one?
I'm not sure what you mean by an expr
subset.
-- Regards, Benjamin
- Previous message: [Python-Dev] Assign(expr* targets, expr value) - why targetS?
- Next message: [Python-Dev] Assign(expr* targets, expr value) - why targetS?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]