Преглед изворни кода

Convert percent-style string formatting to f-strings

Jelmer Vernooij пре 2 месеци
родитељ
комит
2481e7c8a7
3 измењених фајлова са 9 додато и 6 уклоњено
  1. 6 3
      dulwich/hooks.py
  2. 2 2
      dulwich/porcelain.py
  3. 1 1
      dulwich/protocol.py

+ 6 - 3
dulwich/hooks.py

@@ -226,9 +226,12 @@ class PostReceiveShellHook(ShellHook):
             out_data, err_data = p.communicate(in_data)
 
             if (p.returncode != 0) or err_data:
-                err_fmt = b"post-receive exit code: %d\n" + b"stdout:\n%s\nstderr:\n%s"
-                err_msg = err_fmt % (p.returncode, out_data, err_data)
-                raise HookError(err_msg.decode("utf-8", "backslashreplace"))
+                err_msg = (
+                    f"post-receive exit code: {p.returncode}\n"
+                    f"stdout:\n{out_data.decode('utf-8', 'backslashreplace')}\n"
+                    f"stderr:\n{err_data.decode('utf-8', 'backslashreplace')}"
+                )
+                raise HookError(err_msg)
             return out_data
         except OSError as err:
             raise HookError(repr(err)) from err

+ 2 - 2
dulwich/porcelain.py

@@ -3075,10 +3075,10 @@ def push(
         for ref, error in (result.ref_status or {}).items():
             if error is not None:
                 errstream.write(
-                    b"Push of ref %s failed: %s\n" % (ref, error.encode(err_encoding))
+                    f"Push of ref {ref.decode('utf-8', 'replace')} failed: {error}\n".encode(err_encoding)
                 )
             else:
-                errstream.write(b"Ref %s updated\n" % ref)
+                errstream.write(f"Ref {ref.decode('utf-8', 'replace')} updated\n".encode())
 
         if remote_name is not None:
             _import_remote_refs(r.refs, remote_name, remote_changed_refs)

+ 1 - 1
dulwich/protocol.py

@@ -247,7 +247,7 @@ def pkt_line(data: bytes | None) -> bytes:
     """
     if data is None:
         return b"0000"
-    return ("%04x" % (len(data) + 4)).encode("ascii") + data
+    return f"{len(data) + 4:04x}".encode("ascii") + data
 
 
 def pkt_seq(*seq: bytes | None) -> bytes: