Browse Source

Add missing docstrings to fix ruff linting issues

Jelmer Vernooij 5 tháng trước cách đây
mục cha
commit
10ca3e763d
9 tập tin đã thay đổi với 62 bổ sung6 xóa
  1. 7 2
      dulwich/bundle.py
  2. 8 0
      dulwich/client.py
  3. 8 0
      dulwich/cloud/gcs.py
  4. 9 2
      dulwich/object_store.py
  5. 13 0
      dulwich/pack.py
  6. 2 0
      dulwich/refs.py
  7. 11 0
      dulwich/repo.py
  8. 1 0
      dulwich/server.py
  9. 3 2
      dulwich/web.py

+ 7 - 2
dulwich/bundle.py

@@ -38,8 +38,13 @@ from .pack import PackData, UnpackedObject, write_pack_data
 class PackDataLike(Protocol):
     """Protocol for objects that behave like PackData."""
 
-    def __len__(self) -> int: ...
-    def iter_unpacked(self) -> Iterator[UnpackedObject]: ...
+    def __len__(self) -> int:
+        """Return the number of objects in the pack."""
+        ...
+
+    def iter_unpacked(self) -> Iterator[UnpackedObject]:
+        """Iterate over unpacked objects in the pack."""
+        ...
 
 
 if TYPE_CHECKING:

+ 8 - 0
dulwich/client.py

@@ -283,6 +283,7 @@ class ReportStatusParser:
 
 
 def negotiate_protocol_version(proto: Protocol) -> int:
+    """Negotiate protocol version with the server."""
     pkt = proto.read_pkt_line()
     if pkt is not None and pkt.strip() == b"version 2":
         return 2
@@ -291,6 +292,7 @@ def negotiate_protocol_version(proto: Protocol) -> int:
 
 
 def read_server_capabilities(pkt_seq: Iterable[bytes]) -> set[bytes]:
+    """Read server capabilities from packet sequence."""
     server_capabilities = []
     for pkt in pkt_seq:
         server_capabilities.append(pkt)
@@ -300,6 +302,7 @@ def read_server_capabilities(pkt_seq: Iterable[bytes]) -> set[bytes]:
 def read_pkt_refs_v2(
     pkt_seq: Iterable[bytes],
 ) -> tuple[dict[bytes, Optional[bytes]], dict[bytes, bytes], dict[bytes, bytes]]:
+    """Read references using protocol version 2."""
     refs: dict[bytes, Optional[bytes]] = {}
     symrefs = {}
     peeled = {}
@@ -325,6 +328,7 @@ def read_pkt_refs_v2(
 def read_pkt_refs_v1(
     pkt_seq: Iterable[bytes],
 ) -> tuple[dict[bytes, Optional[bytes]], set[bytes]]:
+    """Read references using protocol version 1."""
     server_capabilities = None
     refs: dict[bytes, Optional[bytes]] = {}
     # Receive refs from server
@@ -437,6 +441,7 @@ class FetchPackResult(_DeprecatedDictProxy):
         self.new_unshallow = new_unshallow
 
     def __eq__(self, other: object) -> bool:
+        """Check equality with another object."""
         if isinstance(other, dict):
             self._warn_deprecated()
             return self.refs == other
@@ -486,6 +491,7 @@ class LsRemoteResult(_DeprecatedDictProxy):
         )
 
     def __eq__(self, other: object) -> bool:
+        """Check equality with another object."""
         if isinstance(other, dict):
             self._warn_deprecated()
             return self.refs == other
@@ -526,6 +532,7 @@ class SendPackResult(_DeprecatedDictProxy):
         self.ref_status = ref_status
 
     def __eq__(self, other: object) -> bool:
+        """Check equality with another object."""
         if isinstance(other, dict):
             self._warn_deprecated()
             return self.refs == other
