Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
Fix PERF401 errors.
  • Loading branch information
jaraco committed Jul 19, 2024
1 parent 848c48b commit d6a581f
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 48 deletions.
3 changes: 1 addition & 2 deletions distutils/bcppcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def link( # noqa: C901
temp_dir = os.path.dirname(objects[0]) # preserve tree structure
def_file = os.path.join(temp_dir, f'{modname}.def')
contents = ['EXPORTS']
for sym in export_symbols or []:
contents.append(f' {sym}=_{sym}')
contents.extend(f' {sym}=_{sym}' for sym in export_symbols)
self.execute(write_file, (def_file, contents), f"writing {def_file}")

# Borland C++ has problems with '/' in paths
Expand Down
16 changes: 6 additions & 10 deletions distutils/ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,10 @@ def show_compilers():
# commands that use it.
from distutils.fancy_getopt import FancyGetopt

compilers = []
for compiler in compiler_class.keys():
compilers.append(("compiler=" + compiler, None, compiler_class[compiler][2]))
compilers.sort()
compilers = sorted(
("compiler=" + compiler, None, compiler_class[compiler][2])
for compiler in compiler_class.keys()
)
pretty_printer = FancyGetopt(compilers)
pretty_printer.print_help("List of available compilers:")

Expand Down Expand Up @@ -1218,8 +1218,7 @@ def gen_preprocess_options(macros, include_dirs):
# shell at all costs when we spawn the command!
pp_opts.append("-D{}={}".format(*macro))

for dir in include_dirs:
pp_opts.append(f"-I{dir}")
pp_opts.extend(f"-I{dir}" for dir in include_dirs)
return pp_opts


Expand All @@ -1230,10 +1229,7 @@ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
directories. Returns a list of command-line options suitable for use
with some compiler (depending on the two format strings passed in).
"""
lib_opts = []

for dir in library_dirs:
lib_opts.append(compiler.library_dir_option(dir))
lib_opts = [compiler.library_dir_option(dir) for dir in library_dirs]

for dir in runtime_library_dirs:
lib_opts.extend(always_iterable(compiler.runtime_library_dir_option(dir)))
Expand Down
7 changes: 4 additions & 3 deletions distutils/command/bdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def show_formats():
"""Print list of available formats (arguments to "--format" option)."""
from ..fancy_getopt import FancyGetopt

formats = []
for format in bdist.format_commands:
formats.append(("formats=" + format, None, bdist.format_commands[format][1]))
formats = [
("formats=" + format, None, bdist.format_commands[format][1])
for format in bdist.format_commands
]
pretty_printer = FancyGetopt(formats)
pretty_printer.print_help("List of available distribution formats:")

Expand Down
5 changes: 1 addition & 4 deletions distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,7 @@ def get_outputs(self):
# And build the list of output (built) filenames. Note that this
# ignores the 'inplace' flag, and assumes everything goes in the
# "build" tree.
outputs = []
for ext in self.extensions:
outputs.append(self.get_ext_fullpath(ext.name))
return outputs
return [self.get_ext_fullpath(ext.name) for ext in self.extensions]

def build_extensions(self):
# First, sanity-check the 'extensions' list
Expand Down
7 changes: 3 additions & 4 deletions distutils/command/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ def check_metadata(self):
"""
metadata = self.distribution.metadata

missing = []
for attr in 'name', 'version':
if not getattr(metadata, attr, None):
missing.append(attr)
missing = [
attr for attr in ('name', 'version') if not getattr(metadata, attr, None)
]

if missing:
self.warn("missing required meta-data: {}".format(', '.join(missing)))
Expand Down
4 changes: 1 addition & 3 deletions distutils/command/install_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir):
build_dir = getattr(build_cmd, cmd_option)

prefix_len = len(build_dir) + len(os.sep)
outputs = []
for file in build_files:
outputs.append(os.path.join(output_dir, file[prefix_len:]))
outputs = [os.path.join(output_dir, file[prefix_len:]) for file in build_files]

return outputs

Expand Down
8 changes: 4 additions & 4 deletions distutils/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def show_formats():
from ..archive_util import ARCHIVE_FORMATS
from ..fancy_getopt import FancyGetopt

formats = []
for format in ARCHIVE_FORMATS.keys():
formats.append(("formats=" + format, None, ARCHIVE_FORMATS[format][2]))
formats.sort()
formats = sorted(
("formats=" + format, None, ARCHIVE_FORMATS[format][2])
for format in ARCHIVE_FORMATS.keys()
)
FancyGetopt(formats).print_help("List of available source distribution formats:")


Expand Down
15 changes: 3 additions & 12 deletions distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,7 @@ def print_commands(self):
for cmd in std_commands:
is_std.add(cmd)

extra_commands = []
for cmd in self.cmdclass.keys():
if cmd not in is_std:
extra_commands.append(cmd)
extra_commands = [cmd for cmd in self.cmdclass.keys() if cmd not in is_std]

max_length = 0
for cmd in std_commands + extra_commands:
Expand Down Expand Up @@ -776,10 +773,7 @@ def get_command_list(self):
for cmd in std_commands:
is_std.add(cmd)

extra_commands = []
for cmd in self.cmdclass.keys():
if cmd not in is_std:
extra_commands.append(cmd)
extra_commands = [cmd for cmd in self.cmdclass.keys() if cmd not in is_std]

rv = []
for cmd in std_commands + extra_commands:
Expand Down Expand Up @@ -1301,7 +1295,4 @@ def fix_help_options(options):
"""Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
"""
new_options = []
for help_tuple in options:
new_options.append(help_tuple[0:3])
return new_options
return [opt[0:3] for opt in options]
4 changes: 1 addition & 3 deletions distutils/msvc9compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,7 @@ def link( # noqa: C901
else:
ldflags = self.ldflags_shared

export_opts = []
for sym in export_symbols or []:
export_opts.append("/EXPORT:" + sym)
export_opts = [f"/EXPORT:{sym}" for sym in export_symbols or []]

ld_args = (
ldflags + lib_opts + export_opts + objects + ['/OUT:' + output_filename]
Expand Down
4 changes: 1 addition & 3 deletions distutils/msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,7 @@ def link( # noqa: C901
else:
ldflags = self.ldflags_shared

export_opts = []
for sym in export_symbols or []:
export_opts.append("/EXPORT:" + sym)
export_opts = [f"/EXPORT:{sym}" for sym in export_symbols or []]

ld_args = (
ldflags + lib_opts + export_opts + objects + ['/OUT:' + output_filename]
Expand Down

0 comments on commit d6a581f

Please sign in to comment.