[Python-Dev] Two laments about CPython's AST Nodes
Frank Wierzbicki
fwierzbicki at gmail.com
Wed Aug 19 20:10:35 CEST 2009
Before I start complaining, I want to mention what a huge help it has
been to be able to directly compare the AST exposed by ast.py in
making Jython a better Python. Thanks for that!
Now on to the complaints: Though I recently added support for this in
Jython, I don't like that nodes can be defined without required
attributes, for example:
node = ast.Assign()
Is valid, even though it requires "node.targets" and "node.value" (I'm
less concerned about the required lineno and col_offset, as I can
understand holding off on these so that you can just use
fix_missing_locations to fill these in for you).
My other (bigger) gripe is that you can define these values with
arbitrary objects that will blow up at parse time. So for example you
can write:
node = ast.Assign()
node.targets = "whatever"
Which, when you try to parse, blows up with "TypeError: Assign field
"targets" must be a list, not a str". I'd be much happier if this
blew up right away when you try to make the assignment. At the
moment, this is how it works in Jython (though I could support this
with some contorting).
BTW -- I *am* volunteering to attempt to implement these things in
CPython if there is support :)
-Frank
More information about the Python-Dev
mailing list