[Patches] [ python-Patches-1659410 ] Minor AST tweaks

SourceForge.net noreply at sourceforge.net
Wed Feb 14 10:00:36 CET 2007

Patches item #1659410, was opened at 2007-02-14 01:44
Message generated for change (Comment added) made by loewis
You can respond by visiting: 

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parser/Compiler
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Collin Winter (collinwinter)
Assigned to: Nobody/Anonymous (nobody)
Summary: Minor AST tweaks

Initial Comment:
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.


>Comment By: Martin v. Löwis (loewis)
Date: 2007-02-14 10:00

Logged In: YES 
Originator: NO

Please minimize white-space only changes in the patch. It makes it harder
to read (symtable.c in particular).


You can respond by visiting: 

More information about the Patches mailing list