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

Don't report import-private-name for relative imports #7079

Merged
merged 1 commit into from Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: # from .foo import ..., from ..bar import ...
return True

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