diff options
author | Filipe Laíns <lains@riseup.net> | 2021-07-24 09:50:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-24 09:50:17 (GMT) |
commit | 8072a1181dd64135f700b44372fbf7bf91e68072 (patch) | |
tree | 23ba5f22841e1f5a739d6d6d54ee0f29e094f997 /Lib/test/test_import | |
parent | 5370f0a82aaa4ba617070d5c71d2b18236096ac0 (diff) | |
download | cpython-8072a1181dd64135f700b44372fbf7bf91e68072.zip cpython-8072a1181dd64135f700b44372fbf7bf91e68072.tar.gz cpython-8072a1181dd64135f700b44372fbf7bf91e68072.tar.bz2 |
bpo-44717: improve AttributeError on circular imports of submodules (GH-27299)
Signed-off-by: Filipe Laíns <lains@riseup.net>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/test/test_import')
4 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 9744761..e0299c1 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -1350,6 +1350,16 @@ class CircularImportTests(unittest.TestCase): str(cm.exception), ) + def test_absolute_circular_submodule(self): + with self.assertRaises(AttributeError) as cm: + import test.test_import.data.circular_imports.subpkg2.parent + self.assertIn( + "cannot access submodule 'parent' of module " + "'test.test_import.data.circular_imports.subpkg2' " + "(most likely due to a circular import)", + str(cm.exception), + ) + def test_unwritable_module(self): self.addCleanup(unload, "test.test_import.data.unwritable") self.addCleanup(unload, "test.test_import.data.unwritable.x") diff --git a/Lib/test/test_import/data/circular_imports/subpkg2/__init__.py b/Lib/test/test_import/data/circular_imports/subpkg2/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Lib/test/test_import/data/circular_imports/subpkg2/__init__.py diff --git a/Lib/test/test_import/data/circular_imports/subpkg2/parent/__init__.py b/Lib/test/test_import/data/circular_imports/subpkg2/parent/__init__.py new file mode 100644 index 0000000..9745f60 --- /dev/null +++ b/Lib/test/test_import/data/circular_imports/subpkg2/parent/__init__.py @@ -0,0 +1 @@ +import test.test_import.data.circular_imports.subpkg2.parent.child diff --git a/Lib/test/test_import/data/circular_imports/subpkg2/parent/child.py b/Lib/test/test_import/data/circular_imports/subpkg2/parent/child.py new file mode 100644 index 0000000..1995a37 --- /dev/null +++ b/Lib/test/test_import/data/circular_imports/subpkg2/parent/child.py @@ -0,0 +1,3 @@ +import test.test_import.data.circular_imports.subpkg2.parent + +test.test_import.data.circular_imports.subpkg2.parent |