Title: imp.find_module raises unexpected SyntaxError
Type: behavior Stage:
Components: Versions: Python 3.2
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, Trundle, benjamin.peterson, brett.cannon, emile.anclin, eric.araujo, ncoghlan, ron_adam, skrah, vstinner
Priority: normal Keywords:

Created on 2010-11-30 09:35 by emile.anclin, last changed 2013-01-25 19:31 by brett.cannon. This issue is now closed.

Messages (3)
msg122896 - (view) Author: Emile Anclin (emile.anclin) Date: 2010-11-30 09:35
Considering following file: 
$ cat pylint/test/input/ 
# -*- coding: IBO-8859-1 -*-
""" check correct unknown encoding declaration

__revision__ = 'éééé'

When we try to find that module, imp.find_module raises SyntaxError:

>>> 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

It should be considered as a bug, as stated by  Brett Cannon:

> Considering these semantics changed between Python 2 and 3 w/o a
> discernable benefit (I would consider it a negative as finding a
> module should not be impacted by syntactic correctness; the full act
> of importing should be the only thing that cares about that), I would
> consider it a bug that should be filed.
msg141883 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-08-10 20:23
The reason for this is that file_module tries to detect the encoding of the file to set the encoding for the opened file. IMO, it should just return a file in binary mode.
msg180613 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-01-25 19:31
imp.find_module() is now documented as deprecated, so changing the mode that files are opened in would change backwards-compatibility but wouldn't be worth it.
Date User Action Args
2013-01-25 19:31:04brett.cannonsetstatus: open -> closed

messages: + msg180613
resolution: out of date
nosy: brett.cannon, ncoghlan, vstinner, ron_adam, benjamin.peterson, eric.araujo, Arfrever, Trundle, skrah, emile.anclin
2011-09-25 19:35:03Arfreversetnosy: + Arfrever
2011-08-10 20:23:13benjamin.petersonsetnosy: + benjamin.peterson, vstinner
messages: + msg141883
2011-08-10 18:59:31Trundlesetnosy: + Trundle
2011-08-09 22:50:23skrahsetnosy: + skrah
2010-12-05 23:58:13eric.araujosetnosy: + brett.cannon, ncoghlan, eric.araujo
2010-11-30 15:33:30ron_adamsetnosy: + ron_adam
2010-11-30 09:35:46emile.anclincreate