This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Minor AST tweaks
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.2
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, benjamin.peterson, collinwinter, georg.brandl, jhylton, loewis
Priority: normal Keywords: patch

Created on 2007-02-14 00:44 by collinwinter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ast.patch collinwinter, 2007-02-14 00:44 Some tweaks to make working with the AST easier
Messages (6)
msg51870 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-02-14 00:44
This patch implements these changes, as discussed in http://mail.python.org/pipermail/python-dev/2007-February/071006.html and following.

"""
1) There are times when the _fields attribute on some AST nodes is None; if this was done to indicate that a given node has no AST-related attributes, it would be much easier if _fields was [] in this case. As it is, I had to special-case "node._fields is None" in the visitor so that I don't accidentally iterate over it.
"""

asdl_c.py is changed to always set _fields to a tuple.

"""
2) {BinOp,AugAssign,BoolOp,etc}.op is an instance of, eg, Add, Sub, Mult, Mod, meaning you have to dispatch based on tests like "isinstance(node.op, x)" or "type(node.op) is x". I would much, much prefer to spell this "node.op is x", ie, use "node.op = Add" rather than the current "node.op = Add()" when constructing the nodes.
"""

asdl_c.py is changed so that it no longer emits the *_singleton objects and uses the corresponding *_type objects in their place.

"""
3) I'd like there to be an Else() node for If.orelse, While.orelse, etc. My motivation is that I need the lineno and col_offset values of the "else" statement for a code-coverage utility; as it is, I have to find the last lineno of the if/while/etc suite and the first lineno of the "else" suite and then search between those two for the "else" statement.
"""

An Else node is added to the ASDL file, impacting TryExcept, While, For and If nodes. The compiler, symtable and other files are adjusted to deal with these new nodes.

The patch is against r53772.
msg51871 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-02-14 09:00
Please minimize white-space only changes in the patch. It makes it harder to read (symtable.c in particular).
msg51872 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-02-17 08:17
Please also update Demo/parser/unparse.py to match your changes.
msg85487 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-05 13:11
Note that change #1 is already implemented as of r62051.
msg110521 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-16 22:40
Collin, are you in a position where you could take this issue forward?
msg110554 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-07-17 13:47
I'm going to close this because these are mostly incompatible changes that are too late.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44581
2010-07-17 13:47:39benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg110554

resolution: rejected
2010-07-16 22:40:22BreamoreBoysetnosy: + BreamoreBoy

messages: + msg110521
versions: + Python 3.2, - Python 3.1, Python 2.7
2009-04-05 13:11:42georg.brandlsetnosy: + georg.brandl
messages: + msg85487
2009-03-31 13:36:00jhyltonsetnosy: + jhylton
2009-03-30 21:25:12ajaksu2setstage: patch review
type: enhancement
versions: + Python 3.1, Python 2.7, - Python 2.6
2007-02-14 00:44:45collinwintercreate