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

Janosch Gräf report at bugs.python.org
Sun Nov 20 01:04:39 CET 2011


New submission from Janosch Gräf <janosch.graef at 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 at python
components: Documentation, Interpreter Core
messages: 147972
nosy: Janosch.Gräf, docs at 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 at bugs.python.org>
<http://bugs.python.org/issue13436>
_______________________________________


More information about the Python-bugs-list mailing list