From 0f1582a33c650ba65987e1db8174e2a29d50ab06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Wed, 15 Sep 2021 23:28:43 +0200 Subject: [PATCH 1/2] Move methods to `BaseLayout` --- pylint/reporters/ureports/nodes.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/pylint/reporters/ureports/nodes.py b/pylint/reporters/ureports/nodes.py index c5c14737da..02887612e1 100644 --- a/pylint/reporters/ureports/nodes.py +++ b/pylint/reporters/ureports/nodes.py @@ -28,16 +28,6 @@ def __init__(self, nid=None): def __iter__(self): return iter(self.children) - def append(self, child): - """add a node to children""" - self.children.append(child) - child.parent = self - - def insert(self, index, child): - """insert a child node""" - self.children.insert(index, child) - child.parent = self - def accept(self, visitor, *args, **kwargs): func = getattr(visitor, f"visit_{self.visitor_name}") return func(self, *args, **kwargs) @@ -62,10 +52,16 @@ def __init__(self, children=(), **kwargs): else: self.add_text(child) - def append(self, child): - """overridden to detect problems easily""" + def append(self, child: VNode) -> None: + """add a node to children""" assert child not in self.parents() - VNode.append(self, child) + self.children.append(child) + child.parent = self + + def insert(self, index: int, child: VNode) -> None: + """insert a child node""" + self.children.insert(index, child) + child.parent = self def parents(self): """return the ancestor nodes""" From ce75070a2b04455e24190f56bc0593ddcc8b4995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Wed, 15 Sep 2021 23:38:20 +0200 Subject: [PATCH 2/2] Change typing --- pylint/checkers/imports.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py index 8b413253fc..b8609e9624 100644 --- a/pylint/checkers/imports.py +++ b/pylint/checkers/imports.py @@ -67,7 +67,7 @@ from pylint.graph import DotBackend, get_cycles from pylint.interfaces import IAstroidChecker from pylint.lint import PyLinter -from pylint.reporters.ureports.nodes import Paragraph, VerbatimText, VNode +from pylint.reporters.ureports.nodes import Paragraph, Section, VerbatimText from pylint.typing import CheckerStats from pylint.utils import IsortDriver, get_global_option @@ -186,7 +186,9 @@ def _dependencies_graph(filename: str, dep_info: Dict[str, List[str]]) -> str: return printer.generate(filename) -def _make_graph(filename: str, dep_info: Dict[str, List[str]], sect: VNode, gtype: str): +def _make_graph( + filename: str, dep_info: Dict[str, List[str]], sect: Section, gtype: str +): """generate a dependencies graph and add some information about it in the report's section """