aboutsummaryrefslogtreecommitdiffstats
path: root/tools/check_tfs.py
diff options
context:
space:
mode:
authorJeff Widman <jeff@jeffwidman.com>2020-09-20 22:44:41 -0700
committerJeff Widman <jeff@jeffwidman.com>2020-09-26 04:38:18 +0000
commit8d7ebc732e93471ed88ff2759af0a0cef21a4771 (patch)
treebe5d52d66d3a65df53e5831d62f8b18f3380a635 /tools/check_tfs.py
parentc5926c51e79c9b3b620b9116ab7929afce97d18b (diff)
Fix issues discovered by common python linters
Fix some issues discovered by common python linters including: * switch `None` comparisons to use `is` rather than `==`. Identity != equality, and I've spent 40+ hours before tracking down a subtle bug caused by exactly this issue. Note that this may introduce a problem if one of the scripts is depending on this behavior, in which case the comparison should be changed to `True`/`False` rather than `None`. * Use `except Exception:` as bare `except:` statements have been discouraged for years. Ideally for some of these we'd examine if there were specific exceptions that should be caught, but for now I simply caught all. Again, this could introduce very subtle behavioral changes under Python 2, but IIUC, that was all fixed in Python 3, so safe to move to `except Exception:`. * Use more idiomatic `if not x in y`--> `if x not in y` * Use more idiomatic 2 blank lines. I only did this at the beginning, until I realized how overwhelming this was going to be to apply, then I stopped. * Add a TODO where an undefined function name is called, so will fail whenever that code is run. * Add more idiomatic spacing around `:`. This is also only partially cleaned up, as I gave up when I saw how `asn2wrs.py` was clearly infatuated with the construct. * Various other small cleanups, removed some trailing whitespace and improper indentation that wasn't a multiple of 4, etc. There is still _much_ to do, but I haven't been heavily involved with this project before, so thought this was a sufficient amount to put up and see what the feedback is. Linters that I have enabled which highlighted some of these issues include: * `pylint` * `flake8` * `pycodestyle`
Diffstat (limited to 'tools/check_tfs.py')
-rwxr-xr-xtools/check_tfs.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/check_tfs.py b/tools/check_tfs.py
index a9b9097abe..89581d00f0 100755
--- a/tools/check_tfs.py
+++ b/tools/check_tfs.py
@@ -88,7 +88,7 @@ def findItems(filename):
-def isDissectorFile(filename):
+def is_dissector_file(filename):
p = re.compile('.*packet-.*\.c')
return p.match(filename)
@@ -99,7 +99,7 @@ def findDissectorFilesInFolder(folder):
for f in sorted(os.listdir(folder)):
if should_exit:
return
- if isDissectorFile(f):
+ if is_dissector_file(f):
filename = os.path.join(folder, f)
files.append(filename)
return files
@@ -160,20 +160,20 @@ elif args.commits:
files = [f.decode('utf-8')
for f in subprocess.check_output(command).splitlines()]
# Will examine dissector files only
- files = list(filter(lambda f : isDissectorFile(f), files))
+ files = list(filter(lambda f : is_dissector_file(f), files))
elif args.open:
# Unstaged changes.
command = ['git', 'diff', '--name-only']
files = [f.decode('utf-8')
for f in subprocess.check_output(command).splitlines()]
# Only interested in dissector files.
- files = list(filter(lambda f : isDissectorFile(f), files))
+ files = list(filter(lambda f : is_dissector_file(f), files))
# Staged changes.
command = ['git', 'diff', '--staged', '--name-only']
files_staged = [f.decode('utf-8')
for f in subprocess.check_output(command).splitlines()]
# Only interested in dissector files.
- files_staged = list(filter(lambda f : isDissectorFile(f), files_staged))
+ files_staged = list(filter(lambda f : is_dissector_file(f), files_staged))
for f in files:
files.append(f)
for f in files_staged: