Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed May 4, 2024
1 parent 5384423 commit de0a006
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
14 changes: 8 additions & 6 deletions dulwich/diff_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -302,7 +304,7 @@ def change_type(c):
_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.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dulwich/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def _deserialize(self, chunks):
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
Expand Down
8 changes: 4 additions & 4 deletions dulwich/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
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
Expand Down Expand Up @@ -220,7 +220,7 @@ def __init__(self, backend, proto, stateless_rpc=False) -> None:
self.proto = proto
self.stateless_rpc = stateless_rpc

def handle(self):
def handle(self) -> None:
raise NotImplementedError(self.handle)


Expand Down Expand Up @@ -1111,7 +1111,7 @@ def __init__(self, backend, args, proto, stateless_rpc=False) -> None:
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)

Expand All @@ -1135,7 +1135,7 @@ def write(x):
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)
Expand Down
3 changes: 2 additions & 1 deletion fuzzing/fuzz-targets/fuzz_configfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import atheris
import sys
from io import BytesIO

import atheris

with atheris.instrument_imports():
from dulwich.config import ConfigFile

Expand Down

0 comments on commit de0a006

Please sign in to comment.