@@ -634,6 +641,7 @@ def _read_side_band64k_data(pkt_seq: Iterable[bytes]) -> Iterator[tuple[int, byt
 def find_capability(
     capabilities: list, key: bytes, value: Optional[bytes]
 ) -> Optional[bytes]:
+    """Find a capability with a specific key and value."""
     for capability in capabilities:
         k, v = parse_capability(capability)
         if k != key:

+ 8 - 0
dulwich/cloud/gcs.py

@@ -43,7 +43,15 @@ if TYPE_CHECKING:
 
 
 class GcsObjectStore(BucketBasedObjectStore):
+    """Object store implementation using Google Cloud Storage."""
+
     def __init__(self, bucket: "Bucket", subpath: str = "") -> None:
+        """Initialize GCS object store.
+
+        Args:
+            bucket: GCS bucket instance
+            subpath: Optional subpath within the bucket
+        """
         super().__init__()
         self.bucket = bucket
         self.subpath = subpath

+ 9 - 2
dulwich/object_store.py

@@ -90,8 +90,13 @@ if TYPE_CHECKING:
 class GraphWalker(Protocol):
     """Protocol for graph walker objects."""
 
-    def __next__(self) -> Optional[bytes]: ...
-    def ack(self, sha: bytes) -> None: ...
+    def __next__(self) -> Optional[bytes]:
+        """Return the next object SHA to visit."""
+        ...
+
+    def ack(self, sha: bytes) -> None:
+        """Acknowledge that an object has been received."""
+        ...
 
 
 INFODIR = "info"
@@ -222,6 +227,7 @@ class BaseObjectStore:
     def determine_wants_all(
         self, refs: dict[Ref, ObjectID], depth: Optional[int] = None
     ) -> list[ObjectID]:
+        """Determine which objects are wanted based on refs."""
         def _want_deepen(sha: bytes) -> bool:
             if not depth:
                 return False
@@ -638,6 +644,7 @@ class PackBasedObjectStore(BaseObjectStore, PackedObjectContainer):
 
     @property
     def alternates(self) -> list:
+        """Return list of alternate object stores."""
         return []
 
     def contains_packed(self, sha: bytes) -> bool:

+ 13 - 0
dulwich/pack.py

@@ -1237,6 +1237,13 @@ class PackStreamReader:
         read_some: Optional[Callable[[int], bytes]] = None,
         zlib_bufsize: int = _ZLIB_BUFSIZE,
     ) -> None:
+        """Initialize pack stream reader.
+
+        Args:
+            read_all: Function to read all requested bytes
+            read_some: Function to read some bytes (optional)
+            zlib_bufsize: Buffer size for zlib decompression
+        """
         self.read_all = read_all
         if read_some is None:
             self.read_some = read_all
@@ -1292,6 +1299,7 @@ class PackStreamReader:
 
     @property
     def offset(self) -> int:
+        """Return current offset in the stream."""
         return self._offset - self._buf_len()
 
     def read(self, size: int) -> bytes:
@@ -1595,6 +1603,7 @@ class PackData:
         self.close()
 
     def __eq__(self, other: object) -> bool:
+        """Check equality with another object."""
         if isinstance(other, PackData):
             return self.get_stored_checksum() == other.get_stored_checksum()
         return False
@@ -1620,6 +1629,7 @@ class PackData:
         return compute_file_sha(cast(IO[bytes], self._file), end_ofs=-20).digest()
 
     def iter_unpacked(self, *, include_comp: bool = False) -> Iterator[UnpackedObject]:
+        """Iterate over unpacked objects in the pack."""
         self._file.seek(self._header_size)
 
         if self._num_objects is None:
@@ -2202,9 +2212,11 @@ class SHA1Reader(BinaryIO):
         raise UnsupportedOperation("write")
 
     def writelines(self, lines: Iterable[bytes], /) -> None:  # type: ignore[override]
+        """Write multiple lines to the file (not supported)."""
         raise UnsupportedOperation("writelines")
 
     def write(self, data: bytes, /) -> int:  # type: ignore[override]
+        """Write data to the file (not supported)."""
         raise UnsupportedOperation("write")
 
     def __enter__(self) -> "SHA1Reader":
@@ -2301,6 +2313,7 @@ class SHA1Writer(BinaryIO):
         sha = self.write_sha()
 
     def close(self) -> None:
+        """Close the pack file and finalize the SHA."""
         self.digest = self.write_sha()
         self.f.close()
 

+ 2 - 0
dulwich/refs.py

@@ -66,6 +66,7 @@ class SymrefLoop(Exception):
     """There is a loop between one or more symrefs."""
 
     def __init__(self, ref: bytes, depth: int) -> None:
+        """Initialize SymrefLoop exception."""
         self.ref = ref
         self.depth = depth
 
@@ -1420,6 +1421,7 @@ def write_info_refs(
 
 
 def is_local_branch(x: bytes) -> bool:
+    """Check if a ref name is a local branch."""
     return x.startswith(LOCAL_BRANCH_PREFIX)
 
 

+ 11 - 0
dulwich/repo.py

@@ -146,6 +146,7 @@ class InvalidUserIdentity(Exception):
     """User identity is not of the format 'user <email>'."""
 
     def __init__(self, identity: str) -> None:
+        """Initialize InvalidUserIdentity exception."""
         self.identity = identity
 
 
@@ -339,12 +340,21 @@ def _set_filesystem_hidden(path: str) -> None:
 
 
 class ParentsProvider:
+    """Provider for commit parent information."""
+
     def __init__(
         self,
         store: "BaseObjectStore",
         grafts: dict = {},
         shallows: Iterable[bytes] = [],
     ) -> None:
+        """Initialize ParentsProvider.
+
+        Args:
+            store: Object store to use
+            grafts: Graft information
+            shallows: Shallow commit SHAs
+        """
         self.store = store
         self.grafts = grafts
         self.shallows = set(shallows)
@@ -355,6 +365,7 @@ class ParentsProvider:
     def get_parents(
         self, commit_id: bytes, commit: Optional[Commit] = None
     ) -> list[bytes]:
+        """Get parents for a commit using the parents provider."""
         try:
             return self.grafts[commit_id]
         except KeyError:

+ 1 - 0
dulwich/server.py

@@ -636,6 +636,7 @@ class AckGraphWalkerImpl:
         raise NotImplementedError
 
     def handle_done(self, done_required, done_received):
+        """Handle 'done' packet from client."""
         raise NotImplementedError
 
 

+ 3 - 2
dulwich/web.py

@@ -684,8 +684,9 @@ def make_wsgi_chain(
     handlers: Optional[dict[bytes, Callable[..., Any]]] = None,
     fallback_app: Optional[WSGIApplication] = None,
 ) -> WSGIApplication:
-    """Factory function to create an instance of HTTPGitApplication,
-    correctly wrapped with needed middleware.
+    """Factory function to create an instance of HTTPGitApplication.
+    
+    Correctly wrapped with needed middleware.
     """
     app = HTTPGitApplication(
         backend, dumb=dumb, handlers=handlers, fallback_app=fallback_app