Merge pull request #7487 from ThomasWaldmann/pyupgrade-py39-plus

pyupgrade --py39-plus ./**/*.py
This commit is contained in:
TW 2023-04-02 23:02:07 +02:00 committed by GitHub
commit ffea8a0f25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 14 deletions

View File

@ -885,7 +885,7 @@ Duration: {0.duration}
item_size = item.size
if item_size != item_chunks_size:
raise BackupError(
"Size inconsistency detected: size {}, chunks size {}".format(item_size, item_chunks_size)
f"Size inconsistency detected: size {item_size}, chunks size {item_chunks_size}"
)
if has_damaged_chunks:
raise BackupError("File has damaged (all-zero) chunks. Try running borg check --repair.")

View File

@ -244,7 +244,7 @@ class DebugMixIn:
if len(id) != 32: # 256bit
raise ValueError("id must be 256bits or 64 hex digits")
except ValueError as err:
print("object id %s is invalid [%s]." % (hex_id, str(err)))
print(f"object id {hex_id} is invalid [{str(err)}].")
return EXIT_ERROR
try:
data = repository.get(id)
@ -277,7 +277,7 @@ class DebugMixIn:
if len(id) != 32: # 256bit
raise ValueError("id must be 256bits or 64 hex digits")
except ValueError as err:
print("object id %s is invalid [%s]." % (hex_id, str(err)))
print(f"object id {hex_id} is invalid [{str(err)}].")
return EXIT_ERROR
with open(args.object_path, "rb") as f:
@ -305,13 +305,13 @@ class DebugMixIn:
if len(id) != 32: # 256bit
raise ValueError("id must be 256bits or 64 hex digits")
except ValueError as err:
print("object id %s is invalid [%s]." % (hex_id, str(err)))
print(f"object id {hex_id} is invalid [{str(err)}].")
return EXIT_ERROR
with open(args.binary_path, "rb") as f:
data = f.read()
with open(args.json_path, "r") as f:
with open(args.json_path) as f:
meta = json.load(f)
repo_objs = manifest.repo_objs
@ -332,7 +332,7 @@ class DebugMixIn:
if len(id) != 32: # 256bit
raise ValueError("id must be 256bits or 64 hex digits")
except ValueError as err:
print("object id %s is invalid [%s]." % (hex_id, str(err)))
print(f"object id {hex_id} is invalid [{str(err)}].")
return EXIT_ERROR
repository.put(id, data)
print("object %s put." % hex_id)

View File

@ -156,9 +156,7 @@ class PruneMixIn:
rule=kept_because[archive.id][0], num=kept_because[archive.id][1]
)
if args.output_list:
list_logger.info(
"{message:<40} {archive}".format(message=log_message, archive=format_archive(archive))
)
list_logger.info(f"{log_message:<40} {format_archive(archive)}")
pi.finish()
if sig_int:
# Ctrl-C / SIGINT: do not checkpoint (commit) again, we already have a checkpoint in this case.

View File

@ -1033,7 +1033,7 @@ def ellipsis_truncate(msg, space):
# if there is very little space, just show ...
return "..." + " " * (space - ellipsis_width)
if space < ellipsis_width + msg_width:
return "{}...{}".format(swidth_slice(msg, space // 2 - ellipsis_width), swidth_slice(msg, -space // 2))
return f"{swidth_slice(msg, space // 2 - ellipsis_width)}...{swidth_slice(msg, -space // 2)}"
return msg + " " * (space - msg_width)

View File

@ -56,7 +56,7 @@ class Passphrase(str):
# passcommand is a system command (not inside pyinstaller env)
env = prepare_subprocess_env(system=True)
try:
passphrase = subprocess.check_output(shlex.split(passcommand), universal_newlines=True, env=env)
passphrase = subprocess.check_output(shlex.split(passcommand), text=True, env=env)
except (subprocess.CalledProcessError, FileNotFoundError) as e:
raise PasscommandFailure(e)
return cls(passphrase.rstrip("\n"))

View File

@ -5,7 +5,7 @@ import re
from collections import abc, namedtuple
from datetime import datetime, timedelta, timezone
from operator import attrgetter
from typing import Sequence, FrozenSet
from collections.abc import Sequence
from .logger import create_logger
@ -211,7 +211,7 @@ class Manifest:
NO_OPERATION_CHECK: Sequence[Operation] = tuple()
SUPPORTED_REPO_FEATURES: FrozenSet[str] = frozenset([])
SUPPORTED_REPO_FEATURES: frozenset[str] = frozenset([])
MANIFEST_ID = b"\0" * 32

View File

@ -1693,7 +1693,7 @@ class LoggedIO:
size, tag, key, data = self._read(fd, header, segment, offset, (TAG_PUT2, TAG_PUT), read_data=read_data)
if id != key:
raise IntegrityError(
"Invalid segment entry header, is not for wanted id [segment {}, offset {}]".format(segment, offset)
f"Invalid segment entry header, is not for wanted id [segment {segment}, offset {offset}]"
)
data_size_from_header = size - header_size(tag)
if expected_size is not None and expected_size != data_size_from_header: