Skip to content

Commit

Permalink
Merge pull request #4450 from DimitriPapadopoulos/TRY
Browse files Browse the repository at this point in the history
Enforce ruff/tryceratops rule TRY300
  • Loading branch information
jaraco authored Jun 29, 2024
2 parents 11b2f5f + 92989c2 commit ad8c7ba
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
10 changes: 5 additions & 5 deletions pkg_resources/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def load_module(self, fullname: str):
"""
root, base, target = fullname.partition(self.root_name + '.')
for prefix in self.search_path:
extant = prefix + target
try:
extant = prefix + target
__import__(extant)
mod = sys.modules[extant]
sys.modules[fullname] = mod
return mod
except ImportError:
pass
continue
mod = sys.modules[extant]
sys.modules[fullname] = mod
return mod
else:
raise ImportError(
"The '{target}' package is required; "
Expand Down
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ extend-select = [
"F404", # late-future-import
"PYI", # flake8-pyi
"UP", # pyupgrade
"TRY",
"YTT", # flake8-2020
]
ignore = [
"TRY301", # raise-within-try, it's handy
"UP015", # redundant-open-modes, explicit is preferred
"UP030", # temporarily disabled
"UP031", # temporarily disabled
Expand Down
2 changes: 1 addition & 1 deletion setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ 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)
return cfg, ()
except Exception:
return filenames, ()
return cfg, ()

def finalize_options(self):
"""
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 @@ -102,9 +102,9 @@ def _to_bytes(s):
def isascii(s):
try:
s.encode('ascii')
return True
except UnicodeError:
return False
return True


def _one_liner(text):
Expand Down
2 changes: 1 addition & 1 deletion setuptools/config/_validate_pyproject/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def pep508(value: str) -> bool:
"""
try:
_req.Requirement(value)
return True
except _req.InvalidRequirement:
return False
return True

except ImportError: # pragma: no cover
_logger.warning(
Expand Down
6 changes: 3 additions & 3 deletions setuptools/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def get_version(self, paths=None, default="unknown"):
if self.attribute is None:
try:
f, p, i = find_module(self.module, paths)
if f:
f.close()
return default
except ImportError:
return None
if f:
f.close()
return default

v = get_module_constant(self.module, self.attribute, default, paths)

Expand Down
5 changes: 2 additions & 3 deletions setuptools/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ def _have_cython():
try:
# from (cython_impl) import build_ext
__import__(cython_impl, fromlist=['build_ext']).build_ext
return True
except Exception:
pass
return False
return False
return True


# for compatibility
Expand Down
10 changes: 5 additions & 5 deletions setuptools/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def load_module(self, fullname):
"""
root, base, target = fullname.partition(self.root_name + '.')
for prefix in self.search_path:
extant = prefix + target
try:
extant = prefix + target
__import__(extant)
mod = sys.modules[extant]
sys.modules[fullname] = mod
return mod
except ImportError:
pass
continue
mod = sys.modules[extant]
sys.modules[fullname] = mod
return mod
else:
raise ImportError(
"The '{target}' package is required; "
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 @@ -122,9 +122,9 @@ def touch(path):
def symlink_or_skip_test(src, dst):
try:
os.symlink(src, dst)
return dst
except (OSError, NotImplementedError):
pytest.skip("symlink not supported in OS")
return dst


class TestSdistTest:
Expand Down

0 comments on commit ad8c7ba

Please sign in to comment.