This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: modulefinder fails if module contains syntax error
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, brett.cannon, eric.araujo, eric.snow, flox, jgosmann, ncoghlan, r.david.murray
Priority: normal Keywords: patch

Created on 2013-03-11 12:03 by jgosmann, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
fix-handling-of-syntax-errors.diff jgosmann, 2013-03-11 12:03 Reraise SyntaxError as ImportError if imported module code cannot be compiled
fix-handling-of-syntax-errors.diff jgosmann, 2013-05-12 20:18 Reraise SyntaxError as ImportError if imported module code cannot be compiled review
Pull Requests
URL Status Linked Edit
PR 11787 merged brandtbucher, 2019-02-08 03:23
PR 11787 merged brandtbucher, 2019-02-08 03:23
PR 11787 merged brandtbucher, 2019-02-08 03:24
PR 11787 merged brandtbucher, 2019-02-08 03:24
Messages (8)
msg183953 - (view) Author: Jan Gosmann (jgosmann) * Date: 2013-03-11 12:03
Running modulefinder.ModuleFinder.run_script on a script which has an import statement with a module containing a syntax error will raise a SyntaxError exception. I think, modulefinder should instead continue its analysis and add the module to badmodules. Especially, as there are valid reasons for importing modules with syntax errors like in the following code snippet

if not python3:
    from .exec_py2 import exec_
    from .exec_py3 import exec_

I attached a patch which changes the code to catch potential SyntaxError exceptions and change them to an ImportError.
msg187938 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-04-27 21:42
Thanks for the report and patch.  Could you add a test?

I’m not sure where this sits on the bug vs. feature line.
msg187941 - (view) Author: Jan Gosmann (jgosmann) * Date: 2013-04-27 22:03
Could you point me to some documentation on how to add a test? I have not been involved in Python development so far.
msg187960 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-04-28 04:19
Certainly: contains information to get the source code, describes the files layout and explains how to generate a patch.  You’ll find existing unit tests in Lib/test/

Feel free to ask any question you might have on this bug, or if you prefer on the friendly core-mentorship mailing list (where I am).
msg187961 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-04-28 04:20
I would recommend that you base your patch on the default branch, i.e. what will become Python 3.4.  If we judge that this is not a new feature but actually a bug fix, the core developer who commits the patch will take care of backporting it to 2.7 and 3.3.
msg189059 - (view) Author: Jan Gosmann (jgosmann) * Date: 2013-05-12 20:18
Here is an updated patch, also containing a test.
msg189060 - (view) Author: Jan Gosmann (jgosmann) * Date: 2013-05-12 20:19
It's based on the default branch becoming 3.4.
msg339562 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2019-04-07 08:06
Fixed for Python 3.8 via the patch for #35936. We won't be backporting that patch as it also migrates modulefinder from the deprecated imp API to support importlib one, and is hence considered overly intrusive for a bug fix release.
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61598
2019-04-07 08:06:01ncoghlansetstatus: open -> closed
versions: + Python 3.8, - Python 3.4, Python 3.5
messages: + msg339562

resolution: fixed
stage: patch review -> resolved
2019-02-08 03:24:32brandtbuchersetpull_requests: + pull_request11784
2019-02-08 03:24:20brandtbuchersetpull_requests: + pull_request11783
2019-02-08 03:24:09brandtbuchersetpull_requests: + pull_request11782
2019-02-08 03:23:58brandtbuchersetpull_requests: + pull_request11781
2014-09-01 10:28:17berker.peksagsetnosy: + berker.peksag
stage: patch review
type: behavior

versions: + Python 3.5
2013-05-12 20:19:21jgosmannsetmessages: + msg189060
versions: + Python 3.4, - Python 2.7
2013-05-12 20:18:17jgosmannsetfiles: + fix-handling-of-syntax-errors.diff

messages: + msg189059
2013-04-28 04:20:51eric.araujosetnosy: + brett.cannon, ncoghlan, eric.snow
messages: + msg187961
2013-04-28 04:19:07eric.araujosetmessages: + msg187960
2013-04-27 22:06:16floxsetnosy: + flox
2013-04-27 22:03:29jgosmannsetmessages: + msg187941
2013-04-27 21:42:02eric.araujosetnosy: + r.david.murray, eric.araujo
messages: + msg187938
2013-03-11 12:03:45jgosmanncreate