Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def test_import(self):
self.assertRaises(TypeError, __import__, 1, 2, 3, 4)
self.assertRaises(ValueError, __import__, '')
self.assertRaises(TypeError, __import__, 'sys', name='sys')
# relative import with no parent package, issue37409
self.assertRaises(ImportError, __import__, '',
{'__package__': None, '__name__': '__main__'},
{}, ('foo',), 1)
# embedded null character
self.assertRaises(ModuleNotFoundError, __import__, 'string\x00')

Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,17 @@ def check_relative():
ns = dict(__package__=object())
self.assertRaises(TypeError, check_relative)

def test_import_from_beyond_toplevel(self):
# Regression test for https://bugs.python.org/issue37444
with self.assertRaises(ImportError):
from .......... import foo

@cpython_only
def test_import_shadowed_by_global(self):
# Regression test for https://bugs.python.org/issue37409
assert subprocess.call([sys.executable, '-c',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using test.support.script_helper.assert_python_ok seems like a better choice.

def test_import_shadowed_by_global(self):
    with temp_dir() as path:
        source = "foo = 'x'; from . import foo"
        script = script_helper.make_script(path, "bar.py", source)
        script_helper.assert_python_ok(script)

"foo = 'x'; from . import foo"])

def test_absolute_import_without_future(self):
# If explicit relative import syntax is used, then do not try
# to perform an absolute import in the face of failure.
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ Alain Leufroy
Mark Levinson
Mark Levitt
Ivan Levkivskyi
Ben Lewis
William Lewis
Akira Li
Robert Li
Expand Down