On a Linux environment, I have the following three files in a folder named utils
:
-
An empty file
__init__.py
-
A file named
mymain .py
with the following content:from mytool import foo
-
A file
mytool.py
with the following content:from subprocess import check_output def foo(): print("Hello World")
Now I create a virtual environment with the following setup:
astroid==2.4.2
isort==5.7.0
lazy-object-proxy==1.4.3
packaging==20.9
pylint==2.6.0
pyparsing==2.4.7
six==1.15.0
toml==0.10.2
typed-ast==1.4.2
wrapt==1.12.1
Then I run the pylint check on that folder
pylint utils
or
pylint --disable=C,R,W utils # only the error is of interest
it should return a score of 10.
When you now upgrade the version of astroid
to 2.5.0 and run the check again, you get the error:
************* Module utils.mymain
utils/mymain.py:2:0: E0401: Unable to import 'mytool' (import-error)
Is the changed behavior because of the deprecated importlib methods, as pointed out HERE?
Interesting fact
If you remove the unused import statement in the file mytool.py
, you also get the same import error even with astroid
version 2.4.2
Why; How can an unused import possibly affect the outcome of a pylint
check?
Hint: I have two questions.
from Where does astroid change its behavior for pylint checks of relative imports?
No comments:
Post a Comment