summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2023-03-14 13:10:53 +0100
committerGitHub <noreply@github.com>2023-03-14 08:10:53 -0400
commit0d463f6e2127b81e2d13c482871f82b4c991f7bd (patch)
tree6b906bd9cdfe605a96a5247aae6257ec276d26a0
parent20e87156c577663f70caa4a32c1f46d19df12fb0 (diff)
downloadpylint-git-0d463f6e2127b81e2d13c482871f82b4c991f7bd.tar.gz
[cyclic-import] Break cycle between pylint.checkers.util / variables (#8448)
-rw-r--r--pylint/checkers/utils.py23
-rw-r--r--pylint/checkers/variables.py22
2 files changed, 21 insertions, 24 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 17cecd6eb..0104ff532 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -2266,11 +2266,28 @@ def not_condition_as_string(
return msg
+@lru_cache(maxsize=1000)
+def overridden_method(
+ klass: nodes.LocalsDictNodeNG, name: str | None
+) -> nodes.FunctionDef | None:
+ """Get overridden method if any."""
+ try:
+ parent = next(klass.local_attr_ancestors(name))
+ except (StopIteration, KeyError):
+ return None
+ try:
+ meth_node = parent[name]
+ except KeyError: # pragma: no cover
+ # We have found an ancestor defining <name> but it's not in the local
+ # dictionary. This may happen with astroid built from living objects.
+ return None
+ if isinstance(meth_node, nodes.FunctionDef):
+ return meth_node
+ return None # pragma: no cover
+
+
def clear_lru_caches() -> None:
"""Clear caches holding references to AST nodes."""
- # pylint: disable-next=import-outside-toplevel
- from pylint.checkers.variables import overridden_method
-
caches_holding_node_references: list[_lru_cache_wrapper[Any]] = [
in_for_else_branch,
infer_all,
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index f55b71264..25ca3bc7c 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -15,7 +15,6 @@ import sys
from collections import defaultdict
from collections.abc import Generator, Iterable, Iterator
from enum import Enum
-from functools import lru_cache
from typing import TYPE_CHECKING, Any, NamedTuple
import astroid
@@ -28,6 +27,7 @@ from pylint.checkers.utils import (
in_type_checking_block,
is_postponed_evaluation_enabled,
is_sys_guard,
+ overridden_method,
)
from pylint.constants import PY39_PLUS, TYPING_NEVER, TYPING_NORETURN
from pylint.interfaces import CONTROL_FLOW, HIGH, INFERENCE, INFERENCE_FAILURE
@@ -151,26 +151,6 @@ def _is_from_future_import(stmt: nodes.ImportFrom, name: str) -> bool | None:
return None
-@lru_cache(maxsize=1000)
-def overridden_method(
- klass: nodes.LocalsDictNodeNG, name: str | None
-) -> nodes.FunctionDef | None:
- """Get overridden method if any."""
- try:
- parent = next(klass.local_attr_ancestors(name))
- except (StopIteration, KeyError):
- return None
- try:
- meth_node = parent[name]
- except KeyError:
- # We have found an ancestor defining <name> but it's not in the local
- # dictionary. This may happen with astroid built from living objects.
- return None
- if isinstance(meth_node, nodes.FunctionDef):
- return meth_node
- return None
-
-
def _get_unpacking_extra_info(node: nodes.Assign, inferred: InferenceResult) -> str:
"""Return extra information to add to the message for unpacking-non-sequence
and unbalanced-tuple/dict-unpacking errors.