bpo-43299: Make pyclbr.readmodule_ex() not die on module w/o __spec__#24623
bpo-43299: Make pyclbr.readmodule_ex() not die on module w/o __spec__#24623kxrob wants to merge 1 commit intopython:mainfrom
Conversation
pyclbr.readmodule_ex() should not die when traversing an "import __main__" statement or an import of another module without __spec__ attribute.
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
|
This PR is stale because it has been open for 30 days with no activity. |
|
Is there a chance this bug can be solved? @vstinner |
| try: spec = importlib.util._find_spec_from_path(fullmodule, search_path) | ||
| except ValueError: | ||
| # ValueError: __main__.__spec__ is None / is not set | ||
| spec = None |
There was a problem hiding this comment.
It looks like this would just lead to ModuleNotFoundError below, which seems misleading because module does exist. Is ModuleNotFoundError caught somewhere and pyclbr proceeds to next module? Did you test if this change fixes the reported bug?
There was a problem hiding this comment.
The change from ValueError to an ImportError (subclass) makes it to be processed reasonable (skip to next) in the caller https://github.com/python/cpython/blob/3.10/Lib/pyclbr.py#L243 / visit_Import() in the call stack shown by the trace in bpo 43299 (2 levels higher). And solves the bug in that case at least - and similar in other callers of _readmodule()
In that case the module (main) can indeed not be found in the filesystem for parsing. regular modules have a spec. Raising an ImportError with extra specific text could be another option.


pyclbr.readmodule_ex() should not die when traversing
an "import main" statement or an import of another
module without spec attribute.
https://bugs.python.org/issue43299
https://bugs.python.org/issue43299