From c4fb5937b869fbc20ac01e7e201464fb94e6481e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 29 Jun 2024 12:14:17 +0200 Subject: [PATCH 1/5] Apply ruff/Perflint rule PERF102 PERF102 When using only the values of a dict use the `values()` method --- distutils/command/install.py | 2 +- distutils/dist.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index 1fc09eef..b83e061e 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -680,7 +680,7 @@ def create_home_path(self): if not self.user: return home = convert_path(os.path.expanduser("~")) - for _name, path in self.config_vars.items(): + for path in self.config_vars.values(): if str(path).startswith(home) and not os.path.isdir(path): self.debug_print(f"os.makedirs('{path}', 0o700)") os.makedirs(path, 0o700) diff --git a/distutils/dist.py b/distutils/dist.py index 115302b3..6cc7cd0c 100644 --- a/distutils/dist.py +++ b/distutils/dist.py @@ -741,9 +741,7 @@ def print_commands(self): import distutils.command std_commands = distutils.command.__all__ - is_std = set() - for cmd in std_commands: - is_std.add(cmd) + is_std = set(std_commands) extra_commands = [cmd for cmd in self.cmdclass.keys() if cmd not in is_std] @@ -769,9 +767,7 @@ def get_command_list(self): import distutils.command std_commands = distutils.command.__all__ - is_std = set() - for cmd in std_commands: - is_std.add(cmd) + is_std = set(std_commands) extra_commands = [cmd for cmd in self.cmdclass.keys() if cmd not in is_std] From 7556b83700bee5565c72c0426b0156d9d5292203 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 29 Jun 2024 12:11:54 +0200 Subject: [PATCH 2/5] Apply ruff/Perflint rule PERF402 PERF402 Use `list` or `list.copy` to create a copy of a list --- distutils/command/build_ext.py | 3 +-- distutils/cygwinccompiler.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/distutils/command/build_ext.py b/distutils/command/build_ext.py index cf475fe8..a7e3038b 100644 --- a/distutils/command/build_ext.py +++ b/distutils/command/build_ext.py @@ -638,8 +638,7 @@ def swig_sources(self, sources, extension): # Do not override commandline arguments if not self.swig_opts: - for o in extension.swig_opts: - swig_cmd.append(o) + swig_cmd.extend(extension.swig_opts) for source in swig_sources: target = swig_targets[source] diff --git a/distutils/cygwinccompiler.py b/distutils/cygwinccompiler.py index ce412e83..3743f14e 100644 --- a/distutils/cygwinccompiler.py +++ b/distutils/cygwinccompiler.py @@ -172,8 +172,7 @@ def link( # Generate .def file contents = [f"LIBRARY {os.path.basename(output_filename)}", "EXPORTS"] - for sym in export_symbols: - contents.append(sym) + contents.extend(export_symbols) self.execute(write_file, (def_file, contents), f"writing {def_file}") # next add options for def-file From 9d86ea810f1728ac157623754001d0194ba422e8 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 29 Jun 2024 12:18:12 +0200 Subject: [PATCH 3/5] Apply ruff/Perflint rule PERF403 PERF403 Use a dictionary comprehension instead of a for-loop --- distutils/archive_util.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/distutils/archive_util.py b/distutils/archive_util.py index 07cd97f4..cc4699b1 100644 --- a/distutils/archive_util.py +++ b/distutils/archive_util.py @@ -266,8 +266,7 @@ def make_archive( raise ValueError(f"unknown archive format '{format}'") func = format_info[0] - for arg, val in format_info[1]: - kwargs[arg] = val + kwargs.update(format_info[1]) if format != 'zip': kwargs['owner'] = owner From 7f22d8bc039cca08d80b5ea8d48d7e7673d524cc Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 29 Jun 2024 12:24:57 +0200 Subject: [PATCH 4/5] Enforce ruff/Perflint rules (PERF) --- ruff.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruff.toml b/ruff.toml index 41c9459b..a8215c0c 100644 --- a/ruff.toml +++ b/ruff.toml @@ -8,11 +8,13 @@ extend-select = [ "B", "I", "ISC", + "PERF", "RUF010", "RUF100", "UP", ] ignore = [ + "PERF203", # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules "W191", "E111", From 2b5815cea160e3656d48fb528a451f6ae01d23ef Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 1 Jul 2024 19:09:12 +0200 Subject: [PATCH 5/5] Add `# local` to ignore conflicts with upstrea --- ruff.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruff.toml b/ruff.toml index a8215c0c..0d55637d 100644 --- a/ruff.toml +++ b/ruff.toml @@ -14,7 +14,9 @@ extend-select = [ "UP", ] ignore = [ + # local "PERF203", + # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules "W191", "E111",