[Python-Dev] python3k : imp.find_module raises SyntaxError

Emile Anclin emile.anclin at logilab.fr
Thu Nov 25 15:30:23 CET 2010


hello,

working on Pylint, we have a lot of voluntary corrupted files to test 
Pylint behavior; for instance 
 
$ cat /home/emile/var/pylint/test/input/func_unknown_encoding.py 
# -*- coding: IBO-8859-1 -*-
""" check correct unknown encoding declaration
"""

__revision__ = 'éééé'


and we try to find that module :
find_module('func_unknown_encoding', None). But python3 raises SyntaxError 
in that case ; it didn't raise SyntaxError on python2 nor does so on our 
func_nonascii_noencoding and func_wrong_encoding modules (with obvious 
names)

Python 3.2a2 (r32a2:84522, Sep 14 2010, 15:22:36) 
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from imp import find_module
>>> find_module('func_unknown_encoding', None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SyntaxError: encoding problem: with BOM
>>> find_module('func_wrong_encoding', None)
(<_io.TextIOWrapper name=5 encoding='utf-8'>, 'func_wrong_encoding.py', 
('.py', 'U', 1))
>>> find_module('func_nonascii_noencoding', None)
(<_io.TextIOWrapper name=6 encoding='utf-8'>, 
'func_nonascii_noencoding.py', ('.py', 'U', 1))


So what is the reason of this selective behavior?
Furthermore, there is BOM in our func_unknown_encoding.py module.

-- 

Emile Anclin <emile.anclin at logilab.fr>
http://www.logilab.fr/   http://www.logilab.org/ 
Informatique scientifique & et gestion de connaissances


More information about the Python-Dev mailing list