[New-bugs-announce] [issue19942] UTF-8 encoding not enforced

Jakub Wilk report at bugs.python.org
Tue Dec 10 12:48:59 CET 2013


New submission from Jakub Wilk:

I created a Python file which contained a non-UTF-8 string literal (but no Unicode literals), and added "UTF-8" encoding declaration to it. I expected that Python will raise SyntaxError when importing such module, but it doesn't:

$ python --version
Python 2.7.6

$ python -c 'import test1' && echo ok
ok


Curiously enough, if I change the declaration to "UTF8", then the exception is raised as expected:

$ sed -e 's/UTF-8/UTF8/' < test1.py > test2.py
$ python -c 'import test2'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "test2.py", line 2
SyntaxError: 'utf8' codec can't decode byte 0xa1 in position 5: invalid start byte

----------
messages: 205795
nosy: jwilk
priority: normal
severity: normal
status: open
title: UTF-8 encoding not enforced
versions: Python 2.7

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


More information about the New-bugs-announce mailing list