[pypy-issue] [issue1728] compile() mutates its argument

Bogdan Opanchuk tracker at bugs.pypy.org
Mon Apr 7 03:12:35 CEST 2014


New submission from Bogdan Opanchuk <mantihor at gmail.com>:

Tested in PyPy 2.2.1

The following code:

    import ast
    tree = ast.parse("a = None")
    print(ast.dump(tree))
    compile(tree, '<nofile>', 'exec')
    print(ast.dump(tree))

produced the following output:

    Module(body=[Assign(targets=[Name(id='a', ctx=Store())],
value=Name(id='None', ctx=Load()))])
    Module(body=[Assign(targets=[Name(id='a', ctx=Store())],
value=Const(value=None))])

Apparently, compile() mutated the `tree` argument (adding the `Const` node which
is, incidentally, not even present in
http://docs.python.org/2/library/ast.html#abstract-grammar). The same code in
CPython 2.7.6 or 3.4.0 does not change `tree`. The documentation for `compile()`
does not indicate that the `tree` argument may be changed.

----------
messages: 6682
nosy: bogdan, pypy-issue
priority: bug
release: 2.2
status: unread
title: compile() mutates its argument

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1728>
________________________________________


More information about the pypy-issue mailing list