Skip to content

Commit

Permalink
Don't use removed function from astroid (#8525) (#8526)
Browse files Browse the repository at this point in the history
(cherry picked from commit f7bd676)

Co-authored-by: Daniël van Noord <[email protected]>
  • Loading branch information
github-actions[bot] and DanielNoord authored Apr 2, 2023
1 parent 4e11693 commit 538c41b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
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
_ImportTree = Dict[str, Union[List[Dict[str, Any]], List[str]]]
Expand Down Expand Up @@ -997,7 +1003,7 @@ def _report_external_dependencies(
self, sect: Section, _: LinterStats, _dummy: LinterStats | None
) -> None:
"""Return a verbatim layout for displaying dependencies."""
dep_info = _make_tree_defs(self._external_dependencies_info().items())
dep_info = _make_tree_defs(self._external_dependencies_info.items())
if not dep_info:
raise EmptyReportError()
tree_str = _repr_tree_defs(dep_info)
Expand All @@ -1019,10 +1025,10 @@ def _report_dependencies_graph(
_make_graph(filename, dep_info, sect, "")
filename = self.linter.config.ext_import_graph
if filename:
_make_graph(filename, self._external_dependencies_info(), sect, "external ")
_make_graph(filename, self._external_dependencies_info, sect, "external ")
filename = self.linter.config.int_import_graph
if filename:
_make_graph(filename, self._internal_dependencies_info(), sect, "internal ")
_make_graph(filename, self._internal_dependencies_info, sect, "internal ")

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

@astroid.decorators.cached
@cached_property
def _external_dependencies_info(self) -> defaultdict[str, set[str]]:
"""Return cached external dependencies information or build and
cache them.
"""
return self._filter_dependencies_graph(internal=False)

@astroid.decorators.cached
@cached_property
def _internal_dependencies_info(self) -> defaultdict[str, set[str]]:
"""Return cached internal dependencies information or build and
cache them.
Expand Down

0 comments on commit 538c41b

Please sign in to comment.