Skip to content
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

False positive import-self when attempting relative import of misspelled submodule name in a package. #7452

Open
emcd opened this issue Sep 10, 2022 · 1 comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Import system

Comments

@emcd
Copy link
Contributor

emcd commented Sep 10, 2022

Bug description

from . import <submodule-name> is a frequent pattern in Python and people can misspell a submodule name. As the misspelled name should not conflict with any attribute contained in the module performing the relative import, an error about a missing module attribute would be more appropriate and less likely to produce confusion than import-self. It seems reasonable that import-self should be reserved for cases where there is an attempt to import an existent attribute from the importing module itself.

$ cat pylint_bug/__init__.py
''' Simple reproducer for Pylint 'import-self' false positive. '''
from . import misspelled_module_name

Result of running Pylint on this:

$ pylint --reports=no --score=no pylint_bug
************* Module pylint_bug
pylint_bug/__init__.py   2, 0 [import-self] Module import itself

I see that there has been some recent conversation around another import-self issue: #5151 / #7289 . If a fix for this issue is also part of the fix for that one, then apologies for the noise.

Configuration

No response

Command used

pylint --reports=no --score=no pylint_bug

Pylint output

************* Module pylint_bug
pylint_bug/__init__.py   2, 0 [import-self] Module import itself

Expected behavior

Would expect an error about a missing module attribute. Would only expect to see import-self if the module attribute actually existed and the module had an import cycle with itself.

Pylint version

$ pylint --version
pylint 2.15.2
astroid 2.12.9
Python 3.7.13 (default, Aug  5 2022, 09:50:13)
[GCC 9.4.0]

OS / Environment

No response

Additional dependencies

No response

@emcd emcd added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 10, 2022
@DanielNoord
Copy link
Collaborator

Thanks @emcd. This is indeed a bug! I hope this gets fixed with #7289, but we should at least consider them at the same time!

@clavedeluna clavedeluna added Import system False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Import system
Projects
None yet
Development

No branches or pull requests

3 participants