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

Amaury Forgeot d'Arc report at bugs.python.org
Tue Dec 30 15:37:19 CET 2008


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

Issue4742 is similar issue:

>>> source = b"# coding=cp1252\n\x94 = '\x94'".decode('cp1252')
>>> compile(source, '<test>', 'exec')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<test>", line 0
SyntaxError: unknown encoding: cp1252

The real error here is masked; just before the exception is set, there
is a pending
SyntaxError: 'charmap' codec can't decode byte 0x9d in position 18:
character maps to <undefined>

It seems that the source internal representation is correct utf-8, but
this is decoded again with the "coding=" cookie.

----------
nosy: +amaury.forgeotdarc

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


More information about the Python-bugs-list mailing list