Skip to content
7 changes: 4 additions & 3 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def get_provider(moduleOrReq):
return _find_adapter(_provider_factories, loader)(module)


def _macos_vers(_cache=[]):
def _macos_vers(_cache=None):
if not _cache:
version = platform.mac_ver()[0]
# fallback for MacPorts
Expand All @@ -419,7 +419,7 @@ def _macos_vers(_cache=[]):
if 'ProductVersion' in plist_content:
version = plist_content['ProductVersion']

_cache.append(version.split('.'))
_cache = [version.split('.')]
return _cache[0]


Expand Down Expand Up @@ -2422,7 +2422,8 @@ def _cygwin_patch(filename): # pragma: nocover
return os.path.abspath(filename) if sys.platform == 'cygwin' else filename


def _normalize_cached(filename, _cache={}):
def _normalize_cached(filename, _cache=None):
_cache = _cache or {}
try:
return _cache[filename]
except KeyError:
Expand Down
4 changes: 2 additions & 2 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def _file_with_extension(directory, extension):
matching = (f for f in os.listdir(directory) if f.endswith(extension))
try:
(file,) = matching
except ValueError:
except ValueError as e:
raise ValueError(
'No distribution was found. Ensure that `setup.py` '
'is not empty and that it calls `setup()`.'
)
) from e
return file


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 @@ -157,7 +157,7 @@ def get_ext_filename(self, fullname):

if fullname in self.ext_map:
ext = self.ext_map[fullname]
use_abi3 = getattr(ext, 'py_limited_api') and get_abi3_suffix()
use_abi3 = ext.py_limited_api and get_abi3_suffix()
if use_abi3:
filename = filename[: -len(so_ext)]
so_ext = get_abi3_suffix()
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def exclude_data_files(self, package, src_dir, files):
return list(unique_everseen(keepers))

