summaryrefslogtreecommitdiff
path: root/pylint/pyreverse/dot_printer.py
diff options
context:
space:
mode:
authorAndreas Finkler <3929834+DudeNr33@users.noreply.github.com>2021-08-14 21:34:00 +0200
committerGitHub <noreply@github.com>2021-08-14 21:34:00 +0200
commit4da3862f492f017be3149a5b89f365335f0bf746 (patch)
tree8c6c3622232b22c79280dca66c8c4e5f02262ad5 /pylint/pyreverse/dot_printer.py
parentf2cd986da07c12e81dd411e4b1190386a6cad750 (diff)
downloadpylint-git-4da3862f492f017be3149a5b89f365335f0bf746.tar.gz
``pyreverse``: add PlantUML output (#4846)
* Extract helper method to get annotated arguments into ``Printer`` base class. * Add ``Printer`` subclass for PlantUML output * Add functional test for ``PlantUmlPrinter`` * Add tests for specific layout for ``PlantUmlPrinter`` * Extract test helper function to remove code duplication * Add new test class to check type annotations * Cleanup generated .puml files after tests finished * Create a factory function to get the correct ``Printer`` class for a given filetype. * Fix unittest after adding a new class to the test data. * Add changelog and whatsnew entry * Add "plantuml" as possible extension for PlantUML output
Diffstat (limited to 'pylint/pyreverse/dot_printer.py')
-rw-r--r--pylint/pyreverse/dot_printer.py33
1 files changed, 6 insertions, 27 deletions
diff --git a/pylint/pyreverse/dot_printer.py b/pylint/pyreverse/dot_printer.py
index bcd58984b..4b735bb3f 100644
--- a/pylint/pyreverse/dot_printer.py
+++ b/pylint/pyreverse/dot_printer.py
@@ -80,9 +80,8 @@ class DotPrinter(Printer):
f'"{name}" [color="{color}"{fontcolor_part}{label_part}, shape="{shape}", style="{self.node_style}"];'
)
- @staticmethod
def _build_label_for_node(
- properties: NodeProperties, is_interface: Optional[bool] = False
+ self, properties: NodeProperties, is_interface: Optional[bool] = False
) -> str:
if not properties.label:
return ""
@@ -103,31 +102,11 @@ class DotPrinter(Printer):
# Add class methods
methods: List[astroid.FunctionDef] = properties.methods or []
for func in methods:
- return_type = (
- f": {get_annotation_label(func.returns)}" if func.returns else ""
- )
-
- if func.args.args:
- arguments: List[astroid.AssignName] = [
- arg for arg in func.args.args if arg.name != "self"
- ]
- else:
- arguments = []
-
- annotations = dict(zip(arguments, func.args.annotations[1:]))
- for arg in arguments:
- annotation_label = ""
- ann = annotations.get(arg)
- if ann:
- annotation_label = get_annotation_label(ann)
- annotations[arg] = annotation_label
-
- args = ", ".join(
- f"{arg.name}: {ann}" if ann else f"{arg.name}"
- for arg, ann in annotations.items()
- )
-
- label += fr"{func.name}({args}){return_type}\l"
+ args = self._get_method_arguments(func)
+ label += fr"{func.name}({', '.join(args)})"
+ if func.returns:
+ label += ": " + get_annotation_label(func.returns)
+ label += r"\l"
label += "}"
return label