commit 040998e094c02be42ee00f9ebd35854992568959 parent 7cc77b1400dcb4332477de795d3cf9b13d10b108 Author: Alex Hochheiden <ahochheiden@mozilla.com> Date: Wed, 10 Dec 2025 06:03:23 +0000 Bug 2003412 - Fix PLR1704 warnings: Avoid redefining argument with local variable r=emilio,perftest-reviewers,mozperftest-reviewers,taskgraph-reviewers,releng-reviewers,toolkit-telemetry-reviewers,jdescottes,bhearsum,sparky https://docs.astral.sh/ruff/rules/redefined-argument-from-local/ Differential Revision: https://phabricator.services.mozilla.com/D274691 Diffstat:
28 files changed, 198 insertions(+), 184 deletions(-)
diff --git a/build/checksums.py b/build/checksums.py @@ -58,7 +58,7 @@ def process_files(dirs, output_filename, digests): logger.debug('Creating a new checksums file "%s"' % output_filename) with open(output_filename, "w+") as output: for d in dirs: - for root, dirs, files in os.walk(d): + for root, _, files in os.walk(d): for f in sorted(files): full = os.path.join(root, f) rel = os.path.relpath(full, d) diff --git a/modules/libpref/init/generate_static_pref_list.py b/modules/libpref/init/generate_static_pref_list.py @@ -455,21 +455,23 @@ def emit_code(fd, *pref_list_filenames): init_dirname = os.path.dirname(fd.name) dirname = os.path.dirname(init_dirname) - with FileAvoidWrite(os.path.join(dirname, "StaticPrefsAll.h")) as fd: - fd.write(code["static_prefs_all_h"]) + with FileAvoidWrite(os.path.join(dirname, "StaticPrefsAll.h")) as output_file: + output_file.write(code["static_prefs_all_h"]) for group, text in sorted(code["static_pref_list_group_h"].items()): filename = f"StaticPrefList_{group}.h" - with FileAvoidWrite(os.path.join(init_dirname, filename)) as fd: - fd.write(text) + with FileAvoidWrite(os.path.join(init_dirname, filename)) as group_file: + group_file.write(text) for group, text in sorted(code["static_prefs_group_h"].items()): filename = f"StaticPrefs_{group}.h" - with FileAvoidWrite(os.path.join(dirname, filename)) as fd: - fd.write(text) + with FileAvoidWrite(os.path.join(dirname, filename)) as prefs_file: + prefs_file.write(text) - with FileAvoidWrite(os.path.join(init_dirname, "StaticPrefsCGetters.cpp")) as fd: - fd.write(code["static_prefs_c_getters_cpp"]) + with FileAvoidWrite( + os.path.join(init_dirname, "StaticPrefsCGetters.cpp") + ) as cpp_file: + cpp_file.write(code["static_prefs_c_getters_cpp"]) - with FileAvoidWrite(os.path.join(dirname, "static_prefs.rs")) as fd: - fd.write(code["static_prefs_rs"]) + with FileAvoidWrite(os.path.join(dirname, "static_prefs.rs")) as rust_file: + rust_file.write(code["static_prefs_rs"]) diff --git a/python/mozbuild/mozbuild/action/process_define_files.py b/python/mozbuild/mozbuild/action/process_define_files.py @@ -37,11 +37,11 @@ def process_define_file(output, input): ) and not config.substs.get("JS_STANDALONE"): config = PartialConfigEnvironment(mozpath.join(topobjdir, "js", "src")) - with open(path) as input: + with open(path) as input_file: r = re.compile( r"^\s*#\s*(?P<cmd>[a-z]+)(?:\s+(?P<name>\S+)(?:\s+(?P<value>\S+))?)?", re.U ) - for l in input: + for l in input_file: m = r.match(l) if m: cmd = m.group("cmd") diff --git a/python/mozbuild/mozbuild/action/tooltool.py b/python/mozbuild/mozbuild/action/tooltool.py @@ -991,9 +991,11 @@ class TarFile(tarfile.TarFile): extract(member, path, set_attrs, numeric_owner=numeric_owner, **kwargs) if deferred_links is not None: - for tarinfo, linkpath, numeric_owner in deferred_links.pop(targetpath, []): + for tarinfo, linkpath, deferred_numeric_owner in deferred_links.pop( + targetpath, [] + ): shutil.copy(targetpath, linkpath) - self.chown(tarinfo, linkpath, numeric_owner) + self.chown(tarinfo, linkpath, deferred_numeric_owner) self._extracted_members.add(targetpath) def extract(self, *args, **kwargs): diff --git a/python/mozbuild/mozbuild/artifacts.py b/python/mozbuild/mozbuild/artifacts.py @@ -330,11 +330,11 @@ class ArtifactJob: with self.get_writer(file=processed_filename, compress_level=5) as writer: reader = JarReader(filename) - for filename, entry in reader.entries.items(): + for entry_filename, entry in reader.entries.items(): for pattern, (src_prefix, dest_prefix) in self.test_artifact_patterns: - if not mozpath.match(filename, pattern): + if not mozpath.match(entry_filename, pattern): continue - destpath = mozpath.relpath(filename, src_prefix) + destpath = mozpath.relpath(entry_filename, src_prefix) destpath = mozpath.join(dest_prefix, destpath) self.log( logging.DEBUG, @@ -343,35 +343,37 @@ class ArtifactJob: "Adding {destpath} to processed archive", ) mode = entry["external_attr"] >> 16 - writer.add(destpath.encode("utf-8"), reader[filename], mode=mode) + writer.add( + destpath.encode("utf-8"), reader[entry_filename], mode=mode + ) added_entry = True break - if filename.endswith(".toml"): + if entry_filename.endswith(".toml"): # The artifact build writes test .toml files into the object # directory; they don't come from the upstream test archive. self.log( logging.DEBUG, "artifact", - {"filename": filename}, + {"filename": entry_filename}, "Skipping test INI file {filename}", ) continue for files_entry in OBJDIR_TEST_FILES.values(): origin_pattern = files_entry["pattern"] - leaf_filename = filename + leaf_filename = entry_filename if "dest" in files_entry: dest = files_entry["dest"] origin_pattern = mozpath.join(dest, origin_pattern) - leaf_filename = filename[len(dest) + 1 :] - if mozpath.match(filename, origin_pattern): + leaf_filename = entry_filename[len(dest) + 1 :] + if mozpath.match(entry_filename, origin_pattern): destpath = mozpath.join( "..", files_entry["base"], leaf_filename ) mode = entry["external_attr"] >> 16 writer.add( - destpath.encode("utf-8"), reader[filename], mode=mode + destpath.encode("utf-8"), reader[entry_filename], mode=mode ) if not added_entry: @@ -384,15 +386,15 @@ class ArtifactJob: from mozbuild.action.test_archive import OBJDIR_TEST_FILES added_entry = False - for filename, entry in TarFinder(filename, stream): + for tar_entry_filename, entry in TarFinder(filename, stream): for ( pattern, (src_prefix, dest_prefix), ) in self.test_artifact_patterns: - if not mozpath.match(filename, pattern): + if not mozpath.match(tar_entry_filename, pattern): continue - destpath = mozpath.relpath(filename, src_prefix) + destpath = mozpath.relpath(tar_entry_filename, src_prefix) destpath = mozpath.join(dest_prefix, destpath) self.log( logging.DEBUG, @@ -405,25 +407,25 @@ class ArtifactJob: added_entry = True break - if filename.endswith(".toml"): + if tar_entry_filename.endswith(".toml"): # The artifact build writes test .toml files into the object # directory; they don't come from the upstream test archive. self.log( logging.DEBUG, "artifact", - {"filename": filename}, + {"filename": tar_entry_filename}, "Skipping test INI file {filename}", ) continue for files_entry in OBJDIR_TEST_FILES.values(): origin_pattern = files_entry["pattern"] - leaf_filename = filename + leaf_filename = tar_entry_filename if "dest" in files_entry: dest = files_entry["dest"] origin_pattern = mozpath.join(dest, origin_pattern) - leaf_filename = filename[len(dest) + 1 :] - if mozpath.match(filename, origin_pattern): + leaf_filename = tar_entry_filename[len(dest) + 1 :] + if mozpath.match(tar_entry_filename, origin_pattern): destpath = mozpath.join("..", files_entry["base"], leaf_filename) mode = entry.mode writer.add(destpath.encode("utf-8"), entry.open(), mode=mode) @@ -454,16 +456,16 @@ class ArtifactJob: self, filename, processed_filename, skip_compressed=False ): with self.get_writer(file=processed_filename, compress_level=5) as writer: - for filename, entry in self.iter_artifact_archive(filename): - if skip_compressed and filename.endswith(".gz"): + for archive_filename, entry in self.iter_artifact_archive(filename): + if skip_compressed and archive_filename.endswith(".gz"): self.log( logging.DEBUG, "artifact", - {"filename": filename}, + {"filename": archive_filename}, "Skipping compressed ELF debug symbol file {filename}", ) continue - destpath = mozpath.join("crashreporter-symbols", filename) + destpath = mozpath.join("crashreporter-symbols", archive_filename) self.log( logging.INFO, "artifact", @@ -489,17 +491,17 @@ class ArtifactJob: dest_prefix = extra_archive["dest_prefix"] with self.get_writer(file=processed_filename, compress_level=5) as writer: - for filename, entry in self.iter_artifact_archive(filename): - if not filename.startswith(src_prefix): + for extra_filename, entry in self.iter_artifact_archive(filename): + if not extra_filename.startswith(src_prefix): self.log( logging.DEBUG, "artifact", - {"filename": filename, "src_prefix": src_prefix}, + {"filename": extra_filename, "src_prefix": src_prefix}, "Skipping extra archive item {filename} " "that does not start with {src_prefix}", ) continue - destpath = mozpath.relpath(filename, src_prefix) + destpath = mozpath.relpath(extra_filename, src_prefix) destpath = mozpath.join(dest_prefix, destpath) self.log( logging.INFO, @@ -512,8 +514,8 @@ class ArtifactJob: def iter_artifact_archive(self, filename): if filename.endswith(".zip"): reader = JarReader(filename) - for filename in reader.entries: - yield filename, reader[filename] + for entry_name in reader.entries: + yield entry_name, reader[entry_name] elif filename.endswith(".tar.zst") and self._mozbuild is not None: self._mozbuild._ensure_zstd() import zstandard @@ -599,8 +601,8 @@ class AndroidArtifactJob(ArtifactJob): import gzip with self.get_writer(file=processed_filename, compress_level=5) as writer: - for filename, entry in self.iter_artifact_archive(filename): - if not filename.endswith(".gz"): + for symbols_filename, entry in self.iter_artifact_archive(filename): + if not symbols_filename.endswith(".gz"): continue # Uncompress "libxul.so/D3271457813E976AE7BF5DAFBABABBFD0/libxul.so.dbg.gz" @@ -612,7 +614,7 @@ class AndroidArtifactJob(ArtifactJob): # # There are other paths that will work but none seem more desireable. See # https://github.com/llvm-mirror/lldb/blob/882670690ca69d9dd96b7236c620987b11894af9/source/Host/common/Symbols.cpp#L324. - basename = os.path.basename(filename).replace(".gz", "") + basename = os.path.basename(symbols_filename).replace(".gz", "") destpath = mozpath.join("crashreporter-symbols", basename) self.log( logging.DEBUG, diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -1588,8 +1588,8 @@ class RecursiveMakeBackend(MakeBackend): install_manifest = self._install_manifests[manifest] reltarget = mozpath.relpath(target, path) - for path, files in files.walk(): - target_var = (mozpath.join(target, path) if path else target).replace( + for subpath, subfiles in files.walk(): + target_var = (mozpath.join(target, subpath) if subpath else target).replace( "/", "_" ) # We don't necessarily want to combine these, because non-wildcard @@ -1599,9 +1599,9 @@ class RecursiveMakeBackend(MakeBackend): objdir_files = [] absolute_files = [] - for f in files: + for f in subfiles: assert not isinstance(f, RenamedSourcePath) - dest_dir = mozpath.join(reltarget, path) + dest_dir = mozpath.join(reltarget, subpath) dest_file = mozpath.join(dest_dir, f.target_basename) if not isinstance(f, ObjDirPath): if "*" in f: @@ -1632,7 +1632,7 @@ class RecursiveMakeBackend(MakeBackend): else: install_manifest.add_optional_exists(dest_file) objdir_files.append(self._pretty_path(f, backend_file)) - install_location = "$(DEPTH)/%s" % mozpath.join(target, path) + install_location = "$(DEPTH)/%s" % mozpath.join(target, subpath) if objdir_files: tier = "export" if obj.install_target == "dist/include" else "misc" # We cannot generate multilocale.txt during misc at the moment. @@ -1664,16 +1664,16 @@ class RecursiveMakeBackend(MakeBackend): # Note that if this becomes a manifest, OBJDIR_PP_FILES will likely # still need to use PP_TARGETS internally because we can't have an # install manifest for the root of the objdir. - for i, (path, files) in enumerate(files.walk()): + for i, (walk_path, walk_files) in enumerate(files.walk()): self._no_skip["misc"].add(backend_file.relobjdir) var = "%s_%d" % (name, i) - for f in files: + for f in walk_files: backend_file.write( "%s += %s\n" % (var, self._pretty_path(f, backend_file)) ) backend_file.write( "%s_PATH := $(DEPTH)/%s\n" - % (var, mozpath.join(obj.install_target, path)) + % (var, mozpath.join(obj.install_target, walk_path)) ) backend_file.write("%s_TARGET := misc\n" % var) backend_file.write("PP_TARGETS += %s\n" % var) @@ -1705,13 +1705,13 @@ class RecursiveMakeBackend(MakeBackend): path = mozpath.basedir(target, ("dist/bin",)) if not path: raise Exception("Cannot install localized files to " + target) - for i, (path, files) in enumerate(files.walk()): + for i, (walk_path, walk_files) in enumerate(files.walk()): name = "LOCALIZED_FILES_%d" % i self._no_skip["misc"].add(backend_file.relobjdir) - self._write_localized_files_files(files, name + "_FILES", backend_file) + self._write_localized_files_files(walk_files, name + "_FILES", backend_file) # Use FINAL_TARGET here because some l10n repack rules set # XPI_NAME to generate langpacks. - backend_file.write("%s_DEST = $(FINAL_TARGET)/%s\n" % (name, path)) + backend_file.write("%s_DEST = $(FINAL_TARGET)/%s\n" % (name, walk_path)) backend_file.write("%s_TARGET := misc\n" % name) backend_file.write("INSTALL_TARGETS += %s\n" % name) @@ -1720,10 +1720,10 @@ class RecursiveMakeBackend(MakeBackend): path = mozpath.basedir(target, ("dist/bin",)) if not path: raise Exception("Cannot install localized files to " + target) - for i, (path, files) in enumerate(files.walk()): + for i, (path, file_list) in enumerate(files.walk()): name = "LOCALIZED_PP_FILES_%d" % i self._no_skip["misc"].add(backend_file.relobjdir) - self._write_localized_files_files(files, name, backend_file) + self._write_localized_files_files(file_list, name, backend_file) # Use FINAL_TARGET here because some l10n repack rules set # XPI_NAME to generate langpacks. backend_file.write("%s_PATH = $(FINAL_TARGET)/%s\n" % (name, path)) @@ -1740,9 +1740,9 @@ class RecursiveMakeBackend(MakeBackend): # We can't use an install manifest for the root of the objdir, since it # would delete all the other files that get put there by the build # system. - for i, (path, files) in enumerate(files.walk()): + for i, (path, file_list) in enumerate(files.walk()): self._no_skip["misc"].add(backend_file.relobjdir) - for f in files: + for f in file_list: backend_file.write( "OBJDIR_%d_FILES += %s\n" % (i, self._pretty_path(f, backend_file)) ) diff --git a/python/mozbuild/mozbuild/frontend/reader.py b/python/mozbuild/mozbuild/frontend/reader.py @@ -1407,9 +1407,9 @@ class BuildReader: all_contexts.append(context) result = {} - for path, paths in path_mozbuilds.items(): + for path, mozbuild_paths in path_mozbuilds.items(): result[path] = functools.reduce( - lambda x, y: x + y, (contexts[p] for p in paths), [] + lambda x, y: x + y, (contexts[p] for p in mozbuild_paths), [] ) return result, all_contexts diff --git a/python/mozbuild/mozbuild/test/configure/test_bootstrap.py b/python/mozbuild/mozbuild/test/configure/test_bootstrap.py @@ -97,10 +97,10 @@ class TestBootstrap(BaseConfigureTest): for t in toolchains: exec(f'{t} = bootstrap_search_path("{t}")', sandbox) sandbox._wrapped_importlib = ReadOnlyNamespace(import_module=self.import_module) - for t, in_path, b, state in zip(toolchains, in_path, bootstrapped, states): - if in_path == "append": + for t, in_path_item, b, state in zip(toolchains, in_path, bootstrapped, states): + if in_path_item == "append": expected = ["dummy", mozpath.join(tmp_dir.name, t)] - elif in_path: + elif in_path_item: expected = [mozpath.join(tmp_dir.name, t), "dummy"] else: expected = ["dummy"] diff --git a/python/mozbuild/mozbuild/util.py b/python/mozbuild/mozbuild/util.py @@ -1120,8 +1120,8 @@ def expand_variables(s, variables): If a variable value is not a string, it is iterated and its items are joined with a whitespace.""" result = "" - for s, name in pair(VARIABLES_RE.split(s)): - result += s + for text_part, name in pair(VARIABLES_RE.split(s)): + result += text_part value = variables.get(name) if not value: continue diff --git a/python/mozbuild/mozpack/manifests.py b/python/mozbuild/mozpack/manifests.py @@ -250,9 +250,9 @@ class InstallManifest: type = self.LINK if type == self.PATTERN_LINK else self.COPY finder = FileFinder(base) paths = [f[0] for f in finder.find(pattern)] - for path in paths: - source = mozpath.join(base, path) - parts = ["%d" % type, mozpath.join(dest, path), source] + for file_path in paths: + source = mozpath.join(base, file_path) + parts = ["%d" % type, mozpath.join(dest, file_path), source] fh.write("%s\n" % self.FIELD_SEPARATOR.join(parts)) else: parts = ["%d" % entry[0], dest] diff --git a/python/mozlint/mozlint/pathutils.py b/python/mozlint/mozlint/pathutils.py @@ -273,11 +273,11 @@ def get_ancestors_by_name(name, path, root): relevant configuration files. """ configs = [] - for path in ancestors(path): - config = os.path.join(path, name) + for ancestor_path in ancestors(path): + config = os.path.join(ancestor_path, name) if os.path.isfile(config): configs.append(config) - if path == root: + if ancestor_path == root: break return configs diff --git a/python/mozperftest/mozperftest/metrics/common.py b/python/mozperftest/mozperftest/metrics/common.py @@ -296,17 +296,17 @@ class MetricsStorage: def _alter_name(self, filtered, res, filter): previous = [] for data_type, data_info in filtered.items(): - for res in data_info: - new = filter(res["subtest"]) + for result in data_info: + new = filter(result["subtest"]) if new is None: continue if new in previous: self.logger.warning( f"Another metric which ends with `{new}` was already found. " - f"{res['subtest']} will not be simplified." + f"{result['subtest']} will not be simplified." ) continue - res["subtest"] = new + result["subtest"] = new previous.append(new) diff --git a/python/mozperftest/mozperftest/metrics/visualmetrics.py b/python/mozperftest/mozperftest/metrics/visualmetrics.py @@ -208,8 +208,8 @@ class VisualMetrics(Layer): # we are keeping the last 5 percents percents = list(percents.items()) percents.sort() - for percent, value in percents[:5]: - self.append_metrics(index, f"{name}{percent}", value, **fields) + for percent, progress_value in percents[:5]: + self.append_metrics(index, f"{name}{percent}", progress_value, **fields) def append_metrics(self, index, name, value, **fields): if name not in self.metrics_fields: diff --git a/python/mozperftest/mozperftest/tests/test_visualtools.py b/python/mozperftest/mozperftest/tests/test_visualtools.py @@ -12,16 +12,16 @@ from mozperftest.utils import temporary_env @mock.patch("mozperftest.test.browsertime.visualtools.which", new=lambda name: "Xvfb") def test_xvfb(*mocked): with temporary_env(DISPLAY="ME"): - with mock.patch("subprocess.Popen") as mocked, xvfb(): - mocked.assert_called() + with mock.patch("subprocess.Popen") as popen_mock, xvfb(): + popen_mock.assert_called() assert os.environ["DISPLAY"] == "ME" @mock.patch("mozperftest.test.browsertime.visualtools.which", new=lambda name: "Xvfb") def test_xvfb_env(*mocked): with temporary_env(DISPLAY=None): - with mock.patch("subprocess.Popen") as mocked, xvfb(): - mocked.assert_called() + with mock.patch("subprocess.Popen") as popen_mock, xvfb(): + popen_mock.assert_called() assert "DISPLAY" not in os.environ diff --git a/taskcluster/android_taskgraph/util/group_by.py b/taskcluster/android_taskgraph/util/group_by.py @@ -24,8 +24,8 @@ def component_grouping(config, tasks): # we have a single dependency for that kind and task.attributes.get("is_final_chunked_task", True) ] - for (_, build_type), tasks in groups.items(): - tasks.extend( + for (_, build_type), group_tasks in groups.items(): + group_tasks.extend( [ task for task in tasks_for_all_components diff --git a/taskcluster/android_taskgraph/util/scriptworker.py b/taskcluster/android_taskgraph/util/scriptworker.py @@ -60,13 +60,16 @@ def generate_beetmover_upstream_artifacts( else: raise Exception(f"Unsupported type of dependency. Got job: {job}") - for locale, dep in itertools.product(locales, dependencies): + for current_locale, dep in itertools.product(locales, dependencies): paths = list() for filename in map_config["mapping"]: if dep not in map_config["mapping"][filename]["from"]: continue - if locale != "multi" and not map_config["mapping"][filename]["all_locales"]: + if ( + current_locale != "multi" + and not map_config["mapping"][filename]["all_locales"] + ): continue if ( "only_for_platforms" in map_config["mapping"][filename] @@ -87,10 +90,10 @@ def generate_beetmover_upstream_artifacts( file_config, "source_path_modifier", "source path modifier", - locale=locale, + locale=current_locale, ) - kwargs["locale"] = locale + kwargs["locale"] = current_locale paths.append( os.path.join( @@ -117,7 +120,7 @@ def generate_beetmover_upstream_artifacts( "taskId": {"task-reference": f"<{dep}>"}, "taskType": map_config["tasktype_map"].get(dep), "paths": sorted(paths), - "locale": locale, + "locale": current_locale, } ) diff --git a/taskcluster/gecko_taskgraph/actions/util.py b/taskcluster/gecko_taskgraph/actions/util.py @@ -177,8 +177,8 @@ def fetch_graph_and_labels(parameters, graph_config): try: run_label_to_id = get_artifact(task_id, "public/label-to-taskid.json") label_to_taskid.update(run_label_to_id) - for label, task_id in run_label_to_id.items(): - label_to_taskids.setdefault(label, []).append(task_id) + for label, existing_task_id in run_label_to_id.items(): + label_to_taskids.setdefault(label, []).append(existing_task_id) except TaskclusterRestFailure as e: if e.status_code != 404: raise @@ -200,8 +200,8 @@ def fetch_graph_and_labels(parameters, graph_config): try: run_label_to_id = get_artifact(task_id, "public/label-to-taskid.json") label_to_taskid.update(run_label_to_id) - for label, task_id in run_label_to_id.items(): - label_to_taskids.setdefault(label, []).append(task_id) + for label, existing_task_id in run_label_to_id.items(): + label_to_taskids.setdefault(label, []).append(existing_task_id) except TaskclusterRestFailure as e: if e.status_code != 404: raise diff --git a/taskcluster/gecko_taskgraph/optimize/__init__.py b/taskcluster/gecko_taskgraph/optimize/__init__.py @@ -268,11 +268,11 @@ class ExperimentalOverride: def __getattr__(self, name): val = getattr(self.base, name).copy() - for name, strategy in self.overrides.items(): + for override_name, strategy in self.overrides.items(): if isinstance(strategy, str) and strategy.startswith("base:"): strategy = val[strategy[len("base:") :]] - val[name] = strategy + val[override_name] = strategy return val diff --git a/taskcluster/gecko_taskgraph/util/scriptworker.py b/taskcluster/gecko_taskgraph/util/scriptworker.py @@ -525,7 +525,7 @@ def generate_beetmover_upstream_artifacts( else: raise Exception(f"Unsupported type of dependency. Got job: {job}") - for locale, dep in itertools.product(locales, dependencies): + for current_locale, dep in itertools.product(locales, dependencies): paths = list() for filename in map_config["mapping"]: @@ -537,7 +537,10 @@ def generate_beetmover_upstream_artifacts( ) if dep not in map_config["mapping"][filename]["from"]: continue - if locale != "en-US" and not map_config["mapping"][filename]["all_locales"]: + if ( + current_locale != "en-US" + and not map_config["mapping"][filename]["all_locales"] + ): continue if ( "only_for_platforms" in map_config["mapping"][filename] @@ -563,10 +566,10 @@ def generate_beetmover_upstream_artifacts( file_config, "source_path_modifier", "source path modifier", - locale=locale, + locale=current_locale, ) - kwargs["locale"] = locale + kwargs["locale"] = current_locale paths.append( os.path.join( @@ -595,7 +598,7 @@ def generate_beetmover_upstream_artifacts( "taskId": {"task-reference": f"<{dep}>"}, "taskType": map_config["tasktype_map"].get(dep), "paths": sorted(paths), - "locale": locale, + "locale": current_locale, } ) diff --git a/taskcluster/gecko_taskgraph/util/verify.py b/taskcluster/gecko_taskgraph/util/verify.py @@ -258,16 +258,16 @@ def verify_dependency_tiers(task, taskgraph, scratch_pad, graph_config, paramete return "unknown" return tier - for task in taskgraph.tasks.values(): - tier = tiers[task.label] - for d in task.dependencies.values(): + for current_task in taskgraph.tasks.values(): + tier = tiers[current_task.label] + for d in current_task.dependencies.values(): if taskgraph[d].task.get("workerType") == "always-optimized": continue if "dummy" in taskgraph[d].kind: continue if tier < tiers[d]: raise Exception( - f"{task.label} (tier {printable_tier(tier)}) cannot depend on {d} (tier {printable_tier(tiers[d])})" + f"{current_task.label} (tier {printable_tier(tier)}) cannot depend on {d} (tier {printable_tier(tiers[d])})" ) @@ -291,12 +291,12 @@ def verify_required_signoffs(task, taskgraph, scratch_pad, graph_config, paramet return "required signoffs {}".format(", ".join(signoffs)) return "no required signoffs" - for task in taskgraph.tasks.values(): - required_signoffs = all_required_signoffs[task.label] - for d in task.dependencies.values(): + for current_task in taskgraph.tasks.values(): + required_signoffs = all_required_signoffs[current_task.label] + for d in current_task.dependencies.values(): if required_signoffs < all_required_signoffs[d]: raise Exception( - f"{task.label} ({printable_signoff(required_signoffs)}) cannot depend on {d} ({printable_signoff(all_required_signoffs[d])})" + f"{current_task.label} ({printable_signoff(required_signoffs)}) cannot depend on {d} ({printable_signoff(all_required_signoffs[d])})" ) @@ -414,20 +414,20 @@ def verify_test_packaging(task, taskgraph, scratch_pad, graph_config, parameters missing_tests_allowed = True exceptions = [] - for task in taskgraph.tasks.values(): - if task.kind == "build" and not task.attributes.get( + for current_task in taskgraph.tasks.values(): + if current_task.kind == "build" and not current_task.attributes.get( "skip-verify-test-packaging" ): - build_env = task.task.get("payload", {}).get("env", {}) + build_env = current_task.task.get("payload", {}).get("env", {}) package_tests = build_env.get("MOZ_AUTOMATION_PACKAGE_TESTS") - shippable = task.attributes.get("shippable", False) - build_has_tests = scratch_pad.get(task.label) + shippable = current_task.attributes.get("shippable", False) + build_has_tests = scratch_pad.get(current_task.label) if package_tests != "1": # Shippable builds should always package tests. if shippable: exceptions.append( - f"Build job {task.label} is shippable and does not specify " + f"Build job {current_task.label} is shippable and does not specify " "MOZ_AUTOMATION_PACKAGE_TESTS=1 in the " "environment." ) @@ -436,7 +436,7 @@ def verify_test_packaging(task, taskgraph, scratch_pad, graph_config, parameters # them, so we need to package tests during build. if build_has_tests: exceptions.append( - f"Build job {task.label} has tests dependent on it and does not specify " + f"Build job {current_task.label} has tests dependent on it and does not specify " "MOZ_AUTOMATION_PACKAGE_TESTS=1 in the environment" ) # Build tasks that aren't in the scratch pad have no @@ -448,7 +448,7 @@ def verify_test_packaging(task, taskgraph, scratch_pad, graph_config, parameters # there are no dependent tests. if not missing_tests_allowed: exceptions.append( - f"Build job {task.label} has no tests, but specifies " + f"Build job {current_task.label} has no tests, but specifies " f"MOZ_AUTOMATION_PACKAGE_TESTS={package_tests} in the environment. " "Unset MOZ_AUTOMATION_PACKAGE_TESTS in the task definition " "to fix." diff --git a/testing/marionette/harness/marionette_harness/runner/base.py b/testing/marionette/harness/marionette_harness/runner/base.py @@ -1152,11 +1152,11 @@ class BaseMarionetteTestRunner: ) target_tests = [] - for test in manifest_tests: - if test.get("disabled"): - self.manifest_skipped_tests.append(test) + for manifest_test in manifest_tests: + if manifest_test.get("disabled"): + self.manifest_skipped_tests.append(manifest_test) else: - target_tests.append(test) + target_tests.append(manifest_test) for i in target_tests: if not os.path.exists(i["path"]): diff --git a/testing/mochitest/mach_commands.py b/testing/mochitest/mach_commands.py @@ -414,8 +414,8 @@ def run_mochitest_general( # filtered tests to the mochitest harness. Mochitest harness will read # the master manifest in that case. if not resolve_tests: - for flavor in flavors: - key = (flavor, kwargs.get("subsuite")) + for flavor_name in flavors: + key = (flavor_name, kwargs.get("subsuite")) suites[key] = [] if not suites: @@ -477,8 +477,8 @@ def run_mochitest_general( run_mochitest = mochitest.run_desktop_test overall = None - for (flavor, subsuite), tests in sorted(suites.items()): - suite_name, suite = get_suite_definition(flavor, subsuite) + for (test_flavor, subsuite), tests in sorted(suites.items()): + suite_name, suite = get_suite_definition(test_flavor, subsuite) if "test_paths" in suite["kwargs"]: del suite["kwargs"]["test_paths"] diff --git a/testing/mozbase/manifestparser/manifestparser/manifestparser.py b/testing/mozbase/manifestparser/manifestparser/manifestparser.py @@ -712,8 +712,8 @@ class ManifestParser: else: def accept_filename(filename): - for pattern in patterns: - if fnmatch.fnmatch(filename, pattern): + for search_pattern in patterns: + if fnmatch.fnmatch(filename, search_pattern): return True if not ignore: diff --git a/testing/raptor/raptor/output.py b/testing/raptor/raptor/output.py @@ -747,9 +747,9 @@ class PerftestOutput(metaclass=ABCMeta): ) vals = [] - for name, test in _subtests.items(): - test["value"] = filters.mean(test["replicates"]) - vals.append([test["value"], name]) + for name, subtest_data in _subtests.items(): + subtest_data["value"] = filters.mean(subtest_data["replicates"]) + vals.append([subtest_data["value"], name]) # pylint W1656 return list(_subtests.values()), sorted(vals, reverse=True) diff --git a/tools/tryselect/cli.py b/tools/tryselect/cli.py @@ -132,8 +132,8 @@ class BaseTryParser(ArgumentParser): ArgumentParser.__init__(self, *args, **kwargs) group = self.add_argument_group(f"{self.name} arguments") - for cli, kwargs in self.arguments: - group.add_argument(*cli, **kwargs) + for cli, arg_kwargs in self.arguments: + group.add_argument(*cli, **arg_kwargs) for name in self.common_groups: group = self.add_argument_group(f"{name} arguments") @@ -143,14 +143,14 @@ class BaseTryParser(ArgumentParser): if name == "preset": group = group.add_mutually_exclusive_group() - for cli, kwargs in arguments: - group.add_argument(*cli, **kwargs) + for cli, common_kwargs in arguments: + group.add_argument(*cli, **common_kwargs) if name == "push": group_no_push = group.add_mutually_exclusive_group() arguments = NO_PUSH_ARGUMENT_GROUP - for cli, kwargs in arguments: - group_no_push.add_argument(*cli, **kwargs) + for cli, push_kwargs in arguments: + group_no_push.add_argument(*cli, **push_kwargs) group = self.add_argument_group("task configuration arguments") self.task_configs = {c: all_task_configs[c]() for c in self.task_configs} diff --git a/xpcom/ds/test/test_dafsa.py b/xpcom/ds/test/test_dafsa.py @@ -22,8 +22,8 @@ def _node_to_string(node: Node, prefix, buffer, cache): if not cached: cache[id(node)] = node if node: - for node in sorted(node.children.values(), key=lambda n: n.character): - _node_to_string(node, prefix, buffer, cache) + for child_node in sorted(node.children.values(), key=lambda n: n.character): + _node_to_string(child_node, prefix, buffer, cache) def _dafsa_to_string(dafsa: Dafsa): diff --git a/xpcom/ds/tools/make_dafsa.py b/xpcom/ds/tools/make_dafsa.py @@ -357,8 +357,8 @@ def parse_gperf(infile): def main(outfile, infile): - with open(infile) as infile: - preamble, words = parse_gperf(infile) + with open(infile) as input_file: + preamble, words = parse_gperf(input_file) outfile.write(words_to_cxx(words, preamble)) return 0 diff --git a/xpcom/idl-parser/xpidl/xpidl.py b/xpcom/idl-parser/xpidl/xpidl.py @@ -598,19 +598,19 @@ class Native: self.nativename = nativename self.location = location - for name, value, aloc in attlist: + for attr_name, value, aloc in attlist: if value is not None: raise IDLError("Unexpected attribute value", aloc) - if name in ("ptr", "ref"): + if attr_name in ("ptr", "ref"): if self.modifier is not None: raise IDLError("More than one ptr/ref modifier", aloc) - self.modifier = name - elif name in self.specialtypes.keys(): + self.modifier = attr_name + elif attr_name in self.specialtypes.keys(): if self.specialtype is not None: raise IDLError("More than one special type", aloc) - self.specialtype = name - if self.specialtypes[name] is not None: - self.nativename = self.specialtypes[name] + self.specialtype = attr_name + if self.specialtypes[attr_name] is not None: + self.nativename = self.specialtypes[attr_name] else: raise IDLError("Unexpected attribute", aloc) @@ -1357,8 +1357,8 @@ class Attribute: self.location = location self.doccomments = doccomments - for name, value, aloc in attlist: - if name == "binaryname": + for attr_name, value, aloc in attlist: + if attr_name == "binaryname": if value is None: raise IDLError("binaryname attribute requires a value", aloc) @@ -1368,21 +1368,21 @@ class Attribute: if value is not None: raise IDLError("Unexpected attribute value", aloc) - if name == "noscript": + if attr_name == "noscript": self.noscript = True - elif name == "notxpcom": + elif attr_name == "notxpcom": self.notxpcom = True - elif name == "symbol": + elif attr_name == "symbol": self.symbol = True - elif name == "implicit_jscontext": + elif attr_name == "implicit_jscontext": self.implicit_jscontext = True - elif name == "nostdcall": + elif attr_name == "nostdcall": self.nostdcall = True - elif name == "must_use": + elif attr_name == "must_use": self.must_use = True - elif name == "infallible": + elif attr_name == "infallible": self.infallible = True - elif name == "can_run_script": + elif attr_name == "can_run_script": if ( self.explicit_setter_can_run_script or self.explicit_getter_can_run_script @@ -1395,14 +1395,14 @@ class Attribute: ) self.explicit_setter_can_run_script = True self.explicit_getter_can_run_script = True - elif name == "setter_can_run_script": + elif attr_name == "setter_can_run_script": if self.explicit_setter_can_run_script: raise IDLError( "Redundant setter_can_run_script annotation " "on attribute", aloc, ) self.explicit_setter_can_run_script = True - elif name == "getter_can_run_script": + elif attr_name == "getter_can_run_script": if self.explicit_getter_can_run_script: raise IDLError( "Redundant getter_can_run_script annotation " "on attribute", @@ -1410,7 +1410,7 @@ class Attribute: ) self.explicit_getter_can_run_script = True else: - raise IDLError("Unexpected attribute '%s'" % name, aloc) + raise IDLError("Unexpected attribute '%s'" % attr_name, aloc) def resolve(self, iface): self.iface = iface @@ -1465,8 +1465,8 @@ class Method: self.doccomments = doccomments self.raises = raises - for name, value, aloc in attlist: - if name == "binaryname": + for attr_name, value, aloc in attlist: + if attr_name == "binaryname": if value is None: raise IDLError("binaryname attribute requires a value", aloc) @@ -1476,26 +1476,26 @@ class Method: if value is not None: raise IDLError("Unexpected attribute value", aloc) - if name == "noscript": + if attr_name == "noscript": self.noscript = True - elif name == "notxpcom": + elif attr_name == "notxpcom": self.notxpcom = True - elif name == "symbol": + elif attr_name == "symbol": self.symbol = True - elif name == "implicit_jscontext": + elif attr_name == "implicit_jscontext": self.implicit_jscontext = True - elif name == "optional_argc": + elif attr_name == "optional_argc": self.optional_argc = True - elif name == "nostdcall": + elif attr_name == "nostdcall": self.nostdcall = True - elif name == "must_use": + elif attr_name == "must_use": self.must_use = True - elif name == "can_run_script": + elif attr_name == "can_run_script": self.explicit_can_run_script = True - elif name == "infallible": + elif attr_name == "infallible": self.infallible = True else: - raise IDLError("Unexpected attribute '%s'" % name, aloc) + raise IDLError("Unexpected attribute '%s'" % attr_name, aloc) self.namemap = NameMap() for p in paramlist: @@ -1607,36 +1607,38 @@ class Param: self.location = location self.realtype = realtype - for name, value, aloc in attlist: + for attr_name, value, aloc in attlist: # Put the value-taking attributes first! - if name == "size_is": + if attr_name == "size_is": if value is None: raise IDLError("'size_is' must specify a parameter", aloc) self.size_is = value - elif name == "iid_is": + elif attr_name == "iid_is": if value is None: raise IDLError("'iid_is' must specify a parameter", aloc) self.iid_is = value - elif name == "default": + elif attr_name == "default": if value is None: raise IDLError("'default' must specify a default value", aloc) self.default_value = value else: if value is not None: - raise IDLError("Unexpected value for attribute '%s'" % name, aloc) + raise IDLError( + "Unexpected value for attribute '%s'" % attr_name, aloc + ) - if name == "const": + if attr_name == "const": self.const = True - elif name == "array": + elif attr_name == "array": self.array = True - elif name == "retval": + elif attr_name == "retval": self.retval = True - elif name == "shared": + elif attr_name == "shared": self.shared = True - elif name == "optional": + elif attr_name == "optional": self.optional = True else: - raise IDLError("Unexpected attribute '%s'" % name, aloc) + raise IDLError("Unexpected attribute '%s'" % attr_name, aloc) def resolve(self, method): self.realtype = method.iface.idl.getName(self.type, self.location)