浏览代码

Use f-strings

Jelmer Vernooij 1 年之前
父节点
当前提交
b4eed48680
共有 5 个文件被更改,包括 6 次插入31 次删除
  1. 1 6
      dulwich/client.py
  2. 2 10
      dulwich/contrib/swift.py
  3. 1 6
      dulwich/ignore.py
  4. 1 6
      dulwich/lru_cache.py
  5. 1 3
      examples/latest_change.py

+ 1 - 6
dulwich/client.py

@@ -333,12 +333,7 @@ class FetchPackResult:
         return super().__getattribute__(name)
 
     def __repr__(self) -> str:
-        return "{}({!r}, {!r}, {!r})".format(
-            self.__class__.__name__,
-            self.refs,
-            self.symrefs,
-            self.agent,
-        )
+        return f"{self.__class__.__name__}({self.refs!r}, {self.symrefs!r}, {self.agent!r})"
 
 
 class SendPackResult:

+ 2 - 10
dulwich/contrib/swift.py

@@ -257,11 +257,7 @@ class SwiftConnector:
         if ret.status_code < 200 or ret.status_code >= 300:
             raise SwiftException(
                 "AUTH v1.0 request failed on "
-                + "{} with error code {} ({})".format(
-                    str(auth_httpclient.get_base_url()) + path,
-                    ret.status_code,
-                    str(ret.items()),
-                )
+                + f"{str(auth_httpclient.get_base_url()) + path} with error code {ret.status_code} ({ret.items()!s})"
             )
         storage_url = ret["X-Storage-Url"]
         token = ret["X-Auth-Token"]
@@ -292,11 +288,7 @@ class SwiftConnector:
         if ret.status_code < 200 or ret.status_code >= 300:
             raise SwiftException(
                 "AUTH v2.0 request failed on "
-                + "{} with error code {} ({})".format(
-                    str(auth_httpclient.get_base_url()) + path,
-                    ret.status_code,
-                    str(ret.items()),
-                )
+                + f"{str(auth_httpclient.get_base_url()) + path} with error code {ret.status_code} ({ret.items()!s})"
             )
         auth_ret_json = json.loads(ret.read())
         token = auth_ret_json["access"]["token"]["id"]

+ 1 - 6
dulwich/ignore.py

@@ -299,12 +299,7 @@ class IgnoreFilterManager:
         self._ignorecase = ignorecase
 
     def __repr__(self) -> str:
-        return "{}({}, {!r}, {!r})".format(
-            type(self).__name__,
-            self._top_path,
-            self._global_filters,
-            self._ignorecase,
-        )
+        return f"{type(self).__name__}({self._top_path}, {self._global_filters!r}, {self._ignorecase!r})"
 
     def _load_path(self, path: str) -> Optional[IgnoreFilter]:
         try:

+ 1 - 6
dulwich/lru_cache.py

@@ -55,12 +55,7 @@ class _LRUNode(Generic[K, V]):
             prev_key = None
         else:
             prev_key = self.prev.key
-        return "{}({!r} n:{!r} p:{!r})".format(
-            self.__class__.__name__,
-            self.key,
-            self.next_key,
-            prev_key,
-        )
+        return f"{self.__class__.__name__}({self.key!r} n:{self.next_key!r} p:{prev_key!r})"
 
     def run_cleanup(self) -> None:
         if self.cleanup is not None:

+ 1 - 3
examples/latest_change.py

@@ -21,7 +21,5 @@ except StopIteration:
     print("No file %s anywhere in history." % sys.argv[1])
 else:
     print(
-        "{} was last changed by {} at {} (commit {})".format(
-            sys.argv[1], c.author, time.ctime(c.author_time), c.id
-        )
+        f"{sys.argv[1]} was last changed by {c.author} at {time.ctime(c.author_time)} (commit {c.id})"
     )