Skip to content

Commit 4268969

Browse files
committed
Enable lints around return statements
This enables a class of return-related lints[^1] around return statements. I mainly came here for redundant returns after `else`[^2], but they all seemed useful. In general this seems to reduce nesting, and also make overall flow clearer. [^1]: https://docs.astral.sh/ruff/rules/#flake8-return-ret [^2]: https://docs.astral.sh/ruff/rules/superfluous-else-return/
1 parent 1092e9c commit 4268969

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

btest

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ def ExpandBackticks(origvalue):
263263

264264
return out.strip()
265265

266-
value = reBackticks.sub(_exec, origvalue)
267-
268-
return value
266+
return reBackticks.sub(_exec, origvalue)
269267

270268

271269
# We monkey-patch the config parser to provide an alternative method that
@@ -1488,12 +1486,11 @@ class Test:
14881486
self.diagmsgs += [f"'{cmdline}' succeeded unexpectedly (exit code 0)"]
14891487
return (False, 0)
14901488

1491-
else:
1492-
if not cmd.expect_success:
1493-
return (True, rc)
1489+
if not cmd.expect_success:
1490+
return (True, rc)
14941491

1495-
self.diagmsgs += [f"'{cmdline}' failed unexpectedly (exit code {rc})"]
1496-
return (False, rc)
1492+
self.diagmsgs += [f"'{cmdline}' failed unexpectedly (exit code {rc})"]
1493+
return (False, rc)
14971494

14981495
def rmTmp(self, *, with_close=False):
14991496
if with_close:
@@ -1553,8 +1550,8 @@ class Test:
15531550
def timePostfix(self):
15541551
if self.utime_base >= 0 and self.utime >= 0:
15551552
return f" ({self.utime_perc:+.1f}%)"
1556-
else:
1557-
return ""
1553+
1554+
return ""
15581555

15591556
# Picks up any progress output that has a test has written out.
15601557
def parseProgress(self):
@@ -1612,8 +1609,8 @@ class OutputHandler:
16121609
# requested, plus 1 for "#".
16131610
width = len(str(self.options().threads)) + 1
16141611
return f"[{mp.current_process().name:>{width}}]"
1615-
else:
1616-
return ""
1612+
1613+
return ""
16171614

16181615
def _output(self, msg, nl=True, file=None):
16191616
if not file:
@@ -2555,10 +2552,10 @@ def readTestFile(filename):
25552552
t = Test(filename)
25562553
if t.parse(content, filename):
25572554
return t
2558-
else:
2559-
return None
2560-
else:
2561-
return previous.clone(content)
2555+
2556+
return None
2557+
2558+
return previous.clone(content)
25622559

25632560
if os.path.basename(filename) == ".btest-ignore":
25642561
return []

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ per-file-ignores = """
7373
"""
7474

7575
[tool.ruff.lint]
76-
select = ["C4", "F", "I", "ISC", "UP"]
76+
select = ["C4", "F", "I", "ISC", "RET", "UP"]

0 commit comments

Comments
 (0)