-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Changes from 1 commit
965834e
d0e8069
1697a70
c6e7851
c8438b2
6fb807e
0723016
9f2844c
9d9c57d
6819f9d
24fb8e2
f6a75fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Changes `find_spec()` to raise `ModuleNotFoundError` instead of `AttributeError` when parent does not exist or is not a package.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -522,6 +522,15 @@ def test_find_relative_module_missing_package(self): | |
self.assertNotIn(name, sorted(sys.modules)) | ||
self.assertNotIn(fullname, sorted(sys.modules)) | ||
|
||
def test_ModuleNotFoundError_raised_for_broken_module_name(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not that the name is broken, it's that someone tried to import a submodule on something that isn't a package. So a better name might be Also remove the docstring please (unittest prints that out instead of the method name in verbose mode and we prefer the former to make it easier to find the failing test, plus the formatting doesn't follow PEP 8). |
||
""" | ||
Test that calling find_spec with broken name raises ModuleNotFoundError. | ||
|
||
See issue 30436 for discussion of this behaviour. | ||
""" | ||
with self.assertRaises(ModuleNotFoundError): | ||
self.util.find_spec('module.name') | ||
|
||
|
||
(Frozen_FindSpecTests, | ||
Source_FindSpecTests | ||
|
There was a problem hiding this comment.
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?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should! I
'llupdated the PRThere was a problem hiding this comment.
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 thetry
block to limit the scope of what will have anAttributeError
caught. If there's another potential trigger of theAttributeError
then we have a bigger problem. ;)