You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why? It is an absolute import. It is referencing the standard library logging. If I wanted to reference itself it would be from .logging import ...
This is no implicit relative import, it has been deprecated since Python 3
My circumstances are more or less identical: I have a file named logging.py, with the first line from logging import Formatter, StreamHandler, getLogger, INFO.
Upon running pylint /path/to/file/logging.py, I get W0406: Module import itself (import-self) repeated 4 times.
As far as I can tell, the only way to resolve this is to either disable the warning or rename the file.
My circumstances are more or less identical: I have a file named logging.py, with the first line from logging import Formatter, StreamHandler, getLogger, INFO.
Upon running pylint /path/to/file/logging.py, I get W0406: Module import itself (import-self) repeated 4 times.
I have PYTHONSAFEPATH set, so working directory isn't on sys.path. (Error persists even if the file being checked isn't in the working directory, and even if I run pylint with an init-hook that explicitly writes sys.path to ensure that file being checked isn't in module search path.)
@jacobtylerwalls No that doesn't fix it. I checked out the branch linked in that pull request (specifically commit 849f68e0), built the package and installed in my sys.path. And moved my distro's astroid out of the sys.path. Then:
I just now noticed that if a package (file or directory containing __init__.py) which displays this issue is on my module search path, and instead of providing pylint with a path to the package, I just say pylint $PACKAGENAME, then the error does not arise.
Activity
Project-Magenta commentedon Jun 3, 2020
It is a reference to itself. Try it!
niander commentedon Jun 4, 2020
Why? It is an absolute import. It is referencing the standard library
logging
. If I wanted to reference itself it would befrom .logging import ...
This is no implicit relative import, it has been deprecated since Python 3
DanielNoord commentedon Aug 5, 2021
@Pierre-Sassoulas I cannot reproduce this. Might have been fixed!
GTcreyon commentedon Sep 3, 2024
I've experienced the same (or a very similar) issue.
pylint --version output:
My circumstances are more or less identical: I have a file named
logging.py
, with the first linefrom logging import Formatter, StreamHandler, getLogger, INFO
.Upon running
pylint /path/to/file/logging.py
, I getW0406: Module import itself (import-self)
repeated 4 times.As far as I can tell, the only way to resolve this is to either disable the warning or rename the file.
davetapley commentedon Oct 30, 2024
I just got this too, not sure if regression:
In my case my file is called
falcon.py
and I e.g.:which causes it too, so not limited to stdlib.
dubiousjim commentedon Oct 31, 2024
Confirmed for:
Running
python ./logging.py
executes fine.I have
PYTHONSAFEPATH
set, so working directory isn't onsys.path
. (Error persists even if the file being checked isn't in the working directory, and even if I run pylint with aninit-hook
that explicitly writessys.path
to ensure that file being checked isn't in module search path.)dubiousjim commentedon Oct 31, 2024
Related issues: #5151, #6535, #7289
import-self
false positive when importing non-existing module from current package #3748jacobtylerwalls commentedon Oct 31, 2024
@dubiousjim is the situation any different with pylint-dev/astroid#2223?
dubiousjim commentedon Oct 31, 2024
@jacobtylerwalls No that doesn't fix it. I checked out the branch linked in that pull request (specifically commit 849f68e0), built the package and installed in my sys.path. And moved my distro's
astroid
out of the sys.path. Then:I left my existing
pylint
package in place; only changed the versionastroid
being used.dubiousjim commentedon Oct 31, 2024
Build steps:
Then disable my distro's copy of
astroid
(in/usr/lib
).jacobtylerwalls commentedon Oct 31, 2024
Got it, appreciate you finding out and reporting back.
dubiousjim commentedon Oct 31, 2024
I just now noticed that if a package (file or directory containing
__init__.py
) which displays this issue is on my module search path, and instead of providing pylint with a path to the package, I just saypylint $PACKAGENAME
, then the error does not arise.dubiousjim commentedon Oct 31, 2024
Here's a more exhaustive detailing of when the issue does/doesn't arise: