diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-09-11 12:50:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-11 12:50:14 (GMT) |
commit | f3480ad08823a9bc7df490bb5b54593d9483be70 (patch) | |
tree | c363234083d19fc33c159670882033ffc41fb082 /Lib/test/test_source_encoding.py | |
parent | aca878ecf18b9e915e9b551f095a550b5c6e9bc5 (diff) | |
download | cpython-f3480ad08823a9bc7df490bb5b54593d9483be70.zip cpython-f3480ad08823a9bc7df490bb5b54593d9483be70.tar.gz cpython-f3480ad08823a9bc7df490bb5b54593d9483be70.tar.bz2 |
[3.8] bpo-37409: fix relative import with no parent (GH-14956) (GH-15913)
Relative imports use resolve_name to get the absolute target name,
which first seeks the current module's absolute package name from the globals:
If __package__ (and __spec__.parent) are missing then
import uses __name__, truncating the last segment if
the module is a submodule rather than a package __init__.py
(which it guesses from whether __path__ is defined).
The __name__ attempt should fail if there is no parent package (top level modules),
if __name__ is '__main__' (-m entry points), or both (scripts).
That is, if both __name__ has no subcomponents and the module does not seem
to be a package __init__ module then import should fail..
(cherry picked from commit 92420b3e679959a7d0ce875875601a4cee45231e)
Co-authored-by: Ben Lewis <benjimin@users.noreply.github.com>
(cherry picked from commit 0a6693a469cfb1dd5c8048d8cb4231a7b5883251)
Co-authored-by: Brett Cannon <54418+brettcannon@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_source_encoding.py')
0 files changed, 0 insertions, 0 deletions