Skip to content

Commit d876306

Browse files
committed
fix: warnings invalid escape sequence
1 parent 8c0f447 commit d876306

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/pyconverter/xml2py/ast_tree.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,18 @@ class Member(Element):
517517

518518

519519
def ponctuaction_whitespace(text, ponctuation):
520-
extra_space = re.findall(f"\S\h+\{ponctuation}", text)
520+
pattern = r"\S\h+\{ponctuation}".format(ponctuation=ponctuation)
521+
extra_space = re.findall(pattern, text)
521522
if extra_space:
522523
for character in list(set(extra_space)): # remove duplicates in extra_space list
523-
assigned_character = "\)" if character[0] == ")" else character[0]
524-
text = re.sub(
525-
f"{assigned_character}\h+\{ponctuation}", f"{assigned_character}{ponctuation}", text
524+
assigned_character = r"\)" if character[0] == ")" else character[0]
525+
pattern = r"{assigned_character}\h+\{ponctuation}".format(
526+
assigned_character=assigned_character, ponctuation=ponctuation
526527
)
528+
repl = r"{assigned_character}{ponctuation}".format(
529+
assigned_character=assigned_character, ponctuation=ponctuation
530+
)
531+
text = re.sub(pattern, repl, text)
527532
return text
528533

529534

@@ -2660,7 +2665,7 @@ def py_docstring(self, custom_functions: CustomFunctions) -> str:
26602665

26612666
# final post-processing
26622667
def replacer(match):
2663-
return match.group().replace("*", r"\*").replace("\\*", "\*")
2668+
return match.group().replace("*", r"\*").replace(r"\\*", r"\*")
26642669

26652670
# sphinx doesn't like asterisk symbols
26662671
docstr = re.sub(r"(?<=\S)\*|(\*\S)", replacer, docstr)
@@ -2716,7 +2721,7 @@ def cmd_replacer(match):
27162721
docstr = re.sub(r"<CMD>[a-z0-9]*</CMD>", cmd_replacer, docstr)
27172722

27182723
def pipe_replacer(match):
2719-
return match.group().replace("|", "\|")
2724+
return match.group().replace("|", r"\|")
27202725

27212726
docstr = re.sub(r"\|(.*)\|", pipe_replacer, docstr)
27222727

0 commit comments

Comments
 (0)