Skip to content

Commit

Permalink
pylint-dev#8603 pylint/pyreverse/dot_printer.py, vertical bar escap…
Browse files Browse the repository at this point in the history
…e handling is now part of the printer as it is DOT language specific
  • Loading branch information
ViRuSTriNiTy committed Apr 24, 2023
1 parent dba6685 commit a5864f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 9 additions & 1 deletion pylint/pyreverse/dot_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,19 @@ def _build_label_for_node(self, properties: NodeProperties) -> str:
)
label += rf"{method_name}({', '.join(args)})"
if func.returns:
label += ": " + get_annotation_label(func.returns)
annotation_label = get_annotation_label(func.returns)
label += ": " + self._escape_annotation_label(annotation_label)
label += rf"{HTMLLabels.LINEBREAK_LEFT.value}"
label += "}"
return label

def _escape_annotation_label(self, annotation_label: str) -> str:
# Escape vertical bar characters to make them appear as a literal characters
# otherwise it gets treated as field separator of record-based nodes
annotation_label = annotation_label.replace("|", r"\|")

return annotation_label

def emit_edge(
self,
from_node: str,
Expand Down
12 changes: 1 addition & 11 deletions pylint/pyreverse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,10 @@ def get_annotation_label(ann: nodes.Name | nodes.NodeNG) -> str:
if isinstance(ann, nodes.Name) and ann.name is not None:
return ann.name # type: ignore[no-any-return]
if isinstance(ann, nodes.NodeNG):
label = ann.as_string()

return escape_vertical_bar(label)
return ann.as_string() # type: ignore[no-any-return]
return ""


def escape_vertical_bar(value: str) -> str:
"""Escapes vertical bar character to make it appear as a literal character
otherwise it gets treated as field separator of record-based nodes.
"""

return value.replace("|", r"\|")


def get_annotation(
node: nodes.AssignAttr | nodes.AssignName,
) -> nodes.Name | nodes.Subscript | None:
Expand Down

0 comments on commit a5864f0

Please sign in to comment.