Browse Source

Merge pull request #7996 from ThomasWaldmann/pyupgrade-py39-1.4

pyupgrade py39 (1.4-maint)
TW 1 year ago
parent
commit
043294226b
3 changed files with 7 additions and 7 deletions
  1. 3 3
      src/borg/archiver.py
  2. 2 2
      src/borg/crypto/key.py
  3. 2 2
      src/borg/testsuite/chunker_pytest.py

+ 3 - 3
src/borg/archiver.py

@@ -1449,7 +1449,7 @@ class Archiver:
 
     def _info_archives(self, args, repository, manifest, key, cache):
         def format_cmdline(cmdline):
-            return remove_surrogates(' '.join(shlex.quote(x) for x in cmdline))
+            return remove_surrogates(shlex.join(cmdline))
 
         if args.location.archive:
             archive_names = (args.location.archive,)
@@ -2212,7 +2212,7 @@ class Archiver:
             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)
@@ -2244,7 +2244,7 @@ class Archiver:
             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)

+ 2 - 2
src/borg/crypto/key.py

@@ -512,7 +512,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'))
@@ -785,7 +785,7 @@ class KeyfileKey(ID_HMAC_SHA_256, KeyfileKeyBase):
                 raise KeyfileMismatchError(self.repository._location.canonical_path(), filename)
         # we get here if it really looks like a borg key for this repo,
         # do some more checks that are close to how borg reads/parses the key.
-        with open(filename, 'r') as fd:
+        with open(filename) as fd:
             lines = fd.readlines()
             if len(lines) < 2:
                 logger.warning(f"borg key sanity check: expected 2+ lines total. [{filename}]")

+ 2 - 2
src/borg/testsuite/chunker_pytest.py

@@ -149,8 +149,8 @@ def test_buzhash_chunksize_distribution():
     chunks_count = len(chunks)
     min_chunksize_observed = min(chunk_sizes)
     max_chunksize_observed = max(chunk_sizes)
-    min_count = sum((int(size == 2 ** min_exp) for size in chunk_sizes))
-    max_count = sum((int(size == 2 ** max_exp) for size in chunk_sizes))
+    min_count = sum(int(size == 2 ** min_exp) for size in chunk_sizes)
+    max_count = sum(int(size == 2 ** max_exp) for size in chunk_sizes)
     print(f"count: {chunks_count} min: {min_chunksize_observed} max: {max_chunksize_observed} "
           f"min count: {min_count} max count: {max_count}")
     # usually there will about 64 chunks