Skip to content

Commit

Permalink
Don't report import-private-name for relative imports
Browse files Browse the repository at this point in the history
Closes #7078
  • Loading branch information
scop committed Jun 28, 2022
1 parent 3c5eca2 commit 8e94d7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Expand Up @@ -18,6 +18,10 @@ Release date: TBA

Closes #6965

* Don't report ``import-private-name`` for relative imports.

Closes #7078


What's New in Pylint 2.14.3?
----------------------------
Expand Down
2 changes: 2 additions & 0 deletions pylint/extensions/private_import.py
Expand Up @@ -250,6 +250,8 @@ def same_root_dir(
"""Does the node's file's path contain the base name of `import_mod_name`?"""
if not import_mod_name: # from . import ...
return True
if node.level:
return True # from .foo import ..., from ..bar import ...

base_import_package = import_mod_name.split(".")[0]

Expand Down
7 changes: 6 additions & 1 deletion tests/functional/ext/private_import/private_import.py
@@ -1,7 +1,7 @@
"""Tests for import-private-name."""
# pylint: disable=unused-import, missing-docstring, reimported, import-error, wrong-import-order
# pylint: disable=no-name-in-module, multiple-imports, ungrouped-imports, misplaced-future
# pylint: disable=wrong-import-position
# pylint: disable=wrong-import-position, relative-beyond-top-level

# Basic cases
from _world import hello # [import-private-name]
Expand Down Expand Up @@ -132,3 +132,8 @@ def get_example(self):
class Example:
def save(self):
return self


# Treat relative imports as internal
from .other_file import _private
from ..parent import _private

0 comments on commit 8e94d7a

Please sign in to comment.