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

@@ -71,8 +71,7 @@ class HttpDownloader(DownloaderBase):
self.chunk_size = chunk_size
if self.rate:
func = util.build_selection_func(self.rate, 0, text.parse_bytes)
rmax = func.args[1] if hasattr(func, "args") else func()
if rmax:
if rmax := func.args[1] if hasattr(func, "args") else func():
if rmax < self.chunk_size:
# reduce chunk_size to allow for one iteration each second
self.chunk_size = rmax
@@ -141,15 +140,13 @@ class HttpDownloader(DownloaderBase):
# collect HTTP headers
headers = {"Accept": "*/*"}
# file-specific headers
extra = kwdict.get("_http_headers")
if extra:
if extra := kwdict.get("_http_headers"):
headers.update(extra)
# general headers
if self.headers:
headers.update(self.headers)
# partial content
file_size = pathfmt.part_size()
if file_size:
if file_size := pathfmt.part_size():
headers["Range"] = f"bytes={file_size}-"
# connect to (remote) source
@@ -424,8 +421,7 @@ class HttpDownloader(DownloaderBase):
if mtype in MIME_TYPES:
return MIME_TYPES[mtype]
ext = mimetypes.guess_extension(mtype, strict=False)
if ext:
if ext := mimetypes.guess_extension(mtype, strict=False):
return ext[1:]
self.log.warning("Unknown MIME type '%s'", mtype)