Skip to content

Commit 7c6c8dc

Browse files
committed
Add remaining types to IndexFile ._store_items() ._entries_for_paths()
1 parent 11d91e2 commit 7c6c8dc

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

‎git/index/base.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
# typing -----------------------------------------------------------------------------
6868

69-
from typing import (Any, Callable, Dict, IO, Iterable, Iterator, List,
69+
from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List,
7070
Sequence, TYPE_CHECKING, Tuple, Union)
7171

7272
from git.types import PathLike, TBD
@@ -567,7 +567,8 @@ def write_tree(self) -> Tree:
567567
root_tree._cache = tree_items
568568
return root_tree
569569

570-
def _process_diff_args(self, args: Any) -> List[Any]:
570+
def _process_diff_args(self, args: List[Union[str, diff.Diffable, object]]
571+
) -> List[Union[str, diff.Diffable, object]]:
571572
try:
572573
args.pop(args.index(self))
573574
except IndexError:
@@ -607,13 +608,14 @@ def _preprocess_add_items(self, items: Sequence[Union[PathLike, Blob, BaseIndexE
607608
# END for each item
608609
return paths, entries
609610

610-
def _store_path(self, filepath, fprogress):
611+
def _store_path(self, filepath: PathLike, fprogress: Callable) -> BaseIndexEntry:
611612
"""Store file at filepath in the database and return the base index entry
612613
Needs the git_working_dir decorator active ! This must be assured in the calling code"""
613614
st = os.lstat(filepath) # handles non-symlinks as well
614615
if S_ISLNK(st.st_mode):
615616
# in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8
616-
open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath), encoding=defenc))
617+
open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath),
618+
encoding=defenc)) # type: Callable[[], BinaryIO]
617619
else:
618620
open_stream = lambda: open(filepath, 'rb')
619621
with open_stream() as stream:
@@ -625,16 +627,18 @@ def _store_path(self, filepath, fprogress):
625627

626628
@unbare_repo
627629
@git_working_dir
628-
def _entries_for_paths(self, paths, path_rewriter, fprogress, entries):
629-
entries_added = []
630+
def _entries_for_paths(self, paths: List[str], path_rewriter: Callable, fprogress: Callable,
631+
entries: List[BaseIndexEntry]) -> List[BaseIndexEntry]:
632+
entries_added = [] # type: List[BaseIndexEntry]
630633
if path_rewriter:
631634
for path in paths:
632635
if osp.isabs(path):
633636
abspath = path
634-
gitrelative_path = path[len(self.repo.working_tree_dir) + 1:]
637+
gitrelative_path = path[len(str(self.repo.working_tree_dir)) + 1:]
635638
else:
636639
gitrelative_path = path
637-
abspath = osp.join(self.repo.working_tree_dir, gitrelative_path)
640+
if self.repo.working_tree_dir:
641+
abspath = osp.join(self.repo.working_tree_dir, gitrelative_path)
638642
# end obtain relative and absolute paths
639643

640644
blob = Blob(self.repo, Blob.NULL_BIN_SHA,

0 commit comments

Comments
 (0)