summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-02-25 07:45:43 -0700
committerCharles Harris <charlesr.harris@gmail.com>2017-02-25 07:50:15 -0700
commitead991be337d7c7213f7489b43bda2f74decec6c (patch)
tree3ebd18ae30236d60528c5e2df13a35b481ef77d8 /tools
parente5110fa81540103800da34c2199a0e2823031f98 (diff)
downloadpython-numpy-ead991be337d7c7213f7489b43bda2f74decec6c.tar.gz
python-numpy-ead991be337d7c7213f7489b43bda2f74decec6c.tar.bz2
python-numpy-ead991be337d7c7213f7489b43bda2f74decec6c.zip
MAINT: Refactor tools/find_deprecated_escaped_characters.py
Make the code a bit cleaner.
Diffstat (limited to 'tools')
-rw-r--r--tools/find_deprecated_escaped_characters.py48
1 files changed, 23 insertions, 25 deletions
diff --git a/tools/find_deprecated_escaped_characters.py b/tools/find_deprecated_escaped_characters.py
index 1c3cc0d38..6f90001ca 100644
--- a/tools/find_deprecated_escaped_characters.py
+++ b/tools/find_deprecated_escaped_characters.py
@@ -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()