From fcdf55e588af53d0fd1fa0d77cc6c9aeaa34802a Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Thu, 31 Oct 2024 17:31:25 +0000 Subject: [PATCH] Remove unused vars or mark them explicitly --- pkg_resources/__init__.py | 2 +- pkg_resources/tests/test_resources.py | 6 +++--- setup.py | 2 +- setuptools/__init__.py | 2 +- setuptools/command/bdist_egg.py | 2 +- setuptools/command/build_ext.py | 2 +- setuptools/command/easy_install.py | 2 +- setuptools/command/install_lib.py | 2 +- setuptools/config/setupcfg.py | 2 +- setuptools/depends.py | 4 ++-- setuptools/dist.py | 8 ++++---- setuptools/package_index.py | 10 +++++----- setuptools/sandbox.py | 2 +- setuptools/tests/config/test_setupcfg.py | 20 +++++++++----------- setuptools/tests/test_easy_install.py | 8 ++++---- setuptools/tests/test_egg_info.py | 16 ++++++++-------- setuptools/tests/test_manifest.py | 2 +- setuptools/tests/test_setuptools.py | 2 +- setuptools/tests/test_windows_wrappers.py | 6 +++--- 19 files changed, 49 insertions(+), 51 deletions(-) diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 6418eb2ab0..74b0465bfa 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2064,7 +2064,7 @@ def _extract_resource(self, manager: ResourceManager, zip_path) -> str: # noqa: # return the extracted directory name return os.path.dirname(last) - timestamp, size = self._get_date_and_size(self.zipinfo[zip_path]) + timestamp, _size = self._get_date_and_size(self.zipinfo[zip_path]) if not WRITE_SUPPORT: raise OSError( diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index be1c1213af..00fb5b3290 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -693,11 +693,11 @@ def test_requirements_with_markers(self): ) != Requirement.parse("name[foo,bar]==1.0;python_version=='3.6'") def test_local_version(self): - (req,) = parse_requirements('foo==1.0+org1') + parse_requirements('foo==1.0+org1') def test_spaces_between_multiple_versions(self): - (req,) = parse_requirements('foo>=1.0, <3') - (req,) = parse_requirements('foo >= 1.0, < 3') + parse_requirements('foo>=1.0, <3') + parse_requirements('foo >= 1.0, < 3') @pytest.mark.parametrize( ("lower", "upper"), diff --git a/setup.py b/setup.py index 1cd9e36c15..c28a14e722 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ def pypi_link(pkg_filename): dependency link for PyPI. """ root = 'https://files.pythonhosted.org/packages/source' - name, sep, rest = pkg_filename.partition('-') + name, _sep, _rest = pkg_filename.partition('-') parts = root, name[0], name, pkg_filename return '/'.join(parts) diff --git a/setuptools/__init__.py b/setuptools/__init__.py index 783e5e7591..b330e9aa3e 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -70,7 +70,7 @@ def __init__(self, attrs: Mapping[str, object]): def _get_project_config_files(self, filenames=None): """Ignore ``pyproject.toml``, they are not related to setup_requires""" try: - cfg, toml = super()._split_standard_project_metadata(filenames) + cfg, _toml = super()._split_standard_project_metadata(filenames) except Exception: return filenames, () return cfg, () diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index a623155f22..04d7e945bc 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -181,7 +181,7 @@ def run(self): # noqa: C901 # is too complex (14) # FIXME self.stubs = [] to_compile = [] for p, ext_name in enumerate(ext_outputs): - filename, ext = os.path.splitext(ext_name) + filename, _ext = os.path.splitext(ext_name) pyfile = os.path.join(self.bdist_dir, strip_module(filename) + '.py') self.stubs.append(pyfile) log.info("creating stub loader for %s", ext_name) diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 00a38ba3c9..f098246b9b 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -460,7 +460,7 @@ def link_shared_object( assert output_dir is None # distutils build_ext doesn't pass this output_dir, filename = os.path.split(output_libname) - basename, ext = os.path.splitext(filename) + basename, _ext = os.path.splitext(filename) if self.library_filename("x").startswith('lib'): # strip 'lib' prefix; this is kludgy if some platform uses # a different prefix diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index e1cd32cf0d..37f01ed46e 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1547,7 +1547,7 @@ def extract_wininst_cfg(dist_filename): return None f.seek(prepended - 12) - tag, cfglen, bmlen = struct.unpack(" Iterator[tuple[str, SingleCommandOptions]]: for full_name, value in options.items(): - pre, sep, name = full_name.partition(cls.section_prefix) + pre, _sep, name = full_name.partition(cls.section_prefix) if pre: continue yield name.lstrip('.'), value diff --git a/setuptools/depends.py b/setuptools/depends.py index 0011c05da1..16a67c0306 100644 --- a/setuptools/depends.py +++ b/setuptools/depends.py @@ -70,7 +70,7 @@ def get_version( if self.attribute is None: try: - f, p, i = find_module(self.module, paths) + f, _p, _i = find_module(self.module, paths) except ImportError: return None if f: @@ -122,7 +122,7 @@ def get_module_constant( constant. Otherwise, return 'default'.""" try: - f, path, (suffix, mode, kind) = info = find_module(module, paths) + f, path, (_suffix, _mode, kind) = info = find_module(module, paths) except ImportError: # Module doesn't exist return None diff --git a/setuptools/dist.py b/setuptools/dist.py index 333bc29290..6062c4f868 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -113,7 +113,7 @@ def check_nsp(dist, attr, value): "Distribution contains no modules or packages for " + "namespace package %r" % nsp ) - parent, sep, child = nsp.rpartition('.') + parent, _sep, _child = nsp.rpartition('.') if parent and parent not in ns_packages: distutils.log.warn( "WARNING: %r is declared as a package namespace, but %r" @@ -145,7 +145,7 @@ def check_extras(dist, attr, value): def _check_extra(extra, reqs): - name, sep, marker = extra.partition(':') + _name, _sep, marker = extra.partition(':') try: _check_marker(marker) except InvalidMarker: @@ -886,7 +886,7 @@ def _parse_command_opts(self, parser, args): command = args[0] aliases = self.get_option_dict('aliases') while command in aliases: - src, alias = aliases[command] + _src, alias = aliases[command] del aliases[command] # ensure each alias can expand only once! import shlex @@ -951,7 +951,7 @@ def iter_distribution_names(self): for ext in self.ext_modules or (): if isinstance(ext, tuple): - name, buildinfo = ext + name, _buildinfo = ext else: name = ext.name if name.endswith('module'): diff --git a/setuptools/package_index.py b/setuptools/package_index.py index ca1dbf0cb6..ad95d3573a 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -104,7 +104,7 @@ def parse_bdist_wininst(name): def egg_info_for_url(url): parts = urllib.parse.urlparse(url) - scheme, server, path, parameters, query, fragment = parts + _scheme, server, path, _parameters, _query, fragment = parts base = urllib.parse.unquote(path.split('/')[-1]) if server == 'sourceforge.net' and base == 'download': # XXX Yuck base = urllib.parse.unquote(path.split('/')[-2]) @@ -431,7 +431,7 @@ def scan_egg_link(self, path, entry) -> None: # format is not recognized; punt return - egg_path, setup_path = lines + egg_path, _setup_path = lines for dist in find_distributions(os.path.join(path, egg_path)): dist.location = os.path.join(path, *lines) @@ -820,7 +820,7 @@ def open_url(self, url, warning=None): # noqa: C901 # is too complex (12) def _download_url(self, url, tmpdir): # Determine download filename # - name, fragment = egg_info_for_url(url) + name, _fragment = egg_info_for_url(url) if name: while '..' in name: name = name.replace('..', '.').replace('\\', '_') @@ -848,7 +848,7 @@ def _resolve_vcs(url): >>> rvcs('http://foo/bar') """ scheme = urllib.parse.urlsplit(url).scheme - pre, sep, post = scheme.partition('+') + pre, sep, _post = scheme.partition('+') # svn and git have their own protocol; hg does not allowed = set(['svn', 'git'] + ['hg'] * bool(sep)) return next(iter({pre} & allowed), None) @@ -1121,7 +1121,7 @@ def fix_sf_url(url): def local_open(url): """Read a local path, with special support for directories""" - scheme, server, path, param, query, frag = urllib.parse.urlparse(url) + _scheme, _server, path, _param, _query, _frag = urllib.parse.urlparse(url) filename = urllib.request.url2pathname(path) if os.path.isfile(filename): return urllib.request.urlopen(url) diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index c774a02f8c..b6c63f03d4 100644 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -150,7 +150,7 @@ def resume(self): if '_saved' not in vars(self): return - type, exc = map(pickle.loads, self._saved) + _type, exc = map(pickle.loads, self._saved) raise exc.with_traceback(self._tb) diff --git a/setuptools/tests/config/test_setupcfg.py b/setuptools/tests/config/test_setupcfg.py index 9f225416c0..b31118c0fb 100644 --- a/setuptools/tests/config/test_setupcfg.py +++ b/setuptools/tests/config/test_setupcfg.py @@ -288,9 +288,7 @@ def test_version(self, tmpdir): assert dist.metadata.version == '2016.11.26' def test_version_file(self, tmpdir): - _, config = fake_env( - tmpdir, '[metadata]\nversion = file: fake_package/version.txt\n' - ) + fake_env(tmpdir, '[metadata]\nversion = file: fake_package/version.txt\n') tmpdir.join('fake_package', 'version.txt').write('1.2.3\n') with get_dist(tmpdir) as dist: @@ -302,7 +300,7 @@ def test_version_file(self, tmpdir): dist.metadata.version def test_version_with_package_dir_simple(self, tmpdir): - _, config = fake_env( + fake_env( tmpdir, '[metadata]\n' 'version = attr: fake_package_simple.VERSION\n' @@ -316,7 +314,7 @@ def test_version_with_package_dir_simple(self, tmpdir): assert dist.metadata.version == '1.2.3' def test_version_with_package_dir_rename(self, tmpdir): - _, config = fake_env( + fake_env( tmpdir, '[metadata]\n' 'version = attr: fake_package_rename.VERSION\n' @@ -330,7 +328,7 @@ def test_version_with_package_dir_rename(self, tmpdir): assert dist.metadata.version == '1.2.3' def test_version_with_package_dir_complex(self, tmpdir): - _, config = fake_env( + fake_env( tmpdir, '[metadata]\n' 'version = attr: fake_package_complex.VERSION\n' @@ -585,8 +583,8 @@ def test_packages(self, tmpdir): def test_find_directive(self, tmpdir): dir_package, config = fake_env(tmpdir, '[options]\npackages = find:\n') - dir_sub_one, _ = make_package_dir('sub_one', dir_package) - dir_sub_two, _ = make_package_dir('sub_two', dir_package) + make_package_dir('sub_one', dir_package) + make_package_dir('sub_two', dir_package) with get_dist(tmpdir) as dist: assert set(dist.packages) == set([ @@ -624,8 +622,8 @@ def test_find_namespace_directive(self, tmpdir): tmpdir, '[options]\npackages = find_namespace:\n' ) - dir_sub_one, _ = make_package_dir('sub_one', dir_package) - dir_sub_two, _ = make_package_dir('sub_two', dir_package, ns=True) + make_package_dir('sub_one', dir_package) + make_package_dir('sub_two', dir_package, ns=True) with get_dist(tmpdir) as dist: assert set(dist.packages) == { @@ -779,7 +777,7 @@ def test_entry_points(self, tmpdir): assert dist.entry_points == expected def test_case_sensitive_entry_points(self, tmpdir): - _, config = fake_env( + fake_env( tmpdir, '[options.entry_points]\n' 'GROUP1 = point1 = pack.module:func, ' diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index fdd3cda3a1..586324be37 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -72,7 +72,7 @@ def test_get_script_args(self): header = ei.CommandSpec.best().from_environment().as_header() dist = FakeDist() args = next(ei.ScriptWriter.get_args(dist)) - name, script = itertools.islice(args, 2) + _name, script = itertools.islice(args, 2) assert script.startswith(header) assert "'spec'" in script assert "'console_scripts'" in script @@ -651,7 +651,7 @@ def test_setup_requires_overrides_version_conflict(self, use_setup_cfg): temp_dir, use_setup_cfg=use_setup_cfg ) test_setup_py = os.path.join(test_pkg, 'setup.py') - with contexts.quiet() as (stdout, stderr): + with contexts.quiet() as (stdout, _stderr): # Don't even need to install the package, just # running the setup.py at all is sufficient run_setup(test_setup_py, ['--name']) @@ -713,7 +713,7 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg): test_setup_py = os.path.join(test_pkg, 'setup.py') - with contexts.quiet() as (stdout, stderr): + with contexts.quiet() as (stdout, _stderr): try: # Don't even need to install the package, just # running the setup.py at all is sufficient @@ -765,7 +765,7 @@ def make_dependency_sdist(dist_path, distname, version): use_setup_cfg=use_setup_cfg + ('version',), ) test_setup_py = os.path.join(test_pkg, 'setup.py') - with contexts.quiet() as (stdout, stderr): + with contexts.quiet() as (stdout, _stderr): run_setup(test_setup_py, ['--version']) lines = stdout.readlines() assert len(lines) > 0 diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 7b7433f0ba..a68ecaba4c 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -512,7 +512,7 @@ def test_provides_extra(self, tmpdir_cwd, env): environ = os.environ.copy().update( HOME=env.paths['home'], ) - code, data = environment.run_setup_py( + environment.run_setup_py( cmd=['egg_info'], pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), data_stream=1, @@ -1060,7 +1060,7 @@ def test_license_file_attr_pkg_info(self, tmpdir_cwd, env): def test_metadata_version(self, tmpdir_cwd, env): """Make sure latest metadata version is used by default.""" self._setup_script_with_requires("") - code, data = environment.run_setup_py( + environment.run_setup_py( cmd=['egg_info'], pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), data_stream=1, @@ -1085,7 +1085,7 @@ def test_long_description_content_type(self, tmpdir_cwd, env): environ = os.environ.copy().update( HOME=env.paths['home'], ) - code, data = environment.run_setup_py( + environment.run_setup_py( cmd=['egg_info'], pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), data_stream=1, @@ -1107,7 +1107,7 @@ def test_long_description(self, tmpdir_cwd, env): "long_description='This is a long description\\nover multiple lines'," "long_description_content_type='text/markdown'," ) - code, data = environment.run_setup_py( + environment.run_setup_py( cmd=['egg_info'], pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), data_stream=1, @@ -1138,7 +1138,7 @@ def test_project_urls(self, tmpdir_cwd, env): environ = os.environ.copy().update( HOME=env.paths['home'], ) - code, data = environment.run_setup_py( + environment.run_setup_py( cmd=['egg_info'], pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), data_stream=1, @@ -1156,7 +1156,7 @@ def test_project_urls(self, tmpdir_cwd, env): def test_license(self, tmpdir_cwd, env): """Test single line license.""" self._setup_script_with_requires("license='MIT',") - code, data = environment.run_setup_py( + environment.run_setup_py( cmd=['egg_info'], pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), data_stream=1, @@ -1171,7 +1171,7 @@ def test_license_escape(self, tmpdir_cwd, env): self._setup_script_with_requires( "license='This is a long license text \\nover multiple lines'," ) - code, data = environment.run_setup_py( + environment.run_setup_py( cmd=['egg_info'], pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), data_stream=1, @@ -1189,7 +1189,7 @@ def test_python_requires_egg_info(self, tmpdir_cwd, env): environ = os.environ.copy().update( HOME=env.paths['home'], ) - code, data = environment.run_setup_py( + environment.run_setup_py( cmd=['egg_info'], pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), data_stream=1, diff --git a/setuptools/tests/test_manifest.py b/setuptools/tests/test_manifest.py index 444c7a3689..ad988d2c5f 100644 --- a/setuptools/tests/test_manifest.py +++ b/setuptools/tests/test_manifest.py @@ -369,7 +369,7 @@ def assertWarnings(self, caplog): def make_files(self, files): for file in files: file = os.path.join(self.temp_dir, file) - dirname, basename = os.path.split(file) + dirname, _basename = os.path.split(file) os.makedirs(dirname, exist_ok=True) touch(file) diff --git a/setuptools/tests/test_setuptools.py b/setuptools/tests/test_setuptools.py index ab027b9d09..1d56e1a8a4 100644 --- a/setuptools/tests/test_setuptools.py +++ b/setuptools/tests/test_setuptools.py @@ -74,7 +74,7 @@ def testFindModule(self): dep.find_module('no-such.-thing') with pytest.raises(ImportError): dep.find_module('setuptools.non-existent') - f, p, i = dep.find_module('setuptools.tests') + f, _p, _i = dep.find_module('setuptools.tests') f.close() @needs_bytecode diff --git a/setuptools/tests/test_windows_wrappers.py b/setuptools/tests/test_windows_wrappers.py index 4a112baf75..e46bb6abc0 100644 --- a/setuptools/tests/test_windows_wrappers.py +++ b/setuptools/tests/test_windows_wrappers.py @@ -116,7 +116,7 @@ def test_basic(self, tmpdir): text=True, encoding="utf-8", ) - stdout, stderr = proc.communicate('hello\nworld\n') + stdout, _stderr = proc.communicate('hello\nworld\n') actual = stdout.replace('\r\n', '\n') expected = textwrap.dedent( r""" @@ -153,7 +153,7 @@ def test_symlink(self, tmpdir): text=True, encoding="utf-8", ) - stdout, stderr = proc.communicate('hello\nworld\n') + stdout, _stderr = proc.communicate('hello\nworld\n') actual = stdout.replace('\r\n', '\n') expected = textwrap.dedent( r""" @@ -201,7 +201,7 @@ def test_with_options(self, tmpdir): text=True, encoding="utf-8", ) - stdout, stderr = proc.communicate() + stdout, _stderr = proc.communicate() actual = stdout.replace('\r\n', '\n') expected = textwrap.dedent( r"""