Description
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