simplify if statements by using walrus operators (#7671)

This commit is contained in:
Mike Fährmann
2025-07-22 18:34:38 +02:00
parent e8b2a496ba
commit a097a373a9
83 changed files with 239 additions and 466 deletions

View File

@@ -22,8 +22,7 @@ class PostProcessor():
return self.__class__.__name__
def _init_archive(self, job, options, prefix=None):
archive_path = options.get("archive")
if archive_path:
if archive_path := options.get("archive"):
extr = job.extractor
archive_table = options.get("archive-table")

View File

@@ -21,8 +21,7 @@ class ComparePP(PostProcessor):
self._compare = self._compare_size
self._equal_exc = self._equal_cnt = 0
equal = options.get("equal")
if equal:
if equal := options.get("equal"):
equal, _, emax = equal.partition(":")
self._equal_max = text.parse_int(emax)
if equal == "abort":

View File

@@ -55,8 +55,7 @@ class MetadataPP(PostProcessor):
self._json_encode = self._make_encoder(options, 4).encode
ext = "json"
base_directory = options.get("base-directory")
if base_directory:
if base_directory := options.get("base-directory"):
if base_directory is True:
self._base = lambda p: p.basedirectory
else:
@@ -181,8 +180,7 @@ class MetadataPP(PostProcessor):
try:
pathfmt.directory_formatters = self._directory_formatters
pathfmt.directory_conditions = ()
segments = pathfmt.build_directory(pathfmt.kwdict)
if segments:
if segments := pathfmt.build_directory(pathfmt.kwdict):
directory = pathfmt.clean_path(os.sep.join(segments) + os.sep)
else:
directory = "." + os.sep
@@ -244,8 +242,7 @@ class MetadataPP(PostProcessor):
fp.write(self._json_encode(kwdict) + "\n")
def _make_filter(self, options):
include = options.get("include")
if include:
if include := options.get("include"):
if isinstance(include, str):
include = include.split(",")
return lambda d: {k: d[k] for k in include if k in d}

View File

@@ -17,8 +17,7 @@ class MtimePP(PostProcessor):
def __init__(self, job, options):
PostProcessor.__init__(self, job)
value = options.get("value")
if value:
if value := options.get("value"):
self._get = formatter.parse(value, None, util.identity).format_map
else:
key = options.get("key", "date")

View File

@@ -296,8 +296,7 @@ class UgoiraPP(PostProcessor):
def _exec(self, args):
self.log.debug(args)
out = None if self.output else subprocess.DEVNULL
retcode = util.Popen(args, stdout=out, stderr=out).wait()
if retcode:
if retcode := util.Popen(args, stdout=out, stderr=out).wait():
output.stderr_write("\n")
self.log.error("Non-zero exit status when running %s (%s)",
args, retcode)