Skip to content

Commit c603f0e

Browse files
authored
Don't report import-private-name for relative imports (#7079)
Closes #7078
1 parent 3c5eca2 commit c603f0e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/whatsnew/2/2.14/full.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Release date: TBA
1818

1919
Closes #6965
2020

21+
* Don't report ``import-private-name`` for relative imports.
22+
23+
Closes #7078
24+
2125

2226
What's New in Pylint 2.14.3?
2327
----------------------------

pylint/extensions/private_import.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ def same_root_dir(
250250
"""Does the node's file's path contain the base name of `import_mod_name`?"""
251251
if not import_mod_name: # from . import ...
252252
return True
253+
if node.level: # from .foo import ..., from ..bar import ...
254+
return True
253255

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

tests/functional/ext/private_import/private_import.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for import-private-name."""
22
# pylint: disable=unused-import, missing-docstring, reimported, import-error, wrong-import-order
33
# pylint: disable=no-name-in-module, multiple-imports, ungrouped-imports, misplaced-future
4-
# pylint: disable=wrong-import-position
4+
# pylint: disable=wrong-import-position, relative-beyond-top-level
55

66
# Basic cases
77
from _world import hello # [import-private-name]
@@ -132,3 +132,8 @@ def get_example(self):
132132
class Example:
133133
def save(self):
134134
return self
135+
136+
137+
# Treat relative imports as internal
138+
from .other_file import _private
139+
from ..parent import _private

0 commit comments

Comments
 (0)