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

Brett Cannon report at bugs.python.org
Thu Dec 11 07:19:17 CET 2008


New submission from Brett Cannon <brett at python.org>:

When compile() is called with a string it is a reasonable assumption
that it has already been decoded. But this is not in fact the case and
leads to errors when trying to use non-ASCII identifiers::

 >>> source = "# coding=latin-1\n\u00c6 = '\u00c6'"
 >>> compile(source, '<test>', 'exec')
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<test>", line 2
     Æ = 'Æ'
        ^
 SyntaxError: invalid character in identifier
 >>> compile(source.encode('latin-1'), '<test>', 'exec')
 <code object <module> at 0x389cc8, file "<test>", line 2>

----------
components: Interpreter Core
messages: 77590
nosy: brett.cannon
severity: normal
stage: needs patch
status: open
title: compile() doesn't ignore the source encoding when a string is passed in
type: behavior
versions: Python 3.0

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


More information about the New-bugs-announce mailing list