Issue 10588: imp.find_module raises unexpected SyntaxError (original) (raw)

Issue10588

Created on 2010-11-30 09:35 by emile.anclin, last changed 2022-04-11 14:57 by admin. 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/func_unknown_encoding.py # -*- 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 "", line 1, in 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.
History
Date User Action Args
2022-04-11 14:57:09 admin set github: 54797
2013-01-25 19:31:04 brett.cannon set status: open -> closedmessages: + resolution: out of datenosy:brett.cannon, ncoghlan, vstinner, ron_adam, benjamin.peterson, eric.araujo, Arfrever, Trundle, skrah, emile.anclin
2011-09-25 19:35:03 Arfrever set nosy: + Arfrever
2011-08-10 20:23:13 benjamin.peterson set nosy: + benjamin.peterson, vstinnermessages: +
2011-08-10 18:59:31 Trundle set nosy: + Trundle
2011-08-09 22:50:23 skrah set nosy: + skrah
2010-12-05 23:58:13 eric.araujo set nosy: + brett.cannon, ncoghlan, eric.araujo
2010-11-30 15:33:30 ron_adam set nosy: + ron_adam
2010-11-30 09:35:46 emile.anclin create