diff --git a/src/borg/archiver/tar_cmds.py b/src/borg/archiver/tar_cmds.py index 73119e8ee..5c91ecb7c 100644 --- a/src/borg/archiver/tar_cmds.py +++ b/src/borg/archiver/tar_cmds.py @@ -293,10 +293,7 @@ class TarMixIn: tar = tarfile.open(fileobj=tarstream, mode="r|", ignore_zeros=args.ignore_zeros) - while True: - tarinfo = tar.next() - if not tarinfo: - break + while tarinfo := tar.next(): if tarinfo.isreg(): status = tfo.process_file(tarinfo=tarinfo, status="A", type=stat.S_IFREG, tar=tar) archive.stats.nfiles += 1 diff --git a/src/borg/cockpit/runner.py b/src/borg/cockpit/runner.py index b32e56ad0..010d39449 100644 --- a/src/borg/cockpit/runner.py +++ b/src/borg/cockpit/runner.py @@ -44,10 +44,7 @@ class BorgRunner: ) async def read_stream(stream, stream_name): - while True: - line = await stream.readline() - if not line: - break + while line := await stream.readline(): decoded_line = line.decode("utf-8", errors="replace").rstrip() if decoded_line: self.log_callback({"type": "stream_line", "stream": stream_name, "line": decoded_line}) diff --git a/src/borg/helpers/nanorst.py b/src/borg/helpers/nanorst.py index 3d7c3316e..ea3ac2024 100644 --- a/src/borg/helpers/nanorst.py +++ b/src/borg/helpers/nanorst.py @@ -65,10 +65,7 @@ def rst_to_text(text, state_hook=None, references=None): inline_single = ("*", "`") - while True: - char = text.read(1) - if not char: - break + while char := text.read(1): next = text.peek(1) # type: str if state == "text": diff --git a/src/borg/version.py b/src/borg/version.py index 6371dfa76..a42b4e30e 100644 --- a/src/borg/version.py +++ b/src/borg/version.py @@ -19,8 +19,7 @@ def parse_version(version): (?P\d+)\.(?P\d+)\.(?P\d+) # version, e.g. 1.2.33 (?P\.?(?Pa|b|rc|dev)(?P\d+))? # optional prerelease, e.g. a1 or b2 or rc33 or .dev1 """ - m = re.match(version_re, version, re.VERBOSE) - if m is None: + if (m := re.match(version_re, version, re.VERBOSE)) is None: raise ValueError("Invalid version string %s" % version) gd = m.groupdict() version = [int(gd["major"]), int(gd["minor"]), int(gd["patch"])]