I think there are a couple of related bugs here, with open reports:
1. Issue 14285: runpy catches various exceptions including AttributeError, and incorrectly assumes this means you gave it a bad module or package name.
2. Issue 19771: runpy incorrectly interprets exceptions such as in (1) as meaning the package doesn’t have a __main__ submodule. But these exceptions can happen even if hello.__main__ exists. My patch there changes the error message to:
/home/proj/python/cpython/python: Error while finding spec for 'hello.__main__' (AttributeError: module 'random' has no attribute 'dsgjdgj')
3. Issue 16217: runpy should handle exceptions from user code by printing out the relevant traceback, rather than letting the Python interpreter print out all the internal runpy frames.
Marking this as a dupe of Issue 14285, but I think a proper solution to that would probably affect the other two as well. |