Skip to content
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

bpo-39336: Allow packages to not let their child modules be set on them #18006

Open
wants to merge 2 commits into
base: master
from

Conversation

@DinoV
Copy link
Contributor

DinoV commented Jan 14, 2020

This allows an import to proceed if a module raises AttributeError when attempting to set a child module on the parent package. This can occur if a loader wants to make its modules immutable, in which case the module cannot be set. In this case an ImportWarning is still logged in case this behavior is unexpected.

https://bugs.python.org/issue39336

@DinoV DinoV force-pushed the DinoV:bpo_39336_error branch 3 times, most recently from feb58e2 to 6e45545 Jan 15, 2020
DinoV and others added 2 commits Jan 14, 2020
Fix whitespace

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
@DinoV DinoV force-pushed the DinoV:bpo_39336_error branch 2 times, most recently from 6e45545 to 862b536 Jan 15, 2020
@brettcannon brettcannon self-requested a review Jan 15, 2020
try:
setattr(parent_module, child, module)
except AttributeError:
msg = (f"Can't set child package '{child}' on "

This comment has been minimized.

Copy link
@brettcannon

brettcannon Jan 15, 2020

Member
Suggested change
msg = (f"Can't set child package '{child}' on "
msg = (f"Cannot set an attribute on {parent!r} for child module {child!r}"
@@ -1339,6 +1342,39 @@ def test_circular_from_import(self):
str(cm.exception),
)

def test_unwritable_module(self):
package = inspect.cleandoc('''

This comment has been minimized.

Copy link
@brettcannon

brettcannon Jan 15, 2020

Member

Any reason to not put this as a module in test_import/data/?

@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Jan 15, 2020

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.