3
Look for escape sequences deprecated in Python 3.6.
5
Python 3.6 deprecates a number of non-escape sequences starting with '\' that
6
were accepted before. For instance, '\(' was previously accepted but must now
7
be written as '\\(' or r'\('.
13
"""Find deprecated escape sequences.
15
Checks for deprecated escape sequences in ``*.py files``. If `root` is a
16
file, that file is checked, if `root` is a directory all ``*.py`` files
17
found in a recursive descent are checked.
19
If a deprecated escape sequence is found, the file and line where found is
20
printed. Note that for multiline strings the line where the string ends is
21
printed and the error(s) are somewhere in the body of the string.
26
File or directory to check.
35
from pathlib import Path
39
paths = base.rglob("*.py") if base.is_dir() else [base]
43
with tokenize.open(str(path)) as f:
44
with warnings.catch_warnings(record=True) as w:
45
warnings.simplefilter('always')
46
tree = ast.parse(f.read())
48
print("file: ", str(path))
50
print('line: ', e.lineno, ': ', e.message)
53
print("Errors Found", count)
56
if __name__ == "__main__":
57
from argparse import ArgumentParser
59
parser = ArgumentParser(description="Find deprecated escaped characters")
60
parser.add_argument('root', help='directory or file to be checked')
61
args = parser.parse_args()