diff options
Diffstat (limited to 'tools/find_deprecated_escaped_characters.py')
-rw-r--r-- | tools/find_deprecated_escaped_characters.py | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/tools/find_deprecated_escaped_characters.py b/tools/find_deprecated_escaped_characters.py index 8015d3a42..6f90001ca 100644 --- a/tools/find_deprecated_escaped_characters.py +++ b/tools/find_deprecated_escaped_characters.py @@ -1,8 +1,8 @@ #! /usr/bin/env python -""" +r""" Look for escape sequences deprecated in Python 3.6. -Python 3.6 deprecates a number of non-escape sequences starting with `\` that +Python 3.6 deprecates a number of non-escape sequences starting with '\' that were accepted before. For instance, '\(' was previously accepted but must now be written as '\\(' or r'\('. @@ -31,38 +31,36 @@ def main(root): None """ - count = 0 - - if sys.version_info[:2] >= (3, 6): - import ast - import tokenize - import warnings - from pathlib import Path - - base = Path(root) - paths = base.rglob("*.py") if base.is_dir() else [base] - for path in paths: - # use tokenize to auto-detect encoding on systems where no - # default encoding is defined (e.g. LANG='C') - with tokenize.open(str(path)) as f: - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - tree = ast.parse(f.read()) - if w: - print("file: ", str(path)) - for e in w: - print('line: ', e.lineno, ': ', e.message) - print() - count += len(w) - else: - raise RuntimeError("Python version must be >= 3.6") + import ast + import tokenize + import warnings + from pathlib import Path + count = 0 + base = Path(root) + paths = base.rglob("*.py") if base.is_dir() else [base] + for path in paths: + # use tokenize to auto-detect encoding on systems where no + # default encoding is defined (e.g. LANG='C') + with tokenize.open(str(path)) as f: + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + tree = ast.parse(f.read()) + if w: + print("file: ", str(path)) + for e in w: + print('line: ', e.lineno, ': ', e.message) + print() + count += len(w) print("Errors Found", count) if __name__ == "__main__": from argparse import ArgumentParser + if sys.version_info[:2] < (3, 6): + raise RuntimeError("Python version must be >= 3.6") + parser = ArgumentParser(description="Find deprecated escaped characters") parser.add_argument('root', help='directory or file to be checked') args = parser.parse_args() |