From 7f994bd345da0d00938e69395045d710b0e3a1f5 Mon Sep 17 00:00:00 2001 From: jugglinmike Date: Tue, 22 May 2018 14:10:06 -0400 Subject: [PATCH] [tools] Disallow unused variables (#11097) --- tools/lint/lint.py | 2 +- tools/lint/tests/test_lint.py | 6 +++--- tools/serve/serve.py | 2 +- tools/tox.ini | 3 +-- tools/webdriver/webdriver/client.py | 2 +- tools/wpt/browser.py | 2 +- tools/wpt/tox.ini | 3 +-- tools/wpt/wpt.py | 2 +- tools/wptrunner/test/test.py | 2 +- tools/wptrunner/tox.ini | 3 +-- tools/wptrunner/wptrunner/executors/base.py | 5 ++--- tools/wptrunner/wptrunner/executors/executormarionette.py | 5 +---- tools/wptrunner/wptrunner/executors/executorservodriver.py | 1 - tools/wptrunner/wptrunner/manifestexpected.py | 2 -- tools/wptrunner/wptrunner/metadata.py | 2 -- tools/wptrunner/wptrunner/products.py | 3 --- tools/wptrunner/wptrunner/tests/test_products.py | 2 +- tools/wptrunner/wptrunner/wptrunner.py | 2 -- tools/wptserve/tests/functional/test_server.py | 4 ++-- 19 files changed, 18 insertions(+), 35 deletions(-) diff --git a/tools/lint/lint.py b/tools/lint/lint.py index c1ffd50fb2b6f3..058ee2bbd2394e 100644 --- a/tools/lint/lint.py +++ b/tools/lint/lint.py @@ -157,7 +157,7 @@ def check_git_ignore(repo_root, paths): if filter_string[0] != '!': errors += [("IGNORED PATH", "%s matches an ignore filter in .gitignore - " "please add a .gitignore exception" % path, path, None)] - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError: # Nonzero return code means that no match exists. pass return errors diff --git a/tools/lint/tests/test_lint.py b/tools/lint/tests/test_lint.py index 2899b1dfa233f4..c593c849d88307 100644 --- a/tools/lint/tests/test_lint.py +++ b/tools/lint/tests/test_lint.py @@ -409,7 +409,7 @@ def test_all_filesystem_paths(): (os.path.join('.', 'dir_a'), [], ['file_c', 'file_d'])] - ) as m: + ): got = list(lint_mod.all_filesystem_paths('.')) assert got == ['file_a', 'file_b', @@ -438,7 +438,7 @@ def test_main_no_args(): try: sys.argv = ['./lint'] with _mock_lint('lint', return_value=True) as m: - with _mock_lint('changed_files', return_value=['foo', 'bar']) as m2: + with _mock_lint('changed_files', return_value=['foo', 'bar']): lint_mod.main(**vars(create_parser().parse_args())) m.assert_called_once_with(repo_root, ['foo', 'bar'], "normal") finally: @@ -450,7 +450,7 @@ def test_main_all(): try: sys.argv = ['./lint', '--all'] with _mock_lint('lint', return_value=True) as m: - with _mock_lint('all_filesystem_paths', return_value=['foo', 'bar']) as m2: + with _mock_lint('all_filesystem_paths', return_value=['foo', 'bar']): lint_mod.main(**vars(create_parser().parse_args())) m.assert_called_once_with(repo_root, ['foo', 'bar'], "normal") finally: diff --git a/tools/serve/serve.py b/tools/serve/serve.py index 0fd5f907e96401..d61c9f2a68a98e 100644 --- a/tools/serve/serve.py +++ b/tools/serve/serve.py @@ -434,7 +434,7 @@ def check_subdomains(config): try: urllib2.urlopen("http://%s:%d/" % (domain, port)) - except Exception as e: + except Exception: logger.critical("Failed probing domain %s. " "You may need to edit /etc/hosts or similar, see README.md." % domain) sys.exit(1) diff --git a/tools/tox.ini b/tools/tox.ini index 1db1b4ebb7ab20..732dab8bc5c1da 100644 --- a/tools/tox.ini +++ b/tools/tox.ini @@ -42,9 +42,8 @@ select = E,W,F,N # F401: module imported but unused # F403: ‘from module import *’ used; unable to detect undefined names # F405: name may be undefined, or defined from star imports: module -# F841: local variable name is assigned to but never used # N801: class names should use CapWords convention # N802: function name should be lowercase -ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,F841,N801,N802 +ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,N801,N802 max-line-length = 141 exclude = .tox,html5lib,third_party/py,third_party/pytest,third_party/funcsigs,third_party/attrs,third_party/pluggy/,pywebsocket,six,_venv,webencodings,wptserve/docs,wptserve/tests/functional/docroot/,wpt,wptrunner diff --git a/tools/webdriver/webdriver/client.py b/tools/webdriver/webdriver/client.py index a8abda0b2fcf28..45c4845e0941f9 100644 --- a/tools/webdriver/webdriver/client.py +++ b/tools/webdriver/webdriver/client.py @@ -39,7 +39,7 @@ def _get(self, key=None): def _set(self, key, secs): body = {key: secs * 1000} - timeouts = self.session.send_session_command("POST", "timeouts", body) + self.session.send_session_command("POST", "timeouts", body) return None @property diff --git a/tools/wpt/browser.py b/tools/wpt/browser.py index 1932cf4f4ba73a..de9f92989bc55c 100644 --- a/tools/wpt/browser.py +++ b/tools/wpt/browser.py @@ -112,7 +112,7 @@ def install(self, dest=None): try: mozinstall.install(filename, dest) - except mozinstall.mozinstall.InstallError as e: + except mozinstall.mozinstall.InstallError: if platform == "mac" and os.path.exists(os.path.join(dest, "Firefox Nightly.app")): # mozinstall will fail if nightly is already installed in the venv because # mac installation uses shutil.copy_tree diff --git a/tools/wpt/tox.ini b/tools/wpt/tox.ini index 229bc4bfc5c502..6426f6fb55bdc4 100644 --- a/tools/wpt/tox.ini +++ b/tools/wpt/tox.ini @@ -45,8 +45,7 @@ select = E,W,F,N # F401: module imported but unused # F403: ‘from module import *’ used; unable to detect undefined names # F405: name may be undefined, or defined from star imports: module -# F841: local variable name is assigned to but never used # N801: class names should use CapWords convention # N802: function name should be lowercase -ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,F841,N801,N802 +ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,N801,N802 max-line-length = 141 diff --git a/tools/wpt/wpt.py b/tools/wpt/wpt.py index 49f463d2a9ed1e..882d5ab2ac9140 100644 --- a/tools/wpt/wpt.py +++ b/tools/wpt/wpt.py @@ -46,7 +46,7 @@ def parse_args(argv, commands): parser.add_argument("--debug", action="store_true", help="Run the debugger in case of an exception") subparsers = parser.add_subparsers(dest="command") for command, props in iteritems(commands): - sub_parser = subparsers.add_parser(command, help=props["help"], add_help=False) + subparsers.add_parser(command, help=props["help"], add_help=False) args, extra = parser.parse_known_args(argv) diff --git a/tools/wptrunner/test/test.py b/tools/wptrunner/test/test.py index 622934a42b0cc0..3e82a9813d5c0c 100644 --- a/tools/wptrunner/test/test.py +++ b/tools/wptrunner/test/test.py @@ -73,7 +73,7 @@ def read_config(): # This only allows one product per whatever for now for product in parser.sections(): if product != "general": - dest = rv["products"][product] = {} + rv["products"][product] = {} for key, value in parser.items(product): rv["products"][product][key] = value diff --git a/tools/wptrunner/tox.ini b/tools/wptrunner/tox.ini index f63e2c0cea07e2..a9761e80d8b5d5 100644 --- a/tools/wptrunner/tox.ini +++ b/tools/wptrunner/tox.ini @@ -55,8 +55,7 @@ select = E,W,F,N # F401: module imported but unused # F403: ‘from module import *’ used; unable to detect undefined names # F405: name may be undefined, or defined from star imports: module -# F841: local variable name is assigned to but never used # N801: class names should use CapWords convention # N802: function name should be lowercase -ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,F841,N801,N802 +ignore = E128,E129,E221,E226,E231,E251,E265,E302,E303,E305,E402,E731,E901,W601,F401,F403,F405,N801,N802 max-line-length = 141 diff --git a/tools/wptrunner/wptrunner/executors/base.py b/tools/wptrunner/wptrunner/executors/base.py index 08030b3f5f9277..1e662b0330a4f7 100644 --- a/tools/wptrunner/wptrunner/executors/base.py +++ b/tools/wptrunner/wptrunner/executors/base.py @@ -243,7 +243,6 @@ def logger(self): return self.executor.logger def get_hash(self, test, viewport_size, dpi): - timeout = test.timeout * self.timeout_multiplier key = (test.url, viewport_size, dpi) if key not in self.screenshot_cache: @@ -391,7 +390,7 @@ def run(self): executor = threading.Thread(target=self._run) executor.start() - flag = self.result_flag.wait(self.timeout) + self.result_flag.wait(self.timeout) if self.result[1] is None: self.result = False, ("EXTERNAL-TIMEOUT", None) @@ -533,7 +532,7 @@ def process_action(self, url, payload): raise ValueError("Unknown action %s" % action) try: action_handler(payload) - except Exception as e: + except Exception: self.logger.warning("Action %s failed" % action) self.logger.warning(traceback.format_exc()) self._send_message("complete", "failure") diff --git a/tools/wptrunner/wptrunner/executors/executormarionette.py b/tools/wptrunner/wptrunner/executors/executormarionette.py index bff509c53c6028..f04f0b58284b82 100644 --- a/tools/wptrunner/wptrunner/executors/executormarionette.py +++ b/tools/wptrunner/wptrunner/executors/executormarionette.py @@ -445,7 +445,7 @@ def run(self): else: wait_timeout = None - flag = self.result_flag.wait(wait_timeout) + self.result_flag.wait(wait_timeout) if self.result == (None, None): self.logger.debug("Timed out waiting for a result") @@ -675,9 +675,6 @@ def setup(self, screenshot="unexpected"): self.executor.protocol.marionette._send_message("reftest:setup", data) def run_test(self, test): - viewport_size = test.viewport_size - dpi = test.dpi - references = self.get_references(test) rv = self.executor.protocol.marionette._send_message("reftest:run", {"test": self.executor.test_url(test), diff --git a/tools/wptrunner/wptrunner/executors/executorservodriver.py b/tools/wptrunner/wptrunner/executors/executorservodriver.py index 626c987f26e255..f649a75cd93f05 100644 --- a/tools/wptrunner/wptrunner/executors/executorservodriver.py +++ b/tools/wptrunner/wptrunner/executors/executorservodriver.py @@ -35,7 +35,6 @@ def __init__(self, executor, browser, capabilities, **kwargs): def connect(self): """Connect to browser via WebDriver.""" - url = "http://%s:%d" % (self.host, self.port) self.session = webdriver.Session(self.host, self.port, extension=webdriver.servo.ServoCommandExtensions) self.session.start() diff --git a/tools/wptrunner/wptrunner/manifestexpected.py b/tools/wptrunner/wptrunner/manifestexpected.py index 5d57b70e517c08..eaab26081bd066 100644 --- a/tools/wptrunner/wptrunner/manifestexpected.py +++ b/tools/wptrunner/wptrunner/manifestexpected.py @@ -53,8 +53,6 @@ def value(ini_value): try: node_prefs = node.get("prefs") - if type(node_prefs) in (str, unicode): - prefs = {value(node_prefs)} rv = dict(value(item) for item in node_prefs) except KeyError: rv = {} diff --git a/tools/wptrunner/wptrunner/metadata.py b/tools/wptrunner/wptrunner/metadata.py index 92d77ba8d94fe8..195671ca564cfa 100644 --- a/tools/wptrunner/wptrunner/metadata.py +++ b/tools/wptrunner/wptrunner/metadata.py @@ -119,8 +119,6 @@ def unexpected_changes(manifests, change_data, files_changed): else: return [] - rv = [] - return [fn for _, fn, _ in root_manifest if fn in files_changed and change_data.get(fn) != "M"] # For each testrun diff --git a/tools/wptrunner/wptrunner/products.py b/tools/wptrunner/wptrunner/products.py index c077f95dfd956b..4f2273743ec067 100644 --- a/tools/wptrunner/wptrunner/products.py +++ b/tools/wptrunner/wptrunner/products.py @@ -12,9 +12,6 @@ def products_enabled(config): return names def product_module(config, product): - here = os.path.join(os.path.split(__file__)[0]) - product_dir = os.path.join(here, "browsers") - if product not in products_enabled(config): raise ValueError("Unknown product %s" % product) diff --git a/tools/wptrunner/wptrunner/tests/test_products.py b/tools/wptrunner/wptrunner/tests/test_products.py index 8ece29b8294113..f5d490de25cb14 100644 --- a/tools/wptrunner/wptrunner/tests/test_products.py +++ b/tools/wptrunner/wptrunner/tests/test_products.py @@ -52,7 +52,7 @@ def test_server_start_config(product): False, None, env_options, - env_extras) as test_environment: + env_extras): start.assert_called_once() args = start.call_args config = args[0][0] diff --git a/tools/wptrunner/wptrunner/wptrunner.py b/tools/wptrunner/wptrunner/wptrunner.py index bd2b3ad23bd0e2..3ee4480a530d42 100644 --- a/tools/wptrunner/wptrunner/wptrunner.py +++ b/tools/wptrunner/wptrunner/wptrunner.py @@ -110,8 +110,6 @@ def list_disabled(test_paths, product, **kwargs): def list_tests(test_paths, product, **kwargs): env.do_delayed_imports(logger, test_paths) - rv = [] - ssl_env = env.ssl_env(logger, **kwargs) run_info_extras = products.load_product(kwargs["config"], product)[-1](**kwargs) diff --git a/tools/wptserve/tests/functional/test_server.py b/tools/wptserve/tests/functional/test_server.py index 26c34c31002ca8..7ae31be713090a 100644 --- a/tools/wptserve/tests/functional/test_server.py +++ b/tools/wptserve/tests/functional/test_server.py @@ -10,7 +10,7 @@ class TestFileHandler(TestUsingServer): def test_not_handled(self): with self.assertRaises(HTTPError) as cm: - resp = self.request("/not_existing") + self.request("/not_existing") self.assertEqual(cm.exception.code, 404) @@ -36,7 +36,7 @@ def handler(request, response): route = ("GET", "/test/raises", handler) self.server.router.register(*route) with self.assertRaises(HTTPError) as cm: - resp = self.request("/test/raises") + self.request("/test/raises") self.assertEqual(cm.exception.code, 500)