[Python-Dev] Recent experience with the _ast module

"Martin v. Löwis" martin at v.loewis.de
Wed Feb 14 10:20:07 CET 2007


Collin Winter schrieb:
> 2) It turned out that {BinOp, BoolOp,AugAssign,etc}.op were already
> singleton instances of their respective classes. I've changed
> asdl_c.py to no longer emit the *_singleton names and to use the
> corresponding *_type types in their place, which will enable me to
> write "node.op is _ast.Add", etc.

I don't really like this - it's inconsistent. I'd rather prefer
if the singletons where exposed under a name, e.g.
_ast.Add.singleton, or _ast.add (if that doesn't cause conflicts).

> 3) Adding an Else node was a little more involved, but it proved
> do-able. TryFinally.orelse, While.orelse, For.orelse and If.orelse can
> now be either None or an instance of Else. Else instances have a
> 'body' attribute, which is a sequence of statements.

I still can't see the need (we don't have line numbers for every
token in the AST), but I can't see anything wrong with it, either
(except for the change in the structure, of course, but that will
  happen, anyway).

Regards,
Martin



More information about the Python-Dev mailing list