[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public
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

Merged

Conversation

Copy link
Member

serhiy-storchaka commented Jul 9, 2017

instead of failing with SystemError.

Relative import from non-package now fails with ImportError rather than
SystemError.

…ckage

instead of failing with SystemError.

Relative import from non-package now fails with ImportError rather than
SystemError.
Copy link

mention-bot commented Jul 9, 2017

@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.

Copy link
Contributor

ncoghlan left a comment

Actual changes look good to me, but I believe the NEWS snippet can go in Misc/NEWS.d now

Misc/NEWS Outdated
@@ -10,6 +10,10 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------

- bpo-30876: Relative import from unloaded package now reimports the package
Copy link
Contributor

ncoghlan Jul 10, 2017

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?

Copy link
Member Author

serhiy-storchaka Jul 10, 2017

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.

Copy link
Contributor

mlouielu Jul 10, 2017

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

Copy link
Member Author

serhiy-storchaka Jul 10, 2017

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.

Copy link
Contributor

ncoghlan Jul 10, 2017

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.

Copy link
Member Author

serhiy-storchaka Jul 10, 2017

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

Copy link
Contributor

mlouielu Jul 10, 2017

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 :(

Copy link
Member

vstinner Jul 10, 2017

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 ;-))

Copy link
Member Author

serhiy-storchaka commented Jul 10, 2017

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?

Copy link
Member

brettcannon commented Jul 10, 2017

@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.

Copy link
Member

brettcannon left a comment

Just asking for some changes to use utility code to make test cleanup easier. Otherwise the solution is surprisingly simple. 😄

try:
import package2.submodule1
package2.submodule1.submodule2
finally:
Copy link
Member

brettcannon Jul 10, 2017

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.

Copy link
Member Author

serhiy-storchaka Jul 11, 2017

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?

import submodule1
self.assertNotIn('submodule1', sys.modules)
self.assertNotIn('submodule2', sys.modules)
finally:
Copy link
Member

brettcannon Jul 10, 2017

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.

serhiy-storchaka merged commit 8a9cd20 into python:master Jul 12, 2017
serhiy-storchaka deleted the import-from-unknown-package branch Jul 12, 2017
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jul 12, 2017
…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)
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jul 12, 2017
…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)
serhiy-storchaka added a commit that referenced this pull request Jul 16, 2017
…the package (GH-2639) (#2676)

instead of failing with SystemError.

Relative import from non-package now fails with ImportError rather than
SystemError.
(cherry picked from commit 8a9cd20)
serhiy-storchaka added a commit that referenced this pull request Jul 23, 2017
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants