소스 검색

Fix mypy issues

Jelmer Vernooij 10 달 전
부모
커밋
64815036fc
4개의 변경된 파일15개의 추가작업 그리고 12개의 파일을 삭제
  1. 8 6
      dulwich/diff_tree.py
  2. 1 1
      dulwich/objects.py
  3. 4 4
      dulwich/server.py
  4. 2 1
      fuzzing/fuzz-targets/fuzz_configfile.py

+ 8 - 6
dulwich/diff_tree.py

@@ -26,7 +26,8 @@ from io import BytesIO
 from itertools import chain
 from typing import Dict, List, Optional
 
-from .objects import S_ISGITLINK, Tree, TreeEntry
+from .object_store import BaseObjectStore
+from .objects import S_ISGITLINK, ObjectID, ShaFile, Tree, TreeEntry
 
 # TreeChange type constants.
 CHANGE_ADD = "add"
@@ -238,7 +239,8 @@ def _all_same(seq, key):
     return _all_eq(seq[1:], key, key(seq[0]))
 
 
-def tree_changes_for_merge(store, parent_tree_ids, tree_id, rename_detector=None):
+def tree_changes_for_merge(
+        store: BaseObjectStore, parent_tree_ids: List[ObjectID], tree_id: ObjectID, rename_detector=None):
     """Get the tree changes for a merge tree relative to all its parents.
 
     Args:
@@ -302,7 +304,7 @@ def tree_changes_for_merge(store, parent_tree_ids, tree_id, rename_detector=None
 _BLOCK_SIZE = 64
 
 
-def _count_blocks(obj):
+def _count_blocks(obj: ShaFile) -> Dict[int, int]:
     """Count the blocks in an object.
 
     Splits the data into blocks either on lines or <=64-byte chunks of lines.
@@ -324,10 +326,10 @@ def _count_blocks(obj):
     block_getvalue = block.getvalue
 
     for c in chain.from_iterable(obj.as_raw_chunks()):
-        c = c.to_bytes(1, "big")
-        block_write(c)
+        cb = c.to_bytes(1, "big")
+        block_write(cb)
         n += 1
-        if c == b"\n" or n == _BLOCK_SIZE:
+        if cb == b"\n" or n == _BLOCK_SIZE:
             value = block_getvalue()
             block_counts[hash(value)] += len(value)
             block_seek(0)

+ 1 - 1
dulwich/objects.py

@@ -845,7 +845,7 @@ class Tag(ShaFile):
                 assert isinstance(value, bytes)
                 obj_class = object_class(value)
                 if not obj_class:
-                    raise ObjectFormatException(f"Not a known type: {value}")
+                    raise ObjectFormatException(f"Not a known type: {value!r}")
                 self._object_class = obj_class
             elif field == _TAG_HEADER:
                 self._name = value

+ 4 - 4
dulwich/server.py

@@ -48,7 +48,7 @@ import socket
 import sys
 import time
 from functools import partial
-from typing import Dict, Iterable, List, Optional, Set, Tuple
+from typing import Dict, Iterable, List, Optional, Set, Tuple, cast
 
 try:
     from typing import Protocol as TypingProtocol
@@ -220,7 +220,7 @@ class Handler:
         self.proto = proto
         self.stateless_rpc = stateless_rpc
 
-    def handle(self):
+    def handle(self) -> None:
         raise NotImplementedError(self.handle)
 
 
@@ -1111,7 +1111,7 @@ class UploadArchiveHandler(Handler):
         super().__init__(backend, proto, stateless_rpc)
         self.repo = backend.open_repository(args[0])
 
-    def handle(self):
+    def handle(self) -> None:
         def write(x):
             return self.proto.write_sideband(SIDE_BAND_CHANNEL_DATA, x)
 
@@ -1135,7 +1135,7 @@ class UploadArchiveHandler(Handler):
                 format = arguments[i].decode("ascii")
             else:
                 commit_sha = self.repo.refs[argument]
-                tree = store[store[commit_sha].tree]
+                tree = store[cast(Commit, store[commit_sha]).tree]
             i += 1
         self.proto.write_pkt_line(b"ACK")
         self.proto.write_pkt_line(None)

+ 2 - 1
fuzzing/fuzz-targets/fuzz_configfile.py

@@ -1,7 +1,8 @@
-import atheris
 import sys
 from io import BytesIO
 
+import atheris
+
 with atheris.instrument_imports():
     from dulwich.config import ConfigFile