From 741cd614d7cec1f730a66632f018ff0bcb17b561 Mon Sep 17 00:00:00 2001 From: grayjk Date: Fri, 10 Sep 2021 16:19:37 -0400 Subject: [PATCH] Support pyz imports (#1161) * Support pyz imports Closes PyCQA/pylint#3887 --- ChangeLog | 3 +++ astroid/manager.py | 2 +- tests/unittest_manager.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4fe21c5f13..52c974a717 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,9 @@ Release date: TBA * ``op`` (``str``) for ``AugAssign``, ``BinOp``, ``BoolOp``, ``UnaryOp`` * ``names`` (``list[tuple[str, str | None]]``) for ``Import`` +* Support pyz imports + + Closes PyCQA/pylint#3887 What's New in astroid 2.7.4? ============================ diff --git a/astroid/manager.py b/astroid/manager.py index 5575151e48..89ef2ac609 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -46,7 +46,7 @@ ) from astroid.transforms import TransformVisitor -ZIP_IMPORT_EXTS = (".zip", ".egg", ".whl") +ZIP_IMPORT_EXTS = (".zip", ".egg", ".whl", ".pyz", ".pyzw") def safe_repr(obj): diff --git a/tests/unittest_manager.py b/tests/unittest_manager.py index b81513b191..a810359554 100644 --- a/tests/unittest_manager.py +++ b/tests/unittest_manager.py @@ -220,6 +220,21 @@ def test_ast_from_module_name_zip(self): os.path.sep.join(["data", os.path.normcase("MyPyPa-0.1.0-py2.5.zip")]) ) + def test_ast_from_module_name_pyz(self): + try: + linked_file_name = os.path.join( + resources.RESOURCE_PATH, "MyPyPa-0.1.0-py2.5.pyz" + ) + os.symlink( + os.path.join(resources.RESOURCE_PATH, "MyPyPa-0.1.0-py2.5.zip"), + linked_file_name, + ) + + with self._restore_package_cache(): + self._test_ast_from_zip(linked_file_name) + finally: + os.remove(linked_file_name) + def test_zip_import_data(self): """check if zip_import_data works""" with self._restore_package_cache():