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 <zacharykneupper@Zacharys-MBP.lan>
This commit is contained in:
Zack Kneupper 2021-05-11 05:52:55 -04:00 committed by GitHub
parent 7cec85a37d
commit 045ad5ac2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 24 deletions

View File

@ -333,5 +333,6 @@ Xuan Luong
Xuecong Liao
Yoav Caspi
Zac Hatfield-Dodds
Zachary Kneupper
Zoltán Máté
Zsolt Cserna

View File

@ -100,10 +100,7 @@ def pre_release(version, *, skip_check_links):
def changelog(version, write_out=False):
if write_out:
addopts = []
else:
addopts = ["--draft"]
addopts = [] if write_out else ["--draft"]
check_call(["towncrier", "--yes", "--version", version] + addopts)

View File

@ -618,14 +618,8 @@ class MultiCapture(Generic[AnyStr]):
return self._state == "started"
def readouterr(self) -> CaptureResult[AnyStr]:
if self.out:
out = self.out.snap()
else:
out = ""
if self.err:
err = self.err.snap()
else:
err = ""
out = self.out.snap() if self.out else ""
err = self.err.snap() if self.err else ""
return CaptureResult(out, err)

View File

@ -647,10 +647,7 @@ def _init_checker_class() -> Type["doctest.OutputChecker"]:
exponent: Optional[str] = w.group("exponent1")
if exponent is None:
exponent = w.group("exponent2")
if fraction is None:
precision = 0
else:
precision = len(fraction)
precision = 0 if fraction is None else len(fraction)
if exponent is not None:
precision -= int(exponent)
if float(w.group()) == approx(float(g.group()), abs=10 ** -precision):

View File

@ -669,10 +669,7 @@ class TerminalReporter:
skipped = len(self.stats.get("skipped", []))
deselected = len(self.stats.get("deselected", []))
selected = self._numcollected - errors - skipped - deselected
if final:
line = "collected "
else:
line = "collecting "
line = "collected " if final else "collecting "
line += (
str(self._numcollected) + " item" + ("" if self._numcollected == 1 else "s")
)

View File

@ -61,10 +61,7 @@ def thread_exception_runtest_hook() -> Generator[None, None, None]:
with catch_threading_exception() as cm:
yield
if cm.args:
if cm.args.thread is not None:
thread_name = cm.args.thread.name
else:
thread_name = "<unknown>"
thread_name = "<unknown>" if cm.args.thread is None else cm.args.thread.name
msg = f"Exception in thread {thread_name}\n\n"
msg += "".join(
traceback.format_exception(