Skip to content

AstroidManager.ast_from_module_name returns incorrect module when a pyz is in the PYTHONPATH #2770

Open
@grayjk

Description

@grayjk

Create a pyz x.zip:

$ unzip -t x.zip 
Archive:  x.zip
    testing: xxx/                     OK
    testing: xxx/test.py              OK
    testing: xxx/__init__.py          OK
No errors detected in compressed data of x.zip.

xxx/test.py contains a function named func

Run python:

$ PYTHONPATH=x.zip python3
>>> from astroid.manager import AstroidManager
>>> AstroidManager().ast_from_module_name('xxx.test').file
'/usr/lib/python3.12/test/__init__.py'

The module returned is from the python stdlib but should be from within the pyz

Expected result:

>>> AstroidManager().ast_from_module_name('xxx.test').file
'/home/user/pyztest/x.zip/xxx/test.py'

Tested with astroid 3.3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions