-
-
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
Invalid "Module import itself" error for namespace packages. #2648
Comments
Thanks for reporting an issue! |
At opentelemetry/opentelemetry-python, we have the same issue and it's very annoying as we would like to add companion modules for widely-used libraries that are named the same as the corresponding library, but in a different package. EDIT: astroid==2.3.1,pylint==2.4.2 |
It's very likely that #2862 is the same problem but that issue has a nicer repro. |
Also, the |
I run into the same problem when I use namespace packages. My pylint version is 2.4.4, I tried with more recent versions but it does not solve at all. Any suggestions? |
Did you try to install from scratch (do you have the latest astroid version too) ? This issue seems related to #5235 it might be a solution. If you have an example of repository with namespace feel free to comment on it :) |
Thanks! I uninstalled pylint and astroid, and re-installed pylint with its latest version (2.13.4). I will try to explain the package structure. The problem is, namespace package name conflicts with another python library name (it is an internal one, so I will pick pandas as an example);
The content of namespace_pkg/pandas/init.py is as follows; cat
When I run the file directly as
But when I run pylint:
|
Can you try installing pylint with : |
Yeah, it does fix it. Thanks :) btw, the correct pip install command should be as;
|
@Pierre-Sassoulas Can we use this example to create a folder structure to test on in the primer? |
Yes, I was thinking we should use something else than pandas, like pathlib, so we don't have to add dependencies to pandas. |
@Pierre-Sassoulas do you have any planned timeline for the next release? when we can get the new feature implemented in #5235 :) |
You can check https://github.com/PyCQA/pylint/milestone/61 to see the next patch release addvancement. It depends on the availability of implementers and reviewer but soonish ™️ |
I have been working on a fix in #6405. For anybody affected by this, please let me know if the changes in that PR fix your issues with linting of namespace packages. |
Steps to reproduce
You can either clone this repo to get the test file tree:
git clone https://github.com/feluxe/test_pylint_ns_package_err.git
cd
into it and runpipenv install --dev --pre
or create the file tree manually with the following steps:
Create test file tree manually:
Create this file tree:
Next, install
pylint
andsty
from pypi in a Python 3.7 virtualenv:We add this line to
nspackage/mypackage/__init__.py
:We add this line to
nspackage/sty/__init__.py
:We add these lines to
test.py
:Current behavior
Note: As you can see in the project file tree,
nspackage
is a name space package omitting__init__.py
.If I run
pipenv run pylint nspackage
, I get these errors:Expected behavior
I think the example project is valid Python and pylint should not complain.
You can run
test.py
for validation:which runs just fine.
pylint --version output
The text was updated successfully, but these errors were encountered: