-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
import resolution incorrect with same-named file and external module #5151
Comments
I think if you create an file called
and that file is not part of a package then that file is importing itself, because the directory of the currently-executing script will always be first on Where there might be an issue is with a file called I suppose if the file in question is imported from another Python file, and is not in a package but is imported because its directory has been added to Is there a more specific case that we should be investigating here? |
I suggest closing this in favor of #7289 and retitling it -- that one focuses on the case where we have |
Sorry, I missed the investigation by Tim. That said, I can still get an incorrect pylint-dev/astroid#1747 fixes this. Edit: Never mind, pylint-dev/astroid#1747 doesn't fix this. Needs some investigation. |
Thanks @DanielNoord. Can you include a snippet from a python session that verifies that python is not importing self? E.g. |
❯ cat pylint.py
import pylint
print(pylint.modify_sys_path)
❯ python pylint.py
<function modify_sys_path at 0x101dde050> |
Oh wait, pylint-dev/astroid#1747 does fix this. As the But the successful removal of |
I see something different:
|
Yeah, this is different than the original issue but I think there is still an issue here. |
You can also recreate this with: cd /tmp
mkdir pylint
cd pylint
echo -e "X = 1" > __init__.py
cd ..
echo -e "import pylint\nprint(pylint.X)" > pylint.py Without the fix in |
Proposal, let pylint-dev/astroid#1747 fix this issue as this one was originally about import order resolution which I clearly what we are fixing there. Rescope #7289 to fix @jacobtylerwalls Does that sound right? |
This was fixed in pylint-dev/astroid#1747. We don't need regression tests in |
This was fixed with pylint 2.16's upgrade to astroid 2.13; please reopen if still an issue. |
Problem persists: see this comment on #3665. |
Bug description
When a python file and a external module have the same name, python resolves a
import
for that name to the external module, but pylint resolves it to the current file which causes false positives in rulesimport-self
,no-name-in-module
,no-member
and more module-related rules.To reproduce:
redis
pypi module using your favourite package managerredis.py
with contentimport redis
pylint redis.py
Pylint output
************* Module redis redis.py:1:0: W0406: Module import itself (import-self)
Expected behavior
No error
Pylint version
OS / Environment
macOS 11
Additional dependencies
redis==3.2.0
The text was updated successfully, but these errors were encountered: