From db890891192c9b3d19dc2f576b81fafde280d1aa Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 25 Nov 2024 17:18:45 +0100 Subject: [PATCH] ruff rule PLC0206 and RUF021 (#270) * ruff rule PLC0206 * All checks passed! for ruff rule RUF021 --- pylib/gyp/MSVSSettings.py | 2 +- pylib/gyp/MSVSVersion.py | 2 +- pylib/gyp/__init__.py | 2 +- pylib/gyp/generator/make.py | 12 ++++++------ pylib/gyp/input.py | 11 ++++------- pylib/gyp/xcode_emulation.py | 4 ++-- pylib/gyp/xcodeproj_file.py | 8 ++++---- tools/pretty_sln.py | 4 ++-- tools/pretty_vcproj.py | 4 ++-- 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/pylib/gyp/MSVSSettings.py b/pylib/gyp/MSVSSettings.py index ac87f572..fea6e672 100644 --- a/pylib/gyp/MSVSSettings.py +++ b/pylib/gyp/MSVSSettings.py @@ -171,7 +171,7 @@ def ValidateMSBuild(self, value): int(value, self._msbuild_base) def ConvertToMSBuild(self, value): - msbuild_format = (self._msbuild_base == 10) and "%d" or "0x%04x" + msbuild_format = ((self._msbuild_base == 10) and "%d") or "0x%04x" return msbuild_format % int(value) diff --git a/pylib/gyp/MSVSVersion.py b/pylib/gyp/MSVSVersion.py index 8d7f21e8..1b353629 100644 --- a/pylib/gyp/MSVSVersion.py +++ b/pylib/gyp/MSVSVersion.py @@ -69,7 +69,7 @@ def UsesVcxproj(self): def ProjectExtension(self): """Returns the file extension for the project.""" - return self.uses_vcxproj and ".vcxproj" or ".vcproj" + return (self.uses_vcxproj and ".vcxproj") or ".vcproj" def Path(self): """Returns the path to Visual Studio installation.""" diff --git a/pylib/gyp/__init__.py b/pylib/gyp/__init__.py index d6cc0130..befa76ab 100755 --- a/pylib/gyp/__init__.py +++ b/pylib/gyp/__init__.py @@ -253,7 +253,7 @@ def Noop(value): for name, metadata in options._regeneration_metadata.items(): opt = metadata["opt"] value = getattr(options, name) - value_predicate = metadata["type"] == "path" and FixPath or Noop + value_predicate = (metadata["type"] == "path" and FixPath) or Noop action = metadata["action"] env_name = metadata["env_name"] if action == "append": diff --git a/pylib/gyp/generator/make.py b/pylib/gyp/generator/make.py index 32a21224..634da897 100644 --- a/pylib/gyp/generator/make.py +++ b/pylib/gyp/generator/make.py @@ -788,7 +788,7 @@ def __init__(self, generator_flags, flavor): self.suffix_rules_objdir2 = {} # Generate suffix rules for all compilable extensions. - for ext in COMPILABLE_EXTENSIONS: + for ext, value in COMPILABLE_EXTENSIONS.items(): # Suffix rules for source folder. self.suffix_rules_srcdir.update( { @@ -797,7 +797,7 @@ def __init__(self, generator_flags, flavor): $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(srcdir)/%%%s FORCE_DO_CMD \t@$(call do_cmd,%s,1) """ - % (ext, COMPILABLE_EXTENSIONS[ext]) + % (ext, value) ) } ) @@ -810,7 +810,7 @@ def __init__(self, generator_flags, flavor): $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj).$(TOOLSET)/%%%s FORCE_DO_CMD \t@$(call do_cmd,%s,1) """ - % (ext, COMPILABLE_EXTENSIONS[ext]) + % (ext, value) ) } ) @@ -821,7 +821,7 @@ def __init__(self, generator_flags, flavor): $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD \t@$(call do_cmd,%s,1) """ - % (ext, COMPILABLE_EXTENSIONS[ext]) + % (ext, value) ) } ) @@ -1779,13 +1779,13 @@ def WriteTarget( # using ":=". self.WriteSortedXcodeEnv(self.output, self.GetSortedXcodePostbuildEnv()) - for configname in target_postbuilds: + for configname, value in target_postbuilds.items(): self.WriteLn( "%s: TARGET_POSTBUILDS_%s := %s" % ( QuoteSpaces(self.output), configname, - gyp.common.EncodePOSIXShellList(target_postbuilds[configname]), + gyp.common.EncodePOSIXShellList(value), ) ) diff --git a/pylib/gyp/input.py b/pylib/gyp/input.py index 0881cbbb..5e71fdac 100644 --- a/pylib/gyp/input.py +++ b/pylib/gyp/input.py @@ -2469,11 +2469,8 @@ def SetUpConfigurations(target, target_dict): merged_configurations[configuration] = new_configuration_dict # Put the new configurations back into the target dict as a configuration. - for configuration in merged_configurations: - target_dict["configurations"][configuration] = merged_configurations[ - configuration - ] - + for configuration, value in merged_configurations.items(): + target_dict["configurations"][configuration] = value # Now drop all the abstract ones. configs = target_dict["configurations"] target_dict["configurations"] = { @@ -3020,8 +3017,8 @@ def Load( del target_dict[key] ProcessListFiltersInDict(target_name, tmp_dict) # Write the results back to |target_dict|. - for key in tmp_dict: - target_dict[key] = tmp_dict[key] + for key, value in tmp_dict.items(): + target_dict[key] = value # Make sure every dependency appears at most once. RemoveDuplicateDependencies(targets) diff --git a/pylib/gyp/xcode_emulation.py b/pylib/gyp/xcode_emulation.py index f567542b..aee1a542 100644 --- a/pylib/gyp/xcode_emulation.py +++ b/pylib/gyp/xcode_emulation.py @@ -1127,8 +1127,8 @@ def _GetIOSPostbuilds(self, configname, output_binary): be deployed to a device. This should be run as the very last step of the build.""" if not ( - self.isIOS - and (self.spec["type"] == "executable" or self._IsXCTest()) + (self.isIOS + and (self.spec["type"] == "executable" or self._IsXCTest())) or self.IsIosFramework() ): return [] diff --git a/pylib/gyp/xcodeproj_file.py b/pylib/gyp/xcodeproj_file.py index d0bd2b55..cd72aa26 100644 --- a/pylib/gyp/xcodeproj_file.py +++ b/pylib/gyp/xcodeproj_file.py @@ -3017,10 +3017,10 @@ def _AllSymrootsUnique(self, target, inherit_unique_symroot): symroots = self._DefinedSymroots(target) for s in self._DefinedSymroots(target): if ( - s is not None - and not self._IsUniqueSymrootForTarget(s) - or s is None - and not inherit_unique_symroot + (s is not None + and not self._IsUniqueSymrootForTarget(s)) + or (s is None + and not inherit_unique_symroot) ): return False return True if symroots else inherit_unique_symroot diff --git a/tools/pretty_sln.py b/tools/pretty_sln.py index cf0638a2..8026699d 100755 --- a/tools/pretty_sln.py +++ b/tools/pretty_sln.py @@ -93,10 +93,10 @@ def ParseSolution(solution_file): continue # Change all dependencies clsid to name instead. - for project in dependencies: + for project, deps in dependencies.items(): # For each dependencies in this project new_dep_array = [] - for dep in dependencies[project]: + for dep in deps: # Look for the project name matching this cldis for project_info in projects: if projects[project_info][1] == dep: diff --git a/tools/pretty_vcproj.py b/tools/pretty_vcproj.py index d4b58fd8..86240035 100755 --- a/tools/pretty_vcproj.py +++ b/tools/pretty_vcproj.py @@ -118,8 +118,8 @@ def FixFilenames(filenames, current_directory): new_list = [] for filename in filenames: if filename: - for key in REPLACEMENTS: - filename = filename.replace(key, REPLACEMENTS[key]) + for key, value in REPLACEMENTS.items(): + filename = filename.replace(key, value) os.chdir(current_directory) filename = filename.strip("\"' ") if filename.startswith("$"):