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

[Backport maintenance/2.17.x] Don't use removed function from astroid #8526

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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