Skip to content

Commit 538c41b

Browse files
Don't use removed function from astroid (#8525) (#8526)
(cherry picked from commit f7bd676) Co-authored-by: Daniël van Noord <[email protected]>
1 parent 4e11693 commit 538c41b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pylint/checkers/imports.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
if TYPE_CHECKING:
3838
from pylint.lint import PyLinter
3939

40+
if sys.version_info >= (3, 8):
41+
from functools import cached_property
42+
else:
43+
from astroid.decorators import cachedproperty as cached_property
44+
45+
4046
# The dictionary with Any should actually be a _ImportTree again
4147
# but mypy doesn't support recursive types yet
4248
_ImportTree = Dict[str, Union[List[Dict[str, Any]], List[str]]]
@@ -997,7 +1003,7 @@ def _report_external_dependencies(
9971003
self, sect: Section, _: LinterStats, _dummy: LinterStats | None
9981004
) -> None:
9991005
"""Return a verbatim layout for displaying dependencies."""
1000-
dep_info = _make_tree_defs(self._external_dependencies_info().items())
1006+
dep_info = _make_tree_defs(self._external_dependencies_info.items())
10011007
if not dep_info:
10021008
raise EmptyReportError()
10031009
tree_str = _repr_tree_defs(dep_info)
@@ -1019,10 +1025,10 @@ def _report_dependencies_graph(
10191025
_make_graph(filename, dep_info, sect, "")
10201026
filename = self.linter.config.ext_import_graph
10211027
if filename:
1022-
_make_graph(filename, self._external_dependencies_info(), sect, "external ")
1028+
_make_graph(filename, self._external_dependencies_info, sect, "external ")
10231029
filename = self.linter.config.int_import_graph
10241030
if filename:
1025-
_make_graph(filename, self._internal_dependencies_info(), sect, "internal ")
1031+
_make_graph(filename, self._internal_dependencies_info, sect, "internal ")
10261032

10271033
def _filter_dependencies_graph(self, internal: bool) -> defaultdict[str, set[str]]:
10281034
"""Build the internal or the external dependency graph."""
@@ -1035,14 +1041,14 @@ def _filter_dependencies_graph(self, internal: bool) -> defaultdict[str, set[str
10351041
graph[importee].add(importer)
10361042
return graph
10371043

1038-
@astroid.decorators.cached
1044+
@cached_property
10391045
def _external_dependencies_info(self) -> defaultdict[str, set[str]]:
10401046
"""Return cached external dependencies information or build and
10411047
cache them.
10421048
"""
10431049
return self._filter_dependencies_graph(internal=False)
10441050

1045-
@astroid.decorators.cached
1051+
@cached_property
10461052
def _internal_dependencies_info(self) -> defaultdict[str, set[str]]:
10471053
"""Return cached internal dependencies information or build and
10481054
cache them.

0 commit comments

Comments
 (0)