summaryrefslogtreecommitdiff
path: root/git/index
diff options
context:
space:
mode:
Diffstat (limited to 'git/index')
-rw-r--r--git/index/base.py2
-rw-r--r--git/index/fun.py14
2 files changed, 11 insertions, 5 deletions
diff --git a/git/index/base.py b/git/index/base.py
index 04424060..e2b3f8fa 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -568,7 +568,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# note: additional deserialization could be saved if write_tree_from_cache
# would return sorted tree entries
root_tree = Tree(self.repo, binsha, path='')
- root_tree._cache = tree_items
+ root_tree._cache = tree_items # type: ignore
return root_tree
def _process_diff_args(self, args: List[Union[str, diff.Diffable, object]]
diff --git a/git/index/fun.py b/git/index/fun.py
index 3fded347..ffd109b1 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -53,7 +53,7 @@ from .util import (
from typing import (Dict, IO, List, Sequence, TYPE_CHECKING, Tuple, Type, Union, cast)
-from git.types import PathLike
+from git.types import PathLike, TypeGuard
if TYPE_CHECKING:
from .base import IndexFile
@@ -185,11 +185,17 @@ def read_header(stream: IO[bytes]) -> Tuple[int, int]:
def entry_key(*entry: Union[BaseIndexEntry, PathLike, int]) -> Tuple[PathLike, int]:
""":return: Key suitable to be used for the index.entries dictionary
:param entry: One instance of type BaseIndexEntry or the path and the stage"""
+
+ def is_entry_tuple(entry: Tuple) -> TypeGuard[Tuple[PathLike, int]]:
+ return isinstance(entry, tuple) and len(entry) == 2
+
if len(entry) == 1:
- entry_first = cast(BaseIndexEntry, entry[0]) # type: BaseIndexEntry
+ entry_first = entry[0]
+ assert isinstance(entry_first, BaseIndexEntry)
return (entry_first.path, entry_first.stage)
else:
- entry = cast(Tuple[PathLike, int], tuple(entry))
+ # entry = tuple(entry)
+ assert is_entry_tuple(entry)
return entry
# END handle entry
@@ -293,7 +299,7 @@ def write_tree_from_cache(entries: List[IndexEntry], odb, sl: slice, si: int = 0
# finally create the tree
sio = BytesIO()
tree_to_stream(tree_items, sio.write) # converts bytes of each item[0] to str
- tree_items_stringified = cast(List[Tuple[str, int, str]], tree_items) # type: List[Tuple[str, int, str]]
+ tree_items_stringified = cast(List[Tuple[str, int, str]], tree_items)
sio.seek(0)
istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio))