Skip to content

Commit

Permalink
Support pyz imports (#1161)
Browse files Browse the repository at this point in the history
* Support pyz imports

Closes pylint-dev/pylint#3887
  • Loading branch information
grayjk authored Sep 10, 2021
1 parent ac100bc commit 741cd61
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
============================
Expand Down
2 changes: 1 addition & 1 deletion astroid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 15 additions & 0 deletions tests/unittest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 741cd61

Please sign in to comment.