summaryrefslogtreecommitdiff
path: root/pylint/checkers/imports.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/checkers/imports.py')
-rw-r--r--pylint/checkers/imports.py32
1 files changed, 8 insertions, 24 deletions
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index ef7fe50cc..42649f3d9 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -1,6 +1,6 @@
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
-# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
+# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
+# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
"""Imports checkers for Python code."""
@@ -12,6 +12,7 @@ import os
import sys
from collections import defaultdict
from collections.abc import ItemsView, Sequence
+from functools import cached_property
from typing import TYPE_CHECKING, Any, Dict, List, Union
import astroid
@@ -23,6 +24,7 @@ from pylint.checkers.utils import (
get_import_name,
in_type_checking_block,
is_from_fallback_block,
+ is_module_ignored,
is_sys_guard,
node_ignores_exception,
)
@@ -37,11 +39,6 @@ from pylint.utils.linterstats import LinterStats
if TYPE_CHECKING:
from pylint.lint import PyLinter
-if sys.version_info >= (3, 8):
- from functools import cached_property
-else:
- from astroid.decorators import cachedproperty as cached_property
-
# The dictionary with Any should actually be a _ImportTree again
# but mypy doesn't support recursive types yet
@@ -84,18 +81,6 @@ DEPRECATED_MODULES = {
}
-def _qualified_names(modname: str | None) -> list[str]:
- """Split the names of the given module into subparts.
-
- For example,
- _qualified_names('pylint.checkers.ImportsChecker')
- returns
- ['pylint', 'pylint.checkers', 'pylint.checkers.ImportsChecker']
- """
- names = modname.split(".") if modname is not None else ""
- return [".".join(names[0 : i + 1]) for i in range(len(names))]
-
-
def _get_first_import(
node: ImportNode,
context: nodes.LocalsDictNodeNG,
@@ -153,12 +138,11 @@ def _get_first_import(
def _ignore_import_failure(
node: ImportNode,
- modname: str | None,
+ modname: str,
ignored_modules: Sequence[str],
) -> bool:
- for submodule in _qualified_names(modname):
- if submodule in ignored_modules:
- return True
+ if is_module_ignored(modname, ignored_modules):
+ return True
# Ignore import failure if part of guarded import block
# I.e. `sys.version_info` or `typing.TYPE_CHECKING`
@@ -852,7 +836,7 @@ class ImportsChecker(DeprecatedMixin, BaseChecker):
return std_imports, external_imports, local_imports
def _get_imported_module(
- self, importnode: ImportNode, modname: str | None
+ self, importnode: ImportNode, modname: str
) -> nodes.Module | None:
try:
return importnode.do_import_module(modname)