[issue13436] compile() doesn't work on ImportFrom with level=None

New submission from Janosch Gräf <janosch.graef@gmx.net>: The documentation for ast says that arguments that are marked with a '?' in the abstract grammar are optional and can therefore be None. When I try to compile a Module node which contains an ImportFrom node with attribute level=None compile() throws an exception: Module(body=[ImportFrom(module='time', names=[alias(name='sleep', asname=None), alias(name='time', asname=None)], level=None, lineno=0, col_offset=0)]) Traceback (most recent call last): File "g0.py", line 423, in <module> p.main() File "g0.py", line 65, in main self.reproduce("g1.pyc") File "g0.py", line 85, in reproduce co = self.generate_bytecode(st, genome) File "g0.py", line 243, in generate_bytecode co = compile(st, id, "exec") ValueError: invalid integer value: �������� So, I tried to set level=0: Module(body=[ImportFrom(module='time', names=[alias(name='sleep', asname=None), alias(name='time', asname=None)], level=0, lineno=0, col_offset=0)]) and everything worked fine. BTW: The unprintable bytes in the error message are: ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ---------- assignee: docs@python components: Documentation, Interpreter Core messages: 147972 nosy: Janosch.Gräf, docs@python priority: normal severity: normal status: open title: compile() doesn't work on ImportFrom with level=None type: behavior versions: Python 3.1 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment: Here is a patch for the bad error message (PyBytes_AS_BYTES after PyObject_Repr, bah) ---------- keywords: +patch nosy: +amaury.forgeotdarc Added file: http://bugs.python.org/file23739/issue13436.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Changes by Amaury Forgeot d'Arc <amauryfa@gmail.com>: ---------- nosy: +benjamin.peterson _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Benjamin Peterson <benjamin@python.org> added the comment: LGTM. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Changes by Benjamin Peterson <benjamin@python.org>: ---------- assignee: docs@python -> _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment: New changeset ffcdfc534942 by Amaury Forgeot d'Arc in branch '3.2': Issue #13436: Fix a bogus error message when an AST object was passed http://hg.python.org/cpython/rev/ffcdfc534942 New changeset 470f7d7c57ce by Amaury Forgeot d'Arc in branch '3.2': Issue #13436: commit regenerated Python-ast.c http://hg.python.org/cpython/rev/470f7d7c57ce ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment: I fixed the bogus error message, but "level=None" is still not allowed, whereas the docs promise that optional values can be None. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment: New changeset 2e5506d9a079 by Victor Stinner in branch '3.2': Issue #13436: Fix unsetenv() test on Windows http://hg.python.org/cpython/rev/2e5506d9a079 New changeset 029ad97883ef by Victor Stinner in branch 'default': (Merge 3.2) Issue #13436: Fix unsetenv() test on Windows http://hg.python.org/cpython/rev/029ad97883ef New changeset e66ef9fa55de by Victor Stinner in branch '2.7': Issue #13436: Fix unsetenv() test on Windows http://hg.python.org/cpython/rev/e66ef9fa55de ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Terry J. Reedy <tjreedy@udel.edu> added the comment: Does this apply to 2.7 as well? I believe msg148146 is due to a commit message typo. ---------- nosy: +haypo, terry.reedy versions: +Python 3.2, Python 3.3 -Python 3.1 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Changes by Georg Brandl <georg@python.org>: ---------- Removed message: http://bugs.python.org/msg148146 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment: Here is a patch for the bad error message (PyBytes_AS_BYTES after PyObject_Repr, bah) ---------- keywords: +patch nosy: +amaury.forgeotdarc Added file: http://bugs.python.org/file23739/issue13436.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Changes by Amaury Forgeot d'Arc <amauryfa@gmail.com>: ---------- nosy: +benjamin.peterson _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Benjamin Peterson <benjamin@python.org> added the comment: LGTM. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Changes by Benjamin Peterson <benjamin@python.org>: ---------- assignee: docs@python -> _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment: New changeset ffcdfc534942 by Amaury Forgeot d'Arc in branch '3.2': Issue #13436: Fix a bogus error message when an AST object was passed http://hg.python.org/cpython/rev/ffcdfc534942 New changeset 470f7d7c57ce by Amaury Forgeot d'Arc in branch '3.2': Issue #13436: commit regenerated Python-ast.c http://hg.python.org/cpython/rev/470f7d7c57ce ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment: I fixed the bogus error message, but "level=None" is still not allowed, whereas the docs promise that optional values can be None. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment: New changeset 2e5506d9a079 by Victor Stinner in branch '3.2': Issue #13436: Fix unsetenv() test on Windows http://hg.python.org/cpython/rev/2e5506d9a079 New changeset 029ad97883ef by Victor Stinner in branch 'default': (Merge 3.2) Issue #13436: Fix unsetenv() test on Windows http://hg.python.org/cpython/rev/029ad97883ef New changeset e66ef9fa55de by Victor Stinner in branch '2.7': Issue #13436: Fix unsetenv() test on Windows http://hg.python.org/cpython/rev/e66ef9fa55de ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Terry J. Reedy <tjreedy@udel.edu> added the comment: Does this apply to 2.7 as well? I believe msg148146 is due to a commit message typo. ---------- nosy: +haypo, terry.reedy versions: +Python 3.2, Python 3.3 -Python 3.1 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________

Changes by Georg Brandl <georg@python.org>: ---------- Removed message: http://bugs.python.org/msg148146 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13436> _______________________________________
participants (6)
-
Amaury Forgeot d'Arc
-
Benjamin Peterson
-
Georg Brandl
-
Janosch Gräf
-
Roundup Robot
-
Terry J. Reedy