Explorar o código

Remove Optional from TreeEntry fields

TreeEntry is never instantiated with None values for path, mode, or sha.
The fields should not be Optional. This removes two type: ignore comments
in splitlines() and _serialize() methods.
Jelmer Vernooij hai 3 meses
pai
achega
be2eb7fd28
Modificáronse 2 ficheiros con 7 adicións e 6 borrados
  1. 6 5
      dulwich/objects.py
  2. 1 1
      dulwich/repo.py

+ 6 - 5
dulwich/objects.py

@@ -788,7 +788,8 @@ class Blob(ShaFile):
         if not chunks:
             return []
         if len(chunks) == 1:
-            return chunks[0].splitlines(True)  # type: ignore[no-any-return]
+            result: list[bytes] = chunks[0].splitlines(True)
+            return result
         remaining = None
         ret = []
         for chunk in chunks:
@@ -1181,9 +1182,9 @@ class Tag(ShaFile):
 class TreeEntry(NamedTuple):
     """Named tuple encapsulating a single tree entry."""
 
-    path: Optional[bytes]
-    mode: Optional[int]
-    sha: Optional[bytes]
+    path: bytes
+    mode: int
+    sha: bytes
 
     def in_path(self, path: bytes) -> "TreeEntry":
         """Return a copy of this entry with the given path prepended."""
@@ -1459,7 +1460,7 @@ class Tree(ShaFile):
             last = entry
 
     def _serialize(self) -> list[bytes]:
-        return list(serialize_tree(self.iteritems()))  # type: ignore[arg-type]
+        return list(serialize_tree(self.iteritems()))
 
     def as_pretty_string(self) -> str:
         """Return a human-readable string representation of this tree.

+ 1 - 1
dulwich/repo.py

@@ -100,7 +100,7 @@ from .objects import (
     check_hexsha,
     valid_hexsha,
 )
-from .pack import PackHint, generate_unpacked_objects
+from .pack import generate_unpacked_objects
 from .refs import (
     ANNOTATED_TAG_SUFFIX,  # noqa: F401
     LOCAL_BRANCH_PREFIX,