Skip to content

Commit

Permalink
Use raw strings when using \.
Browse files Browse the repository at this point in the history
The sequence `\.` is an undefined escape sequence, but can be found in regex-strings. In regex strings, we usually want the backslash character and the dot character, instead of escaping dot like if it was a tab character `\t`. This is what raw strings (strings prefixed with r) do: they treat backslashes as literal characters.

In Python 3.12, using `\.` in a string (not raw strings) raises `SyntaxWarning: invalid escape sequence '\.'`
  • Loading branch information
echoix committed Dec 26, 2023
1 parent 9821bac commit aa8951a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions gui/wxpython/core/globalvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ def UpdateGRASSAddOnCommands(eList=None):
os.environ["PATH"] = os.path.join(GUIDIR, "scripts") + os.pathsep + os.environ["PATH"]

ignoredCmdPattern = (
"^d\..*|^r[3]?\.mapcalc$|^i.group$|^r.import$|"
"^r.external$|^r.external.out$|"
"^v.import$|^v.external$|^v.external.out$|"
"^cd$|^cd .*"
r"^d\..*|^r[3]?\.mapcalc$|^i.group$|^r.import$|"
r"^r.external$|^r.external.out$|"
r"^v.import$|^v.external$|^v.external.out$|"
r"^cd$|^cd .*"
)
4 changes: 2 additions & 2 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,9 @@ def _switchPage(self, notification):

def RunSpecialCmd(self, command):
"""Run command from command line, check for GUI wrappers"""
if re.compile("^d\..*").search(command[0]):
if re.compile(r"^d\..*").search(command[0]):
self.RunDisplayCmd(command)
elif re.compile("r[3]?\.mapcalc").search(command[0]):
elif re.compile(r"r[3]?\.mapcalc").search(command[0]):
self.OnMapCalculator(event=None, cmd=command)
elif command[0] == "i.group":
self.OnEditImageryGroups(event=None, cmd=command)
Expand Down
2 changes: 1 addition & 1 deletion lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def f(fmt, *args):
matches = []
# https://docs.python.org/3/library/stdtypes.html#old-string-formatting
for m in re.finditer(
"%([#0 +-]*)([0-9]*)(\.[0-9]*)?([hlL]?[diouxXeEfFgGcrsa%])", fmt
r"%([#0 +-]*)([0-9]*)(\.[0-9]*)?([hlL]?[diouxXeEfFgGcrsa%])", fmt
):
matches.append(m)

Expand Down

0 comments on commit aa8951a

Please sign in to comment.