8000 bpo-30436: Fix exception raised for invalid parent. by zvyn · Pull Request #1899 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-30436: Fix exception raised for invalid parent. #1899

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

Merged
merged 12 commits into from
Jun 14, 2017
Prev Previous commit
Next Next commit
Be very explicit in exception message
  • Loading branch information
brettcannon authored Jun 14, 2017
commit 9d9c57df2f6d2f9ef5ede39f8fc015297293d1cf
4 changes: 2 additions & 2 deletions Lib/importlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def find_spec(name, package=None):
parent_path = parent.__path__
except AttributeError as e:
raise ModuleNotFoundError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the name argument be passed?

Copy link
Contributor Author
@zvyn zvyn Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should! I'll updated the PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the AttributeError purely from the attempt to access __path__ on the imported module? If so then the __import__() call should go outside the try block to limit the scope of what will have an AttributeError caught. If there's another potential trigger of the AttributeError then we have a bigger problem. ;)

"__path__ attribute missing on parent of "
f"{fullname!r}.", name=fullname) from e
f"__path__ attribute not found on {parent_name!r}"
f"while trying to import {fullname!r}.", name=fullname) from e
else:
parent_path = None
return _find_spec(fullname, parent_path)
Expand Down
0