diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-06-26 10:09:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-26 10:09:53 +0800 |
commit | 2d2ff037f9f7a9ae33e5f4f6bdb75b669a1af19a (patch) | |
tree | 5f4fd00ad13fa5455dc876ab9cb9cc4f9b66bdfc /git/index/fun.py | |
parent | 703280b8c3df6f9b1a5cbe0997b717edbcaa8979 (diff) | |
parent | 5d7b8ba9f2e9298496232e4ae66bd904a1d71001 (diff) | |
download | gitpython-2d2ff037f9f7a9ae33e5f4f6bdb75b669a1af19a.tar.gz |
Merge pull request #1279 from Yobmod/main
Finish typing object, improve verious other types.
Diffstat (limited to 'git/index/fun.py')
-rw-r--r-- | git/index/fun.py | 14 |
1 files changed, 10 insertions, 4 deletions
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)) |