Skip to content

Commit 045ad5a

Browse files
zkneupperZachary Kneupper
and
Zachary Kneupper
authored
Replaced if-else statements with ternary expression (#8658)
* Replace if-else with ternary expression * assign out variable in readouterr() with ternary expression * assign err variable in readouterr() with ternary expression * Assign precision with ternary expression * ternary expression for collected/collecting * Assign thread_name with ternary expression * Update AUTHORS Co-authored-by: Zachary Kneupper <[email protected]>
1 parent 7cec85a commit 045ad5a

File tree

6 files changed

+7
-24
lines changed

6 files changed

+7
-24
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,5 +333,6 @@ Xuan Luong
333333
Xuecong Liao
334334
Yoav Caspi
335335
Zac Hatfield-Dodds
336+
Zachary Kneupper
336337
Zoltán Máté
337338
Zsolt Cserna

scripts/release.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ def pre_release(version, *, skip_check_links):
100100

101101

102102
def changelog(version, write_out=False):
103-
if write_out:
104-
addopts = []
105-
else:
106-
addopts = ["--draft"]
103+
addopts = [] if write_out else ["--draft"]
107104
check_call(["towncrier", "--yes", "--version", version] + addopts)
108105

109106

src/_pytest/capture.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,8 @@ def is_started(self) -> bool:
618618
return self._state == "started"
619619

620620
def readouterr(self) -> CaptureResult[AnyStr]:
621-
if self.out:
622-
out = self.out.snap()
623-
else:
624-
out = ""
625-
if self.err:
626-
err = self.err.snap()
627-
else:
628-
err = ""
621+
out = self.out.snap() if self.out else ""
622+
err = self.err.snap() if self.err else ""
629623
return CaptureResult(out, err)
630624

631625

src/_pytest/doctest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,7 @@ def _remove_unwanted_precision(self, want: str, got: str) -> str:
647647
exponent: Optional[str] = w.group("exponent1")
648648
if exponent is None:
649649
exponent = w.group("exponent2")
650-
if fraction is None:
651-
precision = 0
652-
else:
653-
precision = len(fraction)
650+
precision = 0 if fraction is None else len(fraction)
654651
if exponent is not None:
655652
precision -= int(exponent)
656653
if float(w.group()) == approx(float(g.group()), abs=10 ** -precision):

src/_pytest/terminal.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,7 @@ def report_collect(self, final: bool = False) -> None:
669669
skipped = len(self.stats.get("skipped", []))
670670
deselected = len(self.stats.get("deselected", []))
671671
selected = self._numcollected - errors - skipped - deselected
672-
if final:
673-
line = "collected "
674-
else:
675-
line = "collecting "
672+
line = "collected " if final else "collecting "
676673
line += (
677674
str(self._numcollected) + " item" + ("" if self._numcollected == 1 else "s")
678675
)

src/_pytest/threadexception.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ def thread_exception_runtest_hook() -> Generator[None, None, None]:
6161
with catch_threading_exception() as cm:
6262
yield
6363
if cm.args:
64-
if cm.args.thread is not None:
65-
thread_name = cm.args.thread.name
66-
else:
67-
thread_name = "<unknown>"
64+
thread_name = "<unknown>" if cm.args.thread is None else cm.args.thread.name
6865
msg = f"Exception in thread {thread_name}\n\n"
6966
msg += "".join(
7067
traceback.format_exception(

0 commit comments

Comments
 (0)