Procházet zdrojové kódy

Fix more typing issues

Jelmer Vernooij před 4 měsíci
rodič
revize
2bb67c8b09

+ 4 - 4
dulwich/cli.py

@@ -33,7 +33,7 @@ import os
 import signal
 import sys
 from getopt import getopt
-from typing import ClassVar, Optional, TYPE_CHECKING
+from typing import TYPE_CHECKING, ClassVar, Optional
 
 from dulwich import porcelain
 
@@ -129,7 +129,7 @@ class cmd_fetch_pack(Command):
 class cmd_fetch(Command):
     def run(self, args) -> None:
         opts, args = getopt(args, "", [])
-        kwopts = dict(opts)
+        dict(opts)
         client, path = get_transport_and_path(args.pop(0))
         r = Repo(".")
         def progress(msg: bytes) -> None:
@@ -152,7 +152,7 @@ class cmd_for_each_ref(Command):
 class cmd_fsck(Command):
     def run(self, args) -> None:
         opts, args = getopt(args, "", [])
-        kwopts = dict(opts)
+        dict(opts)
         for obj, msg in porcelain.fsck("."):
             print(f"{obj}: {msg}")
 
@@ -404,7 +404,7 @@ class cmd_tag(Command):
 class cmd_repack(Command):
     def run(self, args) -> None:
         opts, args = getopt(args, "", [])
-        kwopts = dict(opts)
+        dict(opts)
         porcelain.repack(".")
 
 

+ 2 - 1
dulwich/graph.py

@@ -19,8 +19,9 @@
 
 """Implementation of merge-base following the approach of git."""
 
+from collections.abc import Iterator
 from heapq import heappop, heappush
-from typing import Generic, Optional, Iterator, TypeVar
+from typing import Generic, Optional, TypeVar
 
 from .lru_cache import LRUCache
 

+ 1 - 2
dulwich/hooks.py

@@ -22,7 +22,6 @@
 
 import os
 import subprocess
-from typing import Any
 
 from .errors import HookError
 
@@ -30,7 +29,7 @@ from .errors import HookError
 class Hook:
     """Generic hook object."""
 
-    def execute(self, *args) -> Any:
+    def execute(self, *args):
         """Execute the hook with the given args.
 
         Args:

+ 1 - 0
dulwich/objects.py

@@ -1529,6 +1529,7 @@ class Commit(ShaFile):
 
         with gpg.Context() as ctx:
             self_without_gpgsig = self.copy()
+            assert isinstance(self_without_gpgsig, Commit)
             self_without_gpgsig._gpgsig = None
             self_without_gpgsig.gpgsig = None
             data, result = ctx.verify(

+ 2 - 1
dulwich/refs.py

@@ -23,8 +23,9 @@
 
 import os
 import warnings
+from collections.abc import Iterator
 from contextlib import suppress
-from typing import Any, Optional, Iterator
+from typing import Any, Optional
 
 from .errors import PackedRefsException, RefFormatError
 from .file import GitFile, ensure_dir_exists

+ 6 - 5
dulwich/server.py

@@ -49,9 +49,10 @@ import socketserver
 import sys
 import time
 import zlib
-from collections.abc import Iterable
+from collections.abc import Iterable, Iterator
 from functools import partial
-from typing import Optional, cast, Iterator, Protocol as TypingProtocol, Type
+from typing import Optional, cast
+from typing import Protocol as TypingProtocol
 
 from dulwich import log_utils
 
@@ -112,7 +113,7 @@ from .protocol import (
     symref_capabilities,
 )
 from .refs import PEELED_TAG_SUFFIX, RefsContainer, write_info_refs
-from .repo import BaseRepo, Repo
+from .repo import Repo
 
 logger = log_utils.getLogger(__name__)
 
@@ -120,7 +121,7 @@ logger = log_utils.getLogger(__name__)
 class Backend:
     """A backend for the Git smart server implementation."""
 
-    def open_repository(self, path) -> BackendRepo:
+    def open_repository(self, path) -> "BackendRepo":
         """Open the repository at a path.
 
         Args:
@@ -763,7 +764,7 @@ class _ProtocolGraphWalker:
         return _all_wants_satisfied(self.store, haves, self._wants)
 
     def set_ack_type(self, ack_type) -> None:
-        impl_classes: dict[int, Type[AckGraphWalkerImpl]] = {
+        impl_classes: dict[int, type[AckGraphWalkerImpl]] = {
             MULTI_ACK: MultiAckGraphWalkerImpl,
             MULTI_ACK_DETAILED: MultiAckDetailedGraphWalkerImpl,
             SINGLE_ACK: SingleAckGraphWalkerImpl,

+ 3 - 4
dulwich/tests/test_object_store.py

@@ -20,25 +20,24 @@
 
 """Tests for the object store interface."""
 
+from typing import TYPE_CHECKING
 from unittest import skipUnless
 
 from dulwich.index import commit_tree
 from dulwich.object_store import (
+    PackBasedObjectStore,
     iter_tree_contents,
     peel_sha,
-    PackBasedObjectStore,
 )
 from dulwich.objects import (
     Blob,
-    TreeEntry,
     Tree,
+    TreeEntry,
 )
 from dulwich.protocol import DEPTH_INFINITE
 
 from .utils import make_object, make_tag
 
-from typing import TYPE_CHECKING
-
 if TYPE_CHECKING:
     from dulwich.object_store import BaseObjectStore