Quellcode durchsuchen

Merge pull request #1091 from jelmer/typing

Fix some typing issues reported by latest mypy
Jelmer Vernooij vor 2 Jahren
Ursprung
Commit
592548522b
3 geänderte Dateien mit 12 neuen und 6 gelöschten Zeilen
  1. 1 1
      dulwich/client.py
  2. 5 2
      dulwich/objects.py
  3. 6 3
      dulwich/repo.py

+ 1 - 1
dulwich/client.py

@@ -910,7 +910,7 @@ class GitClient(object):
         self,
         proto: Protocol,
         capabilities: Set[bytes],
-        progress: Callable[[bytes], None] = None,
+        progress: Optional[Callable[[bytes], None]] = None,
     ) -> Optional[Dict[bytes, Optional[str]]]:
         """Handle the tail of a 'git-receive-pack' request.
 

+ 5 - 2
dulwich/objects.py

@@ -977,7 +977,7 @@ def serialize_tree(items):
         )
 
 
-def sorted_tree_items(entries, name_order):
+def sorted_tree_items(entries, name_order: bool):
     """Iterate over a tree entries dictionary.
 
     Args:
@@ -987,7 +987,10 @@ def sorted_tree_items(entries, name_order):
       entries: Dictionary mapping names to (mode, sha) tuples
     Returns: Iterator over (name, mode, hexsha)
     """
-    key_func = name_order and key_entry_name_order or key_entry
+    if name_order:
+        key_func = key_entry_name_order
+    else:
+        key_func = key_entry
     for name, entry in sorted(entries.items(), key=key_func):
         mode, hexsha = entry
         # Stricter type checks than normal to mirror checks in the C version.

+ 6 - 3
dulwich/repo.py

@@ -595,7 +595,8 @@ class BaseRepo(object):
         )
 
     def get_graph_walker(
-            self, heads: List[ObjectID] = None) -> ObjectStoreGraphWalker:
+            self,
+            heads: Optional[List[ObjectID]] = None) -> ObjectStoreGraphWalker:
         """Retrieve a graph walker.
 
         A graph walker is used by a remote repository (or proxy)
@@ -663,7 +664,8 @@ class BaseRepo(object):
             shallows=self.get_shallow(),
         )
 
-    def get_parents(self, sha: bytes, commit: Commit = None) -> List[bytes]:
+    def get_parents(self, sha: bytes,
+                    commit: Optional[Commit] = None) -> List[bytes]:
         """Retrieve the parents of a specific commit.
 
         If the specific commit is a graftpoint, the graft parents
@@ -855,7 +857,8 @@ class BaseRepo(object):
         else:
             raise ValueError(name)
 
-    def _get_user_identity(self, config: "StackedConfig", kind: str = None) -> bytes:
+    def _get_user_identity(self, config: "StackedConfig",
+                           kind: Optional[str] = None) -> bytes:
         """Determine the identity to use for new commits."""
         # TODO(jelmer): Deprecate this function in favor of get_user_identity
         return get_user_identity(config)