Skip to content

Commit

Permalink
pylint-dev#8603 pylint/pyreverse/utils.py, added escaping of vertic…
Browse files Browse the repository at this point in the history
…al bar character in annotation labels to ensure it is not treated as field separator of record-based nodes
  • Loading branch information
ViRuSTriNiTy committed Apr 23, 2023
1 parent 7826795 commit f2fcee6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pylint/pyreverse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,20 @@ 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):
return ann.as_string() # type: ignore[no-any-return]
label = ann.as_string()

return escape_vertical_bar(label) # 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 f2fcee6

Please sign in to comment.