Skip to content

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

@pmustonen

Description

@pmustonen

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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions