From 459f1448604bf0cd59f2a4132aee84f9be6f9b12 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 20 Nov 2022 19:59:31 +0100 Subject: Apply refurb suggestions [FURB123]: Replace `str(x)` with `x` --- distutils/_collections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/_collections.py b/distutils/_collections.py index 02556614..5ad21cc7 100644 --- a/distutils/_collections.py +++ b/distutils/_collections.py @@ -185,7 +185,7 @@ class RangeMap(dict): return (sorted_keys[RangeMap.first_item], sorted_keys[RangeMap.last_item]) # some special values for the RangeMap - undefined_value = type(str('RangeValueUndefined'), (), {})() + undefined_value = type('RangeValueUndefined', (), {})() class Item(int): "RangeMap Item" -- cgit v1.2.1 From f7ff2d062c4f8ae543f0cd207c51c7b9f7e2e715 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:05:52 +0100 Subject: Apply refurb suggestions [FURB113]: Use `x.extend(...)` instead of repeatedly calling `x.append()` --- distutils/_msvccompiler.py | 3 +-- distutils/bcppcompiler.py | 3 +-- distutils/tests/test_check.py | 11 ++++------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index 8b4023c4..ff2fb0cf 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -413,8 +413,7 @@ class MSVCCompiler(CCompiler): args = [self.cc] + compile_opts + pp_opts if add_cpp_opts: args.append('/EHsc') - args.append(input_opt) - args.append("/Fo" + obj) + args.extend((input_opt, "/Fo" + obj)) args.extend(extra_postargs) try: diff --git a/distutils/bcppcompiler.py b/distutils/bcppcompiler.py index 5d6b8653..c38d57c6 100644 --- a/distutils/bcppcompiler.py +++ b/distutils/bcppcompiler.py @@ -294,8 +294,7 @@ class BCPPCompiler(CCompiler): ld_args.append(libfile) # some default libraries - ld_args.append('import32') - ld_args.append('cw32mt') + ld_args.extend(('import32', 'cw32mt')) # def file for export symbols ld_args.extend([',', def_file]) diff --git a/distutils/tests/test_check.py b/distutils/tests/test_check.py index 54654067..6d240b8b 100644 --- a/distutils/tests/test_check.py +++ b/distutils/tests/test_check.py @@ -152,8 +152,7 @@ class TestCheck(support.TempdirManager): pytest.importorskip('docutils') # Don't fail if there is a `code` or `code-block` directive - example_rst_docs = [] - example_rst_docs.append( + example_rst_docs = [ textwrap.dedent( """\ Here's some code: @@ -163,9 +162,7 @@ class TestCheck(support.TempdirManager): def foo(): pass """ - ) - ) - example_rst_docs.append( + ), textwrap.dedent( """\ Here's some code: @@ -175,8 +172,8 @@ class TestCheck(support.TempdirManager): def foo(): pass """ - ) - ) + ), + ] for rest_with_code in example_rst_docs: pkg_info, dist = self.create_dist(long_description=rest_with_code) -- cgit v1.2.1 From b289d7456d21a0a1c5c66dd4ee654e1ee4a0e027 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:09:25 +0100 Subject: Apply refurb suggestions [FURB108]: Use `x in (y, z)` instead of `x == y or x == z` --- distutils/command/install.py | 2 +- distutils/cygwinccompiler.py | 2 +- distutils/msvc9compiler.py | 2 +- distutils/text_file.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index 08d2f881..a1f8209a 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -609,7 +609,7 @@ class install(Command): for attr in attrs: val = getattr(self, attr) if val is not None: - if os.name == 'posix' or os.name == 'nt': + if os.name in ('posix', 'nt'): val = os.path.expanduser(val) val = subst_vars(val, self.config_vars) setattr(self, attr, val) diff --git a/distutils/cygwinccompiler.py b/distutils/cygwinccompiler.py index f15b8eee..4c5c6a36 100644 --- a/distutils/cygwinccompiler.py +++ b/distutils/cygwinccompiler.py @@ -133,7 +133,7 @@ class CygwinCCompiler(UnixCCompiler): def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): """Compiles the source by spawning GCC and windres if needed.""" - if ext == '.rc' or ext == '.res': + if ext in ('.rc', '.res'): # gcc needs '.res' and '.rc' compiled to object files !!! try: self.spawn(["windres", "-i", src, "-o", obj]) diff --git a/distutils/msvc9compiler.py b/distutils/msvc9compiler.py index a4714a55..49d83b50 100644 --- a/distutils/msvc9compiler.py +++ b/distutils/msvc9compiler.py @@ -391,7 +391,7 @@ class MSVCCompiler(CCompiler): # to cross compile, you use 'x86_amd64'. # On AMD64, 'vcvars32.bat amd64' is a native build env; to cross # compile use 'x86' (ie, it runs the x86 compiler directly) - if plat_name == get_platform() or plat_name == 'win32': + if plat_name in (get_platform(), 'win32'): # native build or cross-compile to win32 plat_spec = PLAT_TO_VCVARS[plat_name] else: diff --git a/distutils/text_file.py b/distutils/text_file.py index 7274d4b1..164c0ea2 100644 --- a/distutils/text_file.py +++ b/distutils/text_file.py @@ -255,7 +255,7 @@ class TextFile: # blank line (whether we rstrip'ed or not)? skip to next line # if appropriate - if (line == '' or line == '\n') and self.skip_blanks: + if line in ('', '\n') and self.skip_blanks: continue if self.join_lines: -- cgit v1.2.1 From 32e9b27a372fa2b3da372e4b4dbf66202f09f215 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:16:07 +0100 Subject: Apply refurb suggestions [FURB131]: Replace `del x[y]` with `x.pop(y)` --- distutils/core.py | 2 +- distutils/dir_util.py | 2 +- distutils/tests/test_archive_util.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/distutils/core.py b/distutils/core.py index 34cafbce..05d29719 100644 --- a/distutils/core.py +++ b/distutils/core.py @@ -132,7 +132,7 @@ def setup(**attrs): # noqa: C901 # our Distribution (see below). klass = attrs.get('distclass') if klass: - del attrs['distclass'] + attrs.pop('distclass') else: klass = Distribution diff --git a/distutils/dir_util.py b/distutils/dir_util.py index 80f77649..23dc3392 100644 --- a/distutils/dir_util.py +++ b/distutils/dir_util.py @@ -227,7 +227,7 @@ def remove_tree(directory, verbose=1, dry_run=0): # remove dir from cache if it's already there abspath = os.path.abspath(cmd[1]) if abspath in _path_created: - del _path_created[abspath] + _path_created.pop(abspath) except OSError as exc: log.warning("error removing %s: %s", directory, exc) diff --git a/distutils/tests/test_archive_util.py b/distutils/tests/test_archive_util.py index 7778c3ad..89c415d7 100644 --- a/distutils/tests/test_archive_util.py +++ b/distutils/tests/test_archive_util.py @@ -289,7 +289,7 @@ class ArchiveUtilTestCase(support.TempdirManager): pass assert os.getcwd() == current_dir finally: - del ARCHIVE_FORMATS['xxx'] + ARCHIVE_FORMATS.pop('xxx') def test_make_archive_tar(self): base_dir = self._create_files() -- cgit v1.2.1 From 1713e720352fc6797d07dd7b61e9bafaed7b8e20 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:19:29 +0100 Subject: Apply refurb suggestions [FURB109]: Replace `in [x, y, z]` with `in (x, y, z)` --- distutils/dist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/dist.py b/distutils/dist.py index d7458a05..970abda0 100644 --- a/distutils/dist.py +++ b/distutils/dist.py @@ -700,7 +700,7 @@ Common commands: (see '--help-commands' for more) if val and is_display_option.get(opt): opt = translate_longopt(opt) value = getattr(self.metadata, "get_" + opt)() - if opt in ['keywords', 'platforms']: + if opt in ('keywords', 'platforms'): print(','.join(value)) elif opt in ('classifiers', 'provides', 'requires', 'obsoletes'): print('\n'.join(value)) -- cgit v1.2.1