-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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-21720: Restore the Python 2.7 logic in handling a fromlist. #4118
bpo-21720: Restore the Python 2.7 logic in handling a fromlist. #4118
Conversation
BytesWarning no longer emitted when the fromlist argument of __import__() or the __all__ attribute of the module contain bytes instances.
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.
A couple minor things, but all stuff I trust you to be able to handle, Serhiy. 😄
Lib/importlib/_bootstrap.py
Outdated
if x == '*': | ||
if not recursive and hasattr(module, '__all__'): | ||
_handle_fromlist(module, module.__all__, import_, True) | ||
|
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.
Extraneous blank line.
Lib/importlib/_bootstrap.py
Outdated
where = "``from list''" | ||
raise TypeError(f"Item in {where} must be str, " | ||
f"not {type(x).__name__}") | ||
if x == '*': |
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.
elif
Lib/importlib/_bootstrap.py
Outdated
@@ -994,7 +994,7 @@ def _gcd_import(name, package=None, level=0): | |||
return _find_and_load(name, _gcd_import) | |||
|
|||
|
|||
def _handle_fromlist(module, fromlist, import_): | |||
def _handle_fromlist(module, fromlist, import_, recursive=False): |
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.
recursive
should probably be keyword-only, else it's ambiguous what _handle_fromlist(..., False)
means.
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.
LGTM too. I'll close Berker's PR in favour of this one.
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6. |
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
…pythonGH-4118) BytesWarning no longer emitted when the fromlist argument of __import__() or the __all__ attribute of the module contain bytes instances.. (cherry picked from commit 41c5694)
BytesWarning no longer emitted when the fromlist argument of
__import__()
or the__all__
attribute of the module contain bytesinstances.
https://bugs.python.org/issue21720