[issue4626] compile() doesn't ignore the source encoding when a string is passed in

Jean-Michel Fauth report at bugs.python.org
Wed Mar 25 10:54:42 CET 2009


Jean-Michel Fauth <wxjmfauth at gmail.com> added the comment:

When I was preparing some test examples to be submitted here.
I noticed the module codeop.py used by the InteractiveInterpreter,
does not like byte strings very much.

IDLE, Python 3.0.1, winxp sp2

>>> source = b'print(999)'
>>> compile(source, '<in>', 'exec')
<code object <module> at 0x00AA5CC8, file "<in>", line 1>
>>> r = compile(source, '<in>', 'exec')
>>> exec(r)
999
>>> from code import InteractiveInterpreter
>>> ii = InteractiveInterpreter()
>>> ii.runsource(source)
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    ii.runsource(source)
  File "C:\Python30\lib\code.py", line 63, in runsource
    code = self.compile(source, filename, symbol)
  File "C:\Python30\lib\codeop.py", line 168, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol)
  File "C:\Python30\lib\codeop.py", line 70, in _maybe_compile
    for line in source.split("\n"):
TypeError: Type str doesn't support the buffer API
>>> 
>>> source = 'print(999)'
>>> ii.runsource(source)
999
False

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4626>
_______________________________________


More information about the Python-bugs-list mailing list