Skip to content

Commit d42a6aa

Browse files
authored
Merge pull request #266 from DimitriPapadopoulos/TRY
Enforce ruff/tryceratops rules (TRY)
2 parents 6c224d3 + d0e3de1 commit d42a6aa

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

distutils/command/install_lib.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def finalize_options(self):
8181
if not isinstance(self.optimize, int):
8282
try:
8383
self.optimize = int(self.optimize)
84-
if self.optimize not in (0, 1, 2):
85-
raise AssertionError
86-
except (ValueError, AssertionError):
84+
except ValueError:
85+
pass
86+
if self.optimize not in (0, 1, 2):
8787
raise DistutilsOptionError("optimize must be 0, 1, or 2")
8888

8989
def run(self):

distutils/cygwinccompiler.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ def check_config_h():
308308
fn = sysconfig.get_config_h_filename()
309309
try:
310310
config_h = pathlib.Path(fn).read_text(encoding='utf-8')
311+
except OSError as exc:
312+
return (CONFIG_H_UNCERTAIN, f"couldn't read '{fn}': {exc.strerror}")
313+
else:
311314
substring = '__GNUC__'
312315
if substring in config_h:
313316
code = CONFIG_H_OK
@@ -316,8 +319,6 @@ def check_config_h():
316319
code = CONFIG_H_NOTOK
317320
mention_inflected = 'does not mention'
318321
return code, f"{fn!r} {mention_inflected} {substring!r}"
319-
except OSError as exc:
320-
return (CONFIG_H_UNCERTAIN, f"couldn't read '{fn}': {exc.strerror}")
321322

322323

323324
def is_cygwincc(cc):

distutils/extension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __init__(
105105
**kw, # To catch unknown keywords
106106
):
107107
if not isinstance(name, str):
108-
raise AssertionError("'name' must be a string")
108+
raise AssertionError("'name' must be a string") # noqa: TRY004
109109
if not (
110110
isinstance(sources, list)
111111
and all(isinstance(v, (str, os.PathLike)) for v in sources)

distutils/file_util.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ def copy_file( # noqa: C901
140140
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
141141
try:
142142
os.link(src, dst)
143-
return (dst, 1)
144143
except OSError:
145144
# If hard linking fails, fall back on copying file
146145
# (some special filesystems don't support hard linking
147146
# even under Unix, see issue #8876).
148147
pass
148+
else:
149+
return (dst, 1)
149150
elif link == 'sym':
150151
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
151152
os.symlink(src, dst)

distutils/msvc9compiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def load_macros(self, version):
154154
if version >= 8.0:
155155
self.set_macro("FrameworkSDKDir", NET_BASE, "sdkinstallrootv2.0")
156156
else:
157-
raise KeyError("sdkinstallrootv2.0")
157+
raise KeyError("sdkinstallrootv2.0") # noqa: TRY301
158158
except KeyError:
159159
raise DistutilsPlatformError(
160160
"""Python was built with Visual Studio 2008;

ruff.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ extend-select = [
1111
"PERF",
1212
"RUF010",
1313
"RUF100",
14+
"TRY",
1415
"UP",
1516
]
1617
ignore = [
1718
# local
1819
"PERF203",
20+
"TRY003",
1921

20-
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
22+
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
2123
"W191",
2224
"E111",
2325
"E114",

0 commit comments

Comments
 (0)