Skip to content

Linting fails if module contains module of the same name #4444

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

Open
iFreilicht opened this issue May 6, 2021 · 3 comments · Fixed by #7114
Open

Linting fails if module contains module of the same name #4444

iFreilicht opened this issue May 6, 2021 · 3 comments · Fixed by #7114
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Import system namespace-package Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@iFreilicht
Copy link

iFreilicht commented May 6, 2021

Steps to reproduce

Given multiple files:

.
`-- a/
    |-- a.py
    `-- b.py

Which are all empty, running pylint a fails:

$ pylint a
************* Module a
a/__init__.py:1:0: F0010: error while code parsing: Unable to load file a/__init__.py:
[Errno 2] No such file or directory: 'a/__init__.py' (parse-error)
$

However, if I rename a.py, pylint a succeeds:

$ mv a/a.py a/c.py
$ pylint a
$

Alternatively, I can also touch a/__init__.py, but that shouldn't be necessary anymore.

Current behavior

Running pylint a if a/a.py is present fails while searching for an __init__.py file.

Expected behavior

Running pylint a if a/a.py is present should succeed.

pylint --version output

Result of pylint --version output:

pylint 3.0.0a3
astroid 2.5.6
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0]

Additional info

This also has some side-effects in module resolution. For example, if I create another file r.py:

.
|-- a
|   |-- a.py
|   `-- b.py
`-- r.py

With the content:

from a import b

Running pylint -E r will run fine, but pylint -E r a will fail. Not just for module a, but for module r as well.

************* Module r
r.py:1:0: E0611: No name 'b' in module 'a' (no-name-in-module)
************* Module a
a/__init__.py:1:0: F0010: error while code parsing: Unable to load file a/__init__.py:
[Errno 2] No such file or directory: 'a/__init__.py' (parse-error)

Again, if I rename a.py to c.py, pylint -E r a will work perfectly.

@hippo91
Copy link
Contributor

hippo91 commented May 14, 2021

@iFreilicht thanks for your report.

@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Import system labels May 14, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation namespace-package labels Jul 2, 2022
@jacobtylerwalls
Copy link
Member

#4909 was a duplicate.

@jacobtylerwalls
Copy link
Member

#7114 was not correct and will be reverted in #7304.

Regression test for test_lint.py for anyone attempting a fix:

def test_identically_named_nested_module(initialized_linter: PyLinter) -> None:
    with tempdir():
        create_files(["identical/identical.py"])
        with open("identical/identical.py", "w", encoding="utf-8") as f:
            f.write("import imp")
        initialized_linter.check(["identical"])
    assert initialized_linter.stats.by_msg["deprecated-module"] == 1

@jacobtylerwalls jacobtylerwalls removed this from the 2.15.0 milestone Aug 13, 2022
@jacobtylerwalls jacobtylerwalls removed their assignment Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Import system namespace-package Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
4 participants