summaryrefslogtreecommitdiff
path: root/git/index/fun.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-06-25 21:03:17 +0100
committerYobmod <yobmod@gmail.com>2021-06-25 21:03:17 +0100
commitaba4d9b4029373d2bccc961a23134454072936ce (patch)
treedb426094fdb61ed4a7c93b586b166553944ae5ce /git/index/fun.py
parent7b09003fffa8196277bcfaa9984a3e6833805a6d (diff)
downloadgitpython-aba4d9b4029373d2bccc961a23134454072936ce.tar.gz
replace cast()s with asserts in fun.py
Diffstat (limited to 'git/index/fun.py')
-rw-r--r--git/index/fun.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/git/index/fun.py b/git/index/fun.py
index 10a44050..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