From 8d7ebc732e93471ed88ff2759af0a0cef21a4771 Mon Sep 17 00:00:00 2001 From: Jeff Widman Date: Sun, 20 Sep 2020 22:44:41 -0700 Subject: 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` --- test/suite_clopts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/suite_clopts.py') diff --git a/test/suite_clopts.py b/test/suite_clopts.py index 2048aa2cac..b488a0c084 100644 --- a/test/suite_clopts.py +++ b/test/suite_clopts.py @@ -164,7 +164,7 @@ class case_tshark_dump_glossaries(subprocesstest.SubprocessTestCase): for glossary in glossaries: try: self.log_fd.truncate() - except: + except Exception: pass self.assertRun((cmd_tshark, '-G', glossary), env=base_env) self.assertEqual(self.countOutput(count_stdout=False, count_stderr=True), 0, 'Found error output while printing glossary ' + glossary) -- cgit v1.2.3