@staticmethod
def _get_platform_patterns(spec, package, src_dir, extra_patterns=[]):
def _get_platform_patterns(spec, package, src_dir, extra_patterns=()):
"""
yield platform-specific path patterns (suitable for glob
or fn_match) from a glob-based spec (such as
Expand Down
4 changes: 2 additions & 2 deletions setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ def process_template_line(self, line):

try:
process_action = action_map[action]
except KeyError:
except KeyError as e:
raise DistutilsInternalError(
"this cannot happen: invalid action '{action!s}'".format(action=action),
)
) from e

# OK, now we know that the action is valid and we have the
# right number of words on the line for that action -- so we
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class NoValue:
yield
finally:
if orig_val is not NoValue:
setattr(os, 'link', orig_val)
os.link = orig_val

def add_defaults(self):
super().add_defaults()
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def with_project_on_sys_path(self, func):
func()

@contextlib.contextmanager
def project_on_sys_path(self, include_dists=[]):
def project_on_sys_path(self, include_dists=()):
self.run_command('egg_info')

# Build extensions in-place
Expand Down
2 changes: 1 addition & 1 deletion setuptools/config/_validate_pyproject/error_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"must not be there",
)

_NEED_DETAILS = {"anyOf", "oneOf", "anyOf", "contains", "propertyNames", "not", "items"}
_NEED_DETAILS = {"anyOf", "oneOf", "contains", "propertyNames", "not", "items"}

_CAMEL_CASE_SPLITTER = re.compile(r"\W+|([A-Z][^A-Z\W]*)")
_IDENTIFIER = re.compile(r"^[\w_]+$", re.I)
Expand Down
8 changes: 4 additions & 4 deletions setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ def __setitem__(self, option_name, value):

try:
current_value = getattr(target_obj, option_name)
except AttributeError:
raise KeyError(option_name)
except AttributeError as e:
raise KeyError(option_name) from e

if current_value:
# Already inhabited. Skipping.
Expand Down Expand Up @@ -582,11 +582,11 @@ def _parse_version(self, value):
# accidentally include newlines and other unintended content
try:
Version(version)
except InvalidVersion:
except InvalidVersion as e:
raise OptionError(
f'Version loaded from {value} does not '
f'comply with PEP 440: {version}'
)
) from e

return version

Expand Down
2 changes: 1 addition & 1 deletion setuptools/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def patch_func(replacement, target_mod, func_name):


def get_unpatched_function(candidate):
return getattr(candidate, 'unpatched')
return getattr(candidate, 'unpatched', None)


def patch_for_msvc_specialized_compiler():
Expand Down
16 changes: 6 additions & 10 deletions setuptools/tests/config/test_setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,17 +957,13 @@ class TestExternalSetters:
# pbr or something else setting these values.
def _fake_distribution_init(self, dist, attrs):
saved_dist_init(dist, attrs)
# see self._DISTUTUILS_UNSUPPORTED_METADATA
setattr(dist.metadata, 'long_description_content_type', 'text/something')
# see self._DISTUTILS_UNSUPPORTED_METADATA
dist.metadata.long_description_content_type = 'text/something'
# Test overwrite setup() args
setattr(
dist.metadata,
'project_urls',
{
'Link One': 'https://example.com/one/',
'Link Two': 'https://example.com/two/',
},
)
dist.metadata.project_urls = {
'Link One': 'https://example.com/one/',
'Link Two': 'https://example.com/two/',
}
return None

@patch.object(_Distribution, '__init__', autospec=True)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@


class BuildBackendBase:
def __init__(self, cwd='.', env={}, backend_name='setuptools.build_meta'):
def __init__(self, cwd='.', env=None, backend_name='setuptools.build_meta'):
self.cwd = cwd
self.env = env
self.env = env or {}
self.backend_name = backend_name


Expand Down
5 changes: 3 additions & 2 deletions setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ def create_setup_requires_package(
version='0.1',
make_package=make_trivial_sdist,
setup_py_template=None,
setup_attrs={},
setup_attrs=None,
use_setup_cfg=(),
):
"""Creates a source tree under path for a trivial test package that has a
Expand All @@ -1213,7 +1213,8 @@ def create_setup_requires_package(
'setup_requires': ['%s==%s' % (distname, version)],
'dependency_links': [os.path.abspath(path)],
}
test_setup_attrs.update(setup_attrs)
if setup_attrs:
test_setup_attrs.update(setup_attrs)

test_pkg = os.path.join(path, 'test_pkg')
os.mkdir(test_pkg)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def test_sdist_with_latin1_encoded_filename(self):
else:
# The Latin-1 filename should have been skipped
filename = filename.decode('latin-1')
filename not in cmd.filelist.files
assert filename not in cmd.filelist.files

_EXAMPLE_DIRECTIVES = {
"setup.cfg - long_description and version": """
Expand Down
6 changes: 3 additions & 3 deletions setuptools/tests/test_setuptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def f1():
assert dep.extract_constant(fc, 'q', -1) is None

# constant assigned
dep.extract_constant(fc, 'x', -1) == "test"
assert dep.extract_constant(fc, 'x', -1) == "test"

# expression assigned
dep.extract_constant(fc, 'y', -1) == -1
assert dep.extract_constant(fc, 'y', -1) == -1

# recognized name, not assigned
dep.extract_constant(fc, 'z', -1) is None
assert dep.extract_constant(fc, 'z', -1) is None

def testFindModule(self):
with pytest.raises(ImportError):
Expand Down
4 changes: 2 additions & 2 deletions tools/build_launchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def get_msbuild():
]
try:
return subprocess.check_output(cmd, encoding='utf-8', text=True).strip()
except subprocess.CalledProcessError:
raise SystemExit("Unable to find MSBuild; check Visual Studio install")
except subprocess.CalledProcessError as e:
raise SystemExit("Unable to find MSBuild; check Visual Studio install") from e


def do_build(arena, platform, target):
Expand Down