-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modulefinder fails if module contains syntax error #61598
Comments
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_
else:
from .exec_py3 import exec_ I attached a patch which changes the code to catch potential SyntaxError exceptions and change them to an ImportError. |
Thanks for the report and patch. Could you add a test? I’m not sure where this sits on the bug vs. feature line. |
Could you point me to some documentation on how to add a test? I have not been involved in Python development so far. |
Certainly: http://docs.python.org/devguide 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/test_modulefinder.py 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). |
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. |
Here is an updated patch, also containing a test. |
It's based on the default branch becoming 3.4. |
Fixed for Python 3.8 via the patch for bpo-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. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: