From 647101833ae276f3b923583e202faa3f7d78e218 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 14:25:23 +0100 Subject: Improve types of @unbare_repo and @git_working_dir decorators --- git/index/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index f4ffba7b..8346d24a 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -410,7 +410,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # whose name contains wildcard characters. if abs_path not in resolved_paths: for f in self._iter_expand_paths(glob.glob(abs_path)): - yield f.replace(rs, '') + yield str(f).replace(rs, '') continue # END glob handling try: @@ -635,7 +635,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): @git_working_dir def _entries_for_paths(self, paths: List[str], path_rewriter: Callable, fprogress: Callable, entries: List[BaseIndexEntry]) -> List[BaseIndexEntry]: - entries_added = [] # type: List[BaseIndexEntry] + entries_added: List[BaseIndexEntry] = [] if path_rewriter: for path in paths: if osp.isabs(path): @@ -769,7 +769,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # automatically # paths can be git-added, for everything else we use git-update-index paths, entries = self._preprocess_add_items(items) - entries_added = [] + entries_added: List[BaseIndexEntry] = [] # This code needs a working tree, therefore we try not to run it unless required. # That way, we are OK on a bare repository as well. # If there are no paths, the rewriter has nothing to do either -- cgit v1.2.1 From 06eca0b84a4538c642c5e1afa2f3441a96bef444 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:47:39 +0100 Subject: Make subodule a forward ref in Index.base --- git/index/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index 8346d24a..b37883a6 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -22,7 +22,6 @@ from git.exc import ( ) from git.objects import ( Blob, - Submodule, Tree, Object, Commit, @@ -76,6 +75,7 @@ if TYPE_CHECKING: from git.repo import Repo from git.refs.reference import Reference from git.util import Actor + from git.objects.submodule.base import Submodule StageType = int @@ -842,7 +842,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): items = [items] for item in items: - if isinstance(item, (BaseIndexEntry, (Blob, Submodule))): + if isinstance(item, (BaseIndexEntry, (Blob, 'Submodule'))): paths.append(self._to_relative_path(item.path)) elif isinstance(item, str): paths.append(self._to_relative_path(item)) @@ -853,7 +853,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): @post_clear_cache @default_index - def remove(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], working_tree: bool = False, + def remove(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], working_tree: bool = False, **kwargs: Any) -> List[str]: """Remove the given items from the index and optionally from the working tree as well. @@ -905,7 +905,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): @post_clear_cache @default_index - def move(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], skip_errors: bool = False, + def move(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], skip_errors: bool = False, **kwargs: Any) -> List[Tuple[str, str]]: """Rename/move the items, whereas the last item is considered the destination of the move operation. If the destination is a file, the first item ( of two ) -- cgit v1.2.1 From 33ffd0b2ed117d043fe828e5f2eabe5c8f8b0b66 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:51:34 +0100 Subject: Make subodule a forward ref in Index.base2 --- git/index/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index b37883a6..5a564b8c 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -75,7 +75,7 @@ if TYPE_CHECKING: from git.repo import Repo from git.refs.reference import Reference from git.util import Actor - from git.objects.submodule.base import Submodule + from git.objects import Submodule StageType = int -- cgit v1.2.1 From f372187ade056a3069e68ba0a90bf53bd7d7e464 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 17:00:44 +0100 Subject: Make subodule a forward ref in Index.base3 --- git/index/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index 5a564b8c..edb79edf 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -593,7 +593,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir)) return os.path.relpath(path, self.repo.working_tree_dir) - def _preprocess_add_items(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]] + def _preprocess_add_items(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']] ) -> Tuple[List[PathLike], List[BaseIndexEntry]]: """ Split the items into two lists of path strings and BaseEntries. """ paths = [] @@ -664,7 +664,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # END path handling return entries_added - def add(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], force: bool = True, + def add(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], force: bool = True, fprogress: Callable = lambda *args: None, path_rewriter: Callable = None, write: bool = True, write_extension_data: bool = False) -> List[BaseIndexEntry]: """Add files from the working tree, specific blobs or BaseIndexEntries -- cgit v1.2.1 From de36cb6f0391fcf4d756909e0cec429599585700 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 17:04:48 +0100 Subject: UnMake subodule a forward ref in Index.base --- git/index/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index edb79edf..b54a19a7 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -22,6 +22,7 @@ from git.exc import ( ) from git.objects import ( Blob, + Submodule, Tree, Object, Commit, @@ -75,7 +76,6 @@ if TYPE_CHECKING: from git.repo import Repo from git.refs.reference import Reference from git.util import Actor - from git.objects import Submodule StageType = int -- cgit v1.2.1 From 3cc0edce2a0deb159cfb3dca10b6044086900ce9 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 17:07:40 +0100 Subject: UnMake subodule a forward ref in Index.base2 --- git/index/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index b54a19a7..50bcf504 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -842,7 +842,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): items = [items] for item in items: - if isinstance(item, (BaseIndexEntry, (Blob, 'Submodule'))): + if isinstance(item, (BaseIndexEntry, (Blob, Submodule))): paths.append(self._to_relative_path(item.path)) elif isinstance(item, str): paths.append(self._to_relative_path(item)) -- cgit v1.2.1 From 28bde3978b4ca18dc97488b88b4424a2d521ac68 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 17:14:43 +0100 Subject: Type index _items_to_rela_paths() --- git/index/base.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index 50bcf504..c6d92526 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -833,12 +833,13 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return entries_added - def _items_to_rela_paths(self, items): + def _items_to_rela_paths(self, items: Union[PathLike, Sequence[Union[PathLike, BaseIndexEntry, Blob, Submodule]]] + ) -> List[PathLike]: """Returns a list of repo-relative paths from the given items which may be absolute or relative paths, entries or blobs""" paths = [] # if string put in list - if isinstance(items, str): + if isinstance(items, (str, os.PathLike)): items = [items] for item in items: @@ -851,8 +852,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # END for each item return paths - @post_clear_cache - @default_index + @ post_clear_cache + @ default_index def remove(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], working_tree: bool = False, **kwargs: Any) -> List[str]: """Remove the given items from the index and optionally from @@ -903,8 +904,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # rm 'path' return [p[4:-1] for p in removed_paths] - @post_clear_cache - @default_index + @ post_clear_cache + @ default_index def move(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], skip_errors: bool = False, **kwargs: Any) -> List[Tuple[str, str]]: """Rename/move the items, whereas the last item is considered the destination of @@ -1023,7 +1024,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): proc.wait() return stdout - @default_index + @ default_index def checkout(self, paths: Union[None, Iterable[PathLike]] = None, force: bool = False, fprogress: Callable = lambda *args: None, **kwargs: Any ) -> Union[None, Iterator[PathLike], Sequence[PathLike]]: @@ -1192,7 +1193,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # END paths handling assert "Should not reach this point" - @default_index + @ default_index def reset(self, commit: Union[Commit, 'Reference', str] = 'HEAD', working_tree: bool = False, paths: Union[None, Iterable[PathLike]] = None, head: bool = False, **kwargs: Any) -> 'IndexFile': @@ -1262,7 +1263,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return self - @default_index + @ default_index def diff(self, other: Union[diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = diff.Diffable.Index, paths: Union[str, List[PathLike], Tuple[PathLike, ...]] = None, create_patch: bool = False, **kwargs: Any ) -> diff.DiffIndex: -- cgit v1.2.1 From 2e2fe186d09272c3cb6c96467fff362deb90994f Mon Sep 17 00:00:00 2001 From: Yobmod Date: Thu, 8 Jul 2021 11:30:16 +0100 Subject: Increase mypy strictness (no_implicit_optional & warn_redundant_casts) and fix errors --- git/index/base.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index c6d92526..d6670b2a 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -113,7 +113,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): _VERSION = 2 # latest version we support S_IFGITLINK = S_IFGITLINK # a submodule - def __init__(self, repo: 'Repo', file_path: PathLike = None) -> None: + def __init__(self, repo: 'Repo', file_path: Union[PathLike, None] = None) -> None: """Initialize this Index instance, optionally from the given ``file_path``. If no file_path is given, we will be created from the current index file. @@ -665,7 +665,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return entries_added def add(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], force: bool = True, - fprogress: Callable = lambda *args: None, path_rewriter: Callable = None, + fprogress: Callable = lambda *args: None, path_rewriter: Union[Callable[..., PathLike], None] = None, write: bool = True, write_extension_data: bool = False) -> List[BaseIndexEntry]: """Add files from the working tree, specific blobs or BaseIndexEntries to the index. @@ -970,7 +970,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return out def commit(self, message: str, parent_commits=None, head: bool = True, author: Union[None, 'Actor'] = None, - committer: Union[None, 'Actor'] = None, author_date: str = None, commit_date: str = None, + committer: Union[None, 'Actor'] = None, author_date: Union[str, None] = None, + commit_date: Union[str, None] = None, skip_hooks: bool = False) -> Commit: """Commit the current default index file, creating a commit object. For more information on the arguments, see tree.commit. @@ -1265,7 +1266,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): @ default_index def diff(self, other: Union[diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = diff.Diffable.Index, - paths: Union[str, List[PathLike], Tuple[PathLike, ...]] = None, create_patch: bool = False, **kwargs: Any + paths: Union[str, List[PathLike], Tuple[PathLike, ...], None] = None, + create_patch: bool = False, **kwargs: Any ) -> diff.DiffIndex: """Diff this index against the working copy or a Tree or Commit object -- cgit v1.2.1 From 5d3818ed3d51d400517a352b5b62e966164af8cf Mon Sep 17 00:00:00 2001 From: Yobmod Date: Thu, 8 Jul 2021 21:42:30 +0100 Subject: Finish initial typing of index folder --- git/index/base.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index d6670b2a..1812faee 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -18,6 +18,7 @@ from git.compat import ( from git.exc import ( GitCommandError, CheckoutError, + GitError, InvalidGitRepositoryError ) from git.objects import ( @@ -66,10 +67,10 @@ from .util import ( # typing ----------------------------------------------------------------------------- -from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List, +from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List, NoReturn, Sequence, TYPE_CHECKING, Tuple, Union) -from git.types import PathLike, TBD +from git.types import Commit_ish, PathLike, TBD if TYPE_CHECKING: from subprocess import Popen @@ -372,13 +373,13 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # UTILITIES @unbare_repo - def _iter_expand_paths(self, paths: Sequence[PathLike]) -> Iterator[PathLike]: + def _iter_expand_paths(self: 'IndexFile', paths: Sequence[PathLike]) -> Iterator[PathLike]: """Expand the directories in list of paths to the corresponding paths accordingly, Note: git will add items multiple times even if a glob overlapped with manually specified paths or if paths where specified multiple times - we respect that and do not prune""" - def raise_exc(e): + def raise_exc(e: Exception) -> NoReturn: raise e r = str(self.repo.working_tree_dir) rs = r + os.sep @@ -426,7 +427,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # END path exception handling # END for each path - def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item, fmakeexc, fprogress, + def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item: TBD, fmakeexc: Callable[..., GitError], + fprogress: Callable[[PathLike, bool, TBD], None], read_from_stdout: bool = True) -> Union[None, str]: """Write path to proc.stdin and make sure it processes the item, including progress. @@ -498,7 +500,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): line.sort() return path_map - @classmethod + @ classmethod def entry_key(cls, *entry: Union[BaseIndexEntry, PathLike, StageType]) -> Tuple[PathLike, StageType]: return entry_key(*entry) @@ -631,8 +633,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode), istream.binsha, 0, to_native_path_linux(filepath))) - @unbare_repo - @git_working_dir + @ unbare_repo + @ git_working_dir def _entries_for_paths(self, paths: List[str], path_rewriter: Callable, fprogress: Callable, entries: List[BaseIndexEntry]) -> List[BaseIndexEntry]: entries_added: List[BaseIndexEntry] = [] @@ -788,8 +790,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # create objects if required, otherwise go with the existing shas null_entries_indices = [i for i, e in enumerate(entries) if e.binsha == Object.NULL_BIN_SHA] if null_entries_indices: - @git_working_dir - def handle_null_entries(self): + @ git_working_dir + def handle_null_entries(self: 'IndexFile') -> None: for ei in null_entries_indices: null_entry = entries[ei] new_entry = self._store_path(null_entry.path, fprogress) @@ -969,8 +971,13 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return out - def commit(self, message: str, parent_commits=None, head: bool = True, author: Union[None, 'Actor'] = None, - committer: Union[None, 'Actor'] = None, author_date: Union[str, None] = None, + def commit(self, + message: str, + parent_commits: Union[Commit_ish, None] = None, + head: bool = True, + author: Union[None, 'Actor'] = None, + committer: Union[None, 'Actor'] = None, + author_date: Union[str, None] = None, commit_date: Union[str, None] = None, skip_hooks: bool = False) -> Commit: """Commit the current default index file, creating a commit object. -- cgit v1.2.1 From 7c6ae2b94cfd1593c12366b6abc0cd5bbb6e07b2 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 15:07:50 +0100 Subject: Try to distinguation git.diff module from diff.Diff.diff and diff.Daffable.diff() --- git/index/base.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index 1812faee..bd3dde99 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -41,7 +41,7 @@ from git.util import ( from gitdb.base import IStream from gitdb.db import MemoryDB -import git.diff as diff +import git.diff as git_diff import os.path as osp from .fun import ( @@ -88,7 +88,7 @@ Treeish = Union[Tree, Commit, str, bytes] __all__ = ('IndexFile', 'CheckoutError') -class IndexFile(LazyMixin, diff.Diffable, Serializable): +class IndexFile(LazyMixin, git_diff.Diffable, Serializable): """ Implements an Index that can be manipulated using a native implementation in @@ -575,8 +575,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): root_tree._cache = tree_items # type: ignore return root_tree - def _process_diff_args(self, args: List[Union[str, diff.Diffable, object]] - ) -> List[Union[str, diff.Diffable, object]]: + def _process_diff_args(self, args: List[Union[str, git_diff.Diffable, object]] + ) -> List[Union[str, git_diff.Diffable, object]]: try: args.pop(args.index(self)) except IndexError: @@ -1272,10 +1272,11 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return self @ default_index - def diff(self, other: Union[diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = diff.Diffable.Index, + def diff(self, + other: Union[git_diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = git_diff.Diffable.Index, paths: Union[str, List[PathLike], Tuple[PathLike, ...], None] = None, create_patch: bool = False, **kwargs: Any - ) -> diff.DiffIndex: + ) -> git_diff.DiffIndex: """Diff this index against the working copy or a Tree or Commit object For a documentation of the parameters and return values, see, @@ -1287,7 +1288,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): """ # index against index is always empty if other is self.Index: - return diff.DiffIndex() + return git_diff.DiffIndex() # index against anything but None is a reverse diff with the respective # item. Handle existing -R flags properly. Transform strings to the object -- cgit v1.2.1 From f916c148ea956655837a98817778abe685bf7ee7 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 15:40:14 +0100 Subject: Improve Diffable method typing --- git/index/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index bd3dde99..6738e223 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -68,7 +68,7 @@ from .util import ( # typing ----------------------------------------------------------------------------- from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List, NoReturn, - Sequence, TYPE_CHECKING, Tuple, Union) + Sequence, TYPE_CHECKING, Tuple, Type, Union) from git.types import Commit_ish, PathLike, TBD @@ -575,8 +575,8 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable): root_tree._cache = tree_items # type: ignore return root_tree - def _process_diff_args(self, args: List[Union[str, git_diff.Diffable, object]] - ) -> List[Union[str, git_diff.Diffable, object]]: + def _process_diff_args(self, args: List[Union[PathLike, 'git_diff.Diffable', Type['git_diff.Diffable.Index']]] + ) -> List[Union[PathLike, 'git_diff.Diffable', Type['git_diff.Diffable.Index']]]: try: args.pop(args.index(self)) except IndexError: -- cgit v1.2.1 From b03af0547f5381cf4043a43acf533687d91f0ea1 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 16:12:40 +0100 Subject: Remove defsult_index decorator from diff() and do check within function. Breaks typechecking for some reason --- git/index/base.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index 6738e223..149edf5a 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -1271,10 +1271,10 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable): return self - @ default_index + # @ default_index, breaks typing for some reason, copied into function def diff(self, other: Union[git_diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = git_diff.Diffable.Index, - paths: Union[str, List[PathLike], Tuple[PathLike, ...], None] = None, + paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None, create_patch: bool = False, **kwargs: Any ) -> git_diff.DiffIndex: """Diff this index against the working copy or a Tree or Commit object @@ -1286,6 +1286,11 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable): Will only work with indices that represent the default git index as they have not been initialized with a stream. """ + + # only run if we are the default repository index + if self._file_path != self._index_path(): + raise AssertionError( + "Cannot call %r on indices that do not represent the default git index" % self.diff()) # index against index is always empty if other is self.Index: return git_diff.DiffIndex() -- cgit v1.2.1 From 797e962fc1811ddc5a5a34308bd243953eb77135 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 16:27:34 +0100 Subject: Make IndexFile and Diffable .diff() types agree --- git/index/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index 149edf5a..75df5184 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -1273,7 +1273,8 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable): # @ default_index, breaks typing for some reason, copied into function def diff(self, - other: Union[git_diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = git_diff.Diffable.Index, + other: Union[Type['git_diff.Diffable.Index'], 'IndexFile.Index', + 'Tree', 'Commit', str, None] = git_diff.Diffable.Index, paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None, create_patch: bool = False, **kwargs: Any ) -> git_diff.DiffIndex: -- cgit v1.2.1 From 09053c565915d114384b1c20af8eecfed98c8069 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 22:58:02 +0100 Subject: Improve IndexFile_process_diff_args() to get checks to rerun --- git/index/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index 75df5184..6f6ea5aa 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -575,8 +575,9 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable): root_tree._cache = tree_items # type: ignore return root_tree - def _process_diff_args(self, args: List[Union[PathLike, 'git_diff.Diffable', Type['git_diff.Diffable.Index']]] - ) -> List[Union[PathLike, 'git_diff.Diffable', Type['git_diff.Diffable.Index']]]: + def _process_diff_args(self, # type: ignore[override] + args: List[Union[str, 'git_diff.Diffable', Type['git_diff.Diffable.Index']]] + ) -> List[Union[str, 'git_diff.Diffable', Type['git_diff.Diffable.Index']]]: try: args.pop(args.index(self)) except IndexError: @@ -1272,9 +1273,8 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable): return self # @ default_index, breaks typing for some reason, copied into function - def diff(self, - other: Union[Type['git_diff.Diffable.Index'], 'IndexFile.Index', - 'Tree', 'Commit', str, None] = git_diff.Diffable.Index, + def diff(self, # type: ignore[override] + other: Union[Type['git_diff.Diffable.Index'], 'Tree', 'Commit', str, None] = git_diff.Diffable.Index, paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None, create_patch: bool = False, **kwargs: Any ) -> git_diff.DiffIndex: -- cgit v1.2.1 From 2ea528e9fbcac850d99ce527ad4a5e4afb3587a8 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 23:21:16 +0100 Subject: Fix typing of index.fun.write_tree_from_cache() --- git/index/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/index/base.py') diff --git a/git/index/base.py b/git/index/base.py index 6f6ea5aa..3aa06e38 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -572,7 +572,7 @@ class IndexFile(LazyMixin, git_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 # type: ignore + root_tree._cache = tree_items # type: ignore # should this be encoded to [bytes, int, str]? return root_tree def _process_diff_args(self, # type: ignore[override] -- cgit v1.2.1