From 5b6fe83f4d817a3b73b44df16cfb4f96bd4d9904 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Wed, 23 Jun 2021 02:22:34 +0100 Subject: Update typing-extensions version in requirements.txt --- git/index/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/index/fun.py') diff --git a/git/index/fun.py b/git/index/fun.py index 1012f480..3fded347 100644 --- a/git/index/fun.py +++ b/git/index/fun.py @@ -109,7 +109,7 @@ def run_commit_hook(name: str, index: 'IndexFile', *args: str) -> None: # end handle return code -def stat_mode_to_index_mode(mode): +def stat_mode_to_index_mode(mode: int) -> int: """Convert the given mode from a stat call to the corresponding index mode and return it""" if S_ISLNK(mode): # symlinks -- cgit v1.2.1 From 42e4f5e26b812385df65f8f32081035e2fb2a121 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Thu, 24 Jun 2021 05:52:48 +0100 Subject: Add types to tree.Tree --- git/index/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/index/fun.py') diff --git a/git/index/fun.py b/git/index/fun.py index 3fded347..10a44050 100644 --- a/git/index/fun.py +++ b/git/index/fun.py @@ -293,7 +293,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)) -- cgit v1.2.1 From aba4d9b4029373d2bccc961a23134454072936ce Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 25 Jun 2021 21:03:17 +0100 Subject: replace cast()s with asserts in fun.py --- git/index/fun.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'git/index/fun.py') 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 -- cgit v1.2.1