Skip to content

Commit c82d08c

Browse files
scopPierre-Sassoulas
authored andcommitted
Don't report import-private-name for relative imports (#7079)
Closes #7078
1 parent f8f05f1 commit c82d08c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/whatsnew/2/2.14/full.rst

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Release date: TBA
2222

2323
Closes #6965
2424

25+
* Don't report ``import-private-name`` for relative imports.
26+
27+
Closes #7078
28+
2529

2630
What's New in Pylint 2.14.3?
2731
----------------------------

pylint/extensions/private_import.py

+2
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

+6-1
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)