From ac9f875e6ca257aca627d90ecb3eef4bdef4e638 Mon Sep 17 00:00:00 2001 From: Ben Lewis Date: Sat, 29 Jun 2019 23:57:16 +1000 Subject: [PATCH] Regression tests for issue37409 and issue37444 --- Lib/test/test_builtin.py | 4 ++++ Lib/test/test_import/__init__.py | 11 +++++++++++ Misc/ACKS | 1 + 3 files changed, 16 insertions(+) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 61155799c44a92a..3f473741401352c 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -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') diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 84cd0da94b36bff..0542d0c0269aa58 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -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', + "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. diff --git a/Misc/ACKS b/Misc/ACKS index df0810fff46cc62..2072ecf866d2ee4 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -964,6 +964,7 @@ Alain Leufroy Mark Levinson Mark Levitt Ivan Levkivskyi +Ben Lewis William Lewis Akira Li Robert Li