-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
False positive import-error #3984
Comments
Love how minimal this example is, I've been able to reproduce this behaviour exactly, including that the false positive import-error disappears after removing I'm doing research on static code analysis in machine learning code, where I run Pylint on a number of Python ML projects (after installing their requirements in a virtualenv). While this currently only includes 8 projects so far, Pylint reports each one of those as having several import-errors. I've noticed that most of those are imports from local files not being resolved correctly, even though they do indeed exist on the filesystem.
|
@sam-s thanks for your report. I can reproduce it. |
I'm seeing this fixed in astroid 2.12. Let's add this test case to pylint. |
@jacobtylerwalls Is this still the case? 🚀 |
No, I was probably testing in a directory on sys.path, and we now know that's been polluting our test results. Failing test for def test_import_sibling_module_from_explicit_package(initialized_linter: PyLinter) -> None:
linter = initialized_linter
with tempdir() as tmpdir:
create_files(["siblingone.py", "siblingtwo.py", "__init__.py"], tmpdir)
with open("siblingone.py", "w", encoding="utf-8") as f:
f.write(
"""\"\"\"This module contains siblingone().\"\"\"
def siblingone():
print("siblingone")
"""
)
with open("siblingtwo.py", "w", encoding="utf-8") as f:
f.write(
"""\"\"\"This module imports siblingone().\"\"\"
import siblingone
print(siblingone.siblingone())
"""
)
linter.check(["siblingtwo"])
assert not linter.stats.by_msg |
Hi, I am still facing this issue with latest pylint version. pylint --version output: pylint 2.16.2
astroid 2.14.2
Python 3.10.4 (main, Feb 15 2023, 15:33:42) [GCC 9.4.0] |
I found 2 solutions for this issue. For those who suffer from this issue like me: from . import a Explanation: As I understand, when we create If your code structure is more complicated, modify an appropriate path value. Hope it helps! |
issue remain in
|
For those who still facing this issue and have a similar structure like below
Try to add
It's working in
|
UPD: Looks like that workaround works and I hit a different bug with parallelism — #10147. |
Steps to reproduce
in an empty directory:
a.py
:b.py
__init__.py
Current behavior
Expected behavior
no diagnostics
Important note
if you remove
__init__.py
, theimport-error
disappears.pylint --version output
The text was updated successfully, but these errors were encountered: