Skip to content

Commit

Permalink
Remove unused vars or mark them explicitly (#4724)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri authored Nov 4, 2024
2 parents ac0e4f8 + fcdf55e commit 566e47d
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions pkg_resources/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ()
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/bdist_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ def extract_wininst_cfg(dist_filename):
return None
f.seek(prepended - 12)

tag, cfglen, bmlen = struct.unpack("<iii", f.read(12))
tag, cfglen, _bmlen = struct.unpack("<iii", f.read(12))
if tag not in (0x1234567A, 0x1234567B):
return None # not a valid tag

Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/install_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _all_packages(pkg_name):
"""
while pkg_name:
yield pkg_name
pkg_name, sep, child = pkg_name.rpartition('.')
pkg_name, _sep, _child = pkg_name.rpartition('.')

def _get_SVEM_NSPs(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _section_options(
cls, options: AllCommandOptions
) -> 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
Expand Down
4 changes: 2 additions & 2 deletions setuptools/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'):
Expand Down
10 changes: 5 additions & 5 deletions setuptools/package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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('\\', '_')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
20 changes: 9 additions & 11 deletions setuptools/tests/config/test_setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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) == {
Expand Down Expand Up @@ -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, '
Expand Down
8 changes: 4 additions & 4 deletions setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions setuptools/tests/test_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_setuptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 566e47d

Please sign in to comment.