Message255690
| Author |
martin.panter |
| Recipients |
BreamoreBoy, eric.araujo, eric.snow, martin.panter, ncoghlan, robagar, schlamar |
| Date |
2015年12月02日.03:44:43 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1449027884.73.0.712796260194.issue14285@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Now I have a deeper understanding I think this can be handled separately to Issue 16217.
This patch pulls together my previous two patches, and adds a fix. There are two aspects of my fix:
1. Import the package before calling find_spec() on the __main__ submodule. This means exceptions raised by the initialization code can be differentiated from exceptions from find_spec().
2. Change all the special ImportError exceptions raised inside runpy [and also one raised by InspectLoader.get_code()] to an internal _Error exception known only to runpy. Now I can be sure that all _Error exceptions are not caused by the initialization code, and I can stop catching ImportError, but still catch _Error and suppress the traceback. When runpy is invoked from the documented run_module() or run_path() APIs, _Error is not used, and it still raises ImportError to maintain backwards compatibility.
I think my patch should avoid the main problem in Issue 19771 as well.
Please review my patch. There are so many error possibilities; it is hard to be sure I have got them all right. |
|