Skip to content

Commit

Permalink
Fix Pyreverse line break bug (pylint-dev#8988)
Browse files Browse the repository at this point in the history
* Elaborate line break test

* Fix Pyreverse line break bug
  • Loading branch information
nickdrozd authored Sep 2, 2023
1 parent 92b9840 commit 2d3aadd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8671.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a line break error in Pyreverse dot output.

Closes #8671
4 changes: 2 additions & 2 deletions pylint/pyreverse/dot_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def _build_label_for_node(self, properties: NodeProperties) -> str:
# Add class methods
methods: list[nodes.FunctionDef] = properties.methods or []
for func in methods:
args = self._get_method_arguments(func)
args = ", ".join(self._get_method_arguments(func)).replace("|", r"\|")
method_name = (
f"<I>{func.name}</I>" if func.is_abstract() else f"{func.name}"
)
label += rf"{method_name}({', '.join(args)})"
label += rf"{method_name}({args})"
if func.returns:
annotation_label = get_annotation_label(func.returns)
label += ": " + self._escape_annotation_label(annotation_label)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
digraph "classes" {
rankdir=BT
charset="utf-8"
"line_breaks.A" [color="black", fontcolor="black", label=<{A|<br ALIGN="LEFT"/>|<I>f</I>(x: str | None)<br ALIGN="LEFT"/>}>, shape="record", style="solid"];
"line_breaks.A" [color="black", fontcolor="black", label=<{A|p : int \| None<br ALIGN="LEFT"/>|<I>f</I>(x: str \| None \| (list[A] \| list[int]), y: A \| (int \| str) \| None): int \| str \| list[A \| int]<br ALIGN="LEFT"/>}>, shape="record", style="solid"];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
classDiagram
class A {
f(x: str | None)*
p : int | None
f(x: str | None | (list[A] | list[int]), y: A | (int | str) | None)* int | str | list[A | int]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@startuml classes
set namespaceSeparator none
class "A" as line_breaks.A {
{abstract}f(x: str | None)
p : int | None
{abstract}f(x: str | None | (list[A] | list[int]), y: A | (int | str) | None) -> int | str | list[A | int]
}
@enduml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8671

class A:
def f(self, x: str | None):
p: int | None

def f(self,
x: (str | None) | (list[A] | list[int]),
y: A | (int | str) | None,
) -> int | str | list[A | int]:
pass

0 comments on commit 2d3aadd

Please sign in to comment.