소스 검색

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

pyupgrade --py39-plus ./**/*.py
TW 2 년 전
부모
커밋
ffea8a0f25
7개의 변경된 파일12개의 추가작업 그리고 14개의 파일을 삭제
  1. 1 1
      src/borg/archive.py
  2. 5 5
      src/borg/archiver/debug_cmd.py
  3. 1 3
      src/borg/archiver/prune_cmd.py
  4. 1 1
      src/borg/helpers/parseformat.py
  5. 1 1
      src/borg/helpers/passphrase.py
  6. 2 2
      src/borg/manifest.py
  7. 1 1
      src/borg/repository.py

+ 1 - 1
src/borg/archive.py

@@ -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.")

+ 5 - 5
src/borg/archiver/debug_cmd.py

@@ -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)

+ 1 - 3
src/borg/archiver/prune_cmd.py

@@ -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.

+ 1 - 1
src/borg/helpers/parseformat.py

@@ -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)
 
 

+ 1 - 1
src/borg/helpers/passphrase.py

@@ -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"))

+ 2 - 2
src/borg/manifest.py

@@ -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
 

+ 1 - 1
src/borg/repository.py

@@ -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: