Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astroid >=3.3.7 imports and executes modules that contain any similarly named identifier as some stdlib module #2684

Open
pmustonen opened this issue Feb 13, 2025 · 2 comments
Assignees

Comments

@pmustonen
Copy link

The frozen module finding logic in astroid >= 3.3.7 (https://github.com/pylint-dev/astroid/blob/main/astroid/interpreter/_import/spec.py#L177) seems to interfere with non-module names that match with names in sys.stdlib_module_names.

The following example is done with pylint (using pylint 3.3.4, astroid 3.3.8 and Python 3.12.8), but I'm still posting it here because it seems to be astroid-related issue. The most simple reproduction I was able to figure out is with a module that is imported

sayhi.py

print("hello")

def trace():
    pass

main.py:

from sayhi import trace

output from pylint main.py is

hello
************* Module main
main.py 1: Unused trace imported from sayhi (unused-import)

The trace here is also name of a module in stdlib, but that should be valid Python code anyway.

Expected outcome is that "hello" is not printed, as sayhi.py shouldn't be imported or executed by astroid (or pylint). That is also the case with astroid 3.3.6.

@DanielNoord
Copy link
Collaborator

I think this is sort of expected behaviour, although obviously not ideal.

I don't really know if there would be a better solution than the one we currently have for frozen modules, but we're obviously open to suggestions.

@jacobtylerwalls
Copy link
Member

@pmustonen any proposed fixes are welcome, I'm assigning myself not to discourage anyone else's contributions, but just to put it on a tinker list for when I might have time.

@jacobtylerwalls jacobtylerwalls self-assigned this Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants