Skip to content

Commit ad8c7ba

Browse files
authored
Merge pull request #4450 from DimitriPapadopoulos/TRY
Enforce ruff/tryceratops rule TRY300
2 parents 11b2f5f + 92989c2 commit ad8c7ba

File tree

9 files changed

+21
-20
lines changed

9 files changed

+21
-20
lines changed

pkg_resources/extern/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ def load_module(self, fullname: str):
4141
"""
4242
root, base, target = fullname.partition(self.root_name + '.')
4343
for prefix in self.search_path:
44+
extant = prefix + target
4445
try:
45-
extant = prefix + target
4646
__import__(extant)
47-
mod = sys.modules[extant]
48-
sys.modules[fullname] = mod
49-
return mod
5047
except ImportError:
51-
pass
48+
continue
49+
mod = sys.modules[extant]
50+
sys.modules[fullname] = mod
51+
return mod
5252
else:
5353
raise ImportError(
5454
"The '{target}' package is required; "

ruff.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ extend-select = [
1414
"F404", # late-future-import
1515
"PYI", # flake8-pyi
1616
"UP", # pyupgrade
17+
"TRY",
1718
"YTT", # flake8-2020
1819
]
1920
ignore = [
21+
"TRY301", # raise-within-try, it's handy
2022
"UP015", # redundant-open-modes, explicit is preferred
2123
"UP030", # temporarily disabled
2224
"UP031", # temporarily disabled

setuptools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def _get_project_config_files(self, filenames=None):
5757
"""Ignore ``pyproject.toml``, they are not related to setup_requires"""
5858
try:
5959
cfg, toml = super()._split_standard_project_metadata(filenames)
60-
return cfg, ()
6160
except Exception:
6261
return filenames, ()
62+
return cfg, ()
6363

6464
def finalize_options(self):
6565
"""

setuptools/command/easy_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def _to_bytes(s):
102102
def isascii(s):
103103
try:
104104
s.encode('ascii')
105-
return True
106105
except UnicodeError:
107106
return False
107+
return True
108108

109109

110110
def _one_liner(text):

setuptools/config/_validate_pyproject/formats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ def pep508(value: str) -> bool:
9191
"""
9292
try:
9393
_req.Requirement(value)
94-
return True
9594
except _req.InvalidRequirement:
9695
return False
96+
return True
9797

9898
except ImportError: # pragma: no cover
9999
_logger.warning(

setuptools/depends.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ def get_version(self, paths=None, default="unknown"):
5858
if self.attribute is None:
5959
try:
6060
f, p, i = find_module(self.module, paths)
61-
if f:
62-
f.close()
63-
return default
6461
except ImportError:
6562
return None
63+
if f:
64+
f.close()
65+
return default
6666

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

setuptools/extension.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ def _have_cython():
1616
try:
1717
# from (cython_impl) import build_ext
1818
__import__(cython_impl, fromlist=['build_ext']).build_ext
19-
return True
2019
except Exception:
21-
pass
22-
return False
20+
return False
21+
return True
2322

2423

2524
# for compatibility

setuptools/extern/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def load_module(self, fullname):
3232
"""
3333
root, base, target = fullname.partition(self.root_name + '.')
3434
for prefix in self.search_path:
35+
extant = prefix + target
3536
try:
36-
extant = prefix + target
3737
__import__(extant)
38-
mod = sys.modules[extant]
39-
sys.modules[fullname] = mod
40-
return mod
4138
except ImportError:
42-
pass
39+
continue
40+
mod = sys.modules[extant]
41+
sys.modules[fullname] = mod
42+
return mod
4343
else:
4444
raise ImportError(
4545
"The '{target}' package is required; "

setuptools/tests/test_sdist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ def touch(path):
122122
def symlink_or_skip_test(src, dst):
123123
try:
124124
os.symlink(src, dst)
125-
return dst
126125
except (OSError, NotImplementedError):
127126
pytest.skip("symlink not supported in OS")
127+
return dst
128128

129129

130130
class TestSdistTest:

0 commit comments

Comments
 (0)