-
-
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
Running pylint on namespace modules results in import-error #2862
Comments
@gpakosz Thanks for reporting an issue. I believe this is an issue related to namespace packages. In Python 3, you can have directories without |
Thanks for the reply @PCManticore, FYI in this specific repro, I had to create both |
I seem to be running into this issue too, with pylint 2.5.2. A test-case based on the structure of the project I've been assigned to:
main.py runs fine:
Even if pylint complains:
Adding the current directory to PYTHONPATH or sys.path, or removing the outer
The presence or absence of 2.4.4 doesn't exhibit the same behavior.
|
Please bring back support for native namespace packaging. Is there a work-around other than keeping pylint less than version 2.5.x? |
Yes, you can add a new
This works as long as you don't add an The |
fixes #22517 - need to ignore pylint `import-error` due to same issue as here: pylint-dev/pylint#2862
fixes Azure#22517 - need to ignore pylint `import-error` due to same issue as here: pylint-dev/pylint#2862
fixes Azure#22517 - need to ignore pylint `import-error` due to same issue as here: pylint-dev/pylint#2862
A test for def test_lint_namespace_package(initialized_linter: PyLinter) -> None:
linter = initialized_linter
with tempdir():
create_files(["namespace/__init__.py", "namespace/submodule.py"])
create_files(["other/namespace/namespace.py"])
with open(Path("namespace/submodule.py"), "w", encoding="utf-8") as f:
f.write("""\"\"\"This is namespace.submodule\"\"\"
def noop():
pass
""")
with open(Path("other/namespace/example.py"), "w", encoding="utf-8") as f:
f.write("""\"\"\"This module imports namespace.submodule\"\"\"
import namespace.submodule
namespace.submodule.noop()
""")
linter.check(["other/namespace/example.py"])
assert not linter.stats.by_msg |
See #3984 for an even simpler test case. I'm optimistic but not certain that a fix would handle both cases. |
Here's a simple repro
When I launch the code with
python -m
, the code runs just fine.However, when running
pylint
on a single file, I'm hittingE0611
. My real goal is to launchpylint
on modified file from a Gitpre-commit
hook. I tried using--init-hook
and manipulatesys.path
without success.Thanks for the help
The text was updated successfully, but these errors were encountered: