-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
false-positive: E0401 import-error for relative imports inside __init__.py (but only sometimes) #5319
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
Comments
I noticed if I change the order of relative imports n a |
I wrote a script which generates a minimal example with N nested submodules each including M files each. Unfortunately, the issue does not occur in the minimal example. make_minimal_example_E0401.txt (note: change the extension to .py since GitHub does not allow to upload script files) |
Thanks for the report. The indeterminacy is described in #3651, which appears to be fixed in recent pylint versions (anything shipping with astroid > 2.9.1). Feel free to reopen if still an issue. |
It looks like this issue is still present - I have tried on 2.14.4 and 2.14.5 with the same issue ... sometimes happening We are currently migrating from a Windows pipeline to a Linux pipeline in ADO when this issue first occured. I am not sure if it has to do with Linux or not, but we are only able to reproduce it there. We have several repos where we have made this change recently with no issue. Also, we still have the Windows pipeline running and not seeing this issue. astroid-2.11.7 pylama-8.3.8 isort-5.10.1 mccabe-0.7.0 pycodestyle-2.8.0 pydocstyle-6.1.1 pyflakes-2.4.0 I will continue to go down in versions to see if one is stable @jacobtylerwalls for visibility |
Thanks for testing, it's much appreciated! I'm going to take a note on #3651 that it may not be solved. (I declared victory too soon, it seems, since the regression test at #7117 isn't passing.) Still, unless there's a reason to treat these as separate issues, I'm thinking we can just keep #3651 open. |
Bug description
Description
Relative imports inside a
__init__.py
file cause random E0401.E.g.:
Say one has a module A.B.C.D inside a folder
src
such that__init__.py
files exist for modules A, B, C and Dsrc/A/B/C/D/some_moduleX.py
exists and definesSomeClassX
whereX=1,2,3
src/A/B/C/D/__init__.py
containspylint will issue E0401 (pseudo-)randomly for some of the imports, even if all of them are similar. For which one the warnings are issued depends on the version/machine used - e.g. GitHub actions uses pylint v.2.11.1 and gives me different locations and a different amount of E0401.
If there are only a few relative imports across the entire project, pylint might not issue E0401 at all.
Python code using this module works flawlessly. E.g. via
from A.B.C.D import SomeClass2
Workaround
Adding a
.pylintrc
fixes the issue.
Sad Note
I tried to come up with a minimalistic example with nested modules all containing relative imports in the
__init__.py
files importing dummy classes from the same level but for some reason this bug could not be provoked that way. I tried for quite a while but this is the best I can do.Related
Configuration
No response
Command used
Pylint output
Expected behavior
no warnings
Pylint version
OS / Environment
ArchLinux 5.15.2-arch1-1 (Fri, 12 Nov 2021)
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: