-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-30876: Relative import from unloaded package now reimports the package #2639
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-30876: Relative import from unloaded package now reimports the package #2639
Conversation
…ckage instead of failing with SystemError. Relative import from non-package now fails with ImportError rather than SystemError.
|
@serhiy-storchaka, thanks for your PR! By analyzing the history of the files in this pull request, we identified @brettcannon, @pitrou and @ericsnowcurrently to be potential reviewers. |
ncoghlan
left a comment
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.
Actual changes look good to me, but I believe the NEWS snippet can go in Misc/NEWS.d now
Misc/NEWS
Outdated
| Core and Builtins | ||
| ----------------- | ||
|
|
||
| - bpo-30876: Relative import from unloaded package now reimports the package |
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 this be a file in NEWS.d now?
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.
I wait until blurb 1.0.1 become available on PyPI.
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.
@serhiy-storchaka It seems to be available on PyPi, I just download via pip.
Collecting blurb
Downloading blurb-1.0.1-py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 547kB/s
Installing collected packages: blurb
Successfully installed blurb-1.0.1
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.
What exactly command do you use? I used python3 -m pip install --user blurb and it installed blurb-1.0.
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.
If you already have a version of blurb installed, you may need --upgrade to get it to upgrade to the latest one.
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.
I first uninstalled blurb. If install blurb, the --upgrade option doesn't have any effect.
$ python3 -m pip install --user --upgrade blurb
Requirement already up-to-date: blurb in /home/serhiy/.local/lib/python3.5/site-packages
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.
I think the problem is because core-workflow add the pre-requirement on PyPI in 1.0.1 version: Requires Python: >=3.6. You can saw it at 1.0.1, since the latest version which didn't require Python 3.6 is 1.0, you will only get 1.0 on Python 3.5 :(
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.
FYI I installed blurb from source:
- clone /home/haypo/prog/python/core-workflow
- enter blurb/ directory
- install flit: sudo python3 -m pip install -U flit
- install blurb using flit: sudo python3 -m flit install
(I would also prefer to get it using pip ;-))
|
Blurb 1.0.1 works with 3.5, but requires 3.6, and blurb 1.0 requires 3.5, but works only with 3.6? |
|
@serhiy-storchaka it's all a mistake because no one updated the blurb.ini file for blurb in the PRs to add Python 3.5 support. I've now fixed it and will do an updated release sometime this week (I'll try to do it today). And just for reference this was reported in python/core-workflow#159. |
brettcannon
left a comment
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.
Just asking for some changes to use utility code to make test cleanup easier. Otherwise the solution is surprisingly simple. 😄
Lib/test/test_import/__init__.py
Outdated
| try: | ||
| import package2.submodule1 | ||
| package2.submodule1.submodule2 | ||
| finally: |
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.
All of this cleanup can be handled by the test.test_importlib.util.import_state and uncache context managers.
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.
Thank you Brett. I afraid that test.test_importlib.util.import_state does too much, I think test.support.DirsOnSysPath should be enough.
I wondering what is better, provide test files as a part of the source tree, or create them from zero in a temporary directory?
Lib/test/test_import/__init__.py
Outdated
| import submodule1 | ||
| self.assertNotIn('submodule1', sys.modules) | ||
| self.assertNotIn('submodule2', sys.modules) | ||
| finally: |
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.
Use test.test_importlib.util.import_state to manage sys.path mutations.
…the package (pythonGH-2639) instead of failing with SystemError. Relative import from non-package now fails with ImportError rather than SystemError.. (cherry picked from commit 8a9cd20)
…the package (pythonGH-2639) instead of failing with SystemError. Relative import from non-package now fails with ImportError rather than SystemError.. (cherry picked from commit 8a9cd20)
* bpo-30876: Relative import from unloaded package now reimports the package instead of failing with SystemError. Relative import from non-package now fails with ImportError rather than SystemError. (cherry picked from commit 8a9cd20) * bpo-18018: Import raises ImportError instead of SystemError if a relative import is attempted without a known parent package. * bpo-26367: importlib.__init__() raises ImportError like builtins.__import__() when ``level`` is specified but without an accompanying package specified.
instead of failing with SystemError.
Relative import from non-package now fails with ImportError rather than
SystemError.