[Lldb-commits] [clang] [clang-tools-extra] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] [polly] fix(python): fix invalid escape sequences (PR #91856)
Eisuke Kawashima via lldb-commits
lldb-commits at lists.llvm.org
Sat May 11 12:55:12 PDT 2024
e-kwsm wrote:
> Why do we need to make this change?
The valid escape sequences in Python are listed [here](https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences): `\t`, `\n`, etc.
Invalid ones fixed here seem to be used for regular expression, [re](https://docs.python.org/3/library/re.html), e.g. `\.` for literal dot, `\d` for a digit `[0-9]`.
I use [flake8](https://flake8.pycqa.org/en/latest/) for check.
> Did you use a script to generate this patch?
No. We have choices to fix these:
1. escape backslashes: `"\s"` -> `"\\s"`
2. use raw string: `"\s"` -> `r"\s"`
I thought 2 is simple but actually it does not work for e.g.:
```diff
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -242,7 +242,7 @@ def main():
filename = None
lines_by_file = {}
for line in sys.stdin:
- match = re.search('^\+\+\+\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
+ match = re.search('^\\+\\+\\+\\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
if match:
filename = match.group(2)
if filename is None:
```
Here `\t\n` is valid whereas `\+` is not.
So I manually fixed them.
https://github.com/llvm/llvm-project/pull/91856
More information about the lldb-commits
mailing list