diff options
Diffstat (limited to 'git/index/util.py')
-rw-r--r-- | git/index/util.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/git/index/util.py b/git/index/util.py index 471e9262..4f8af553 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -11,9 +11,12 @@ import os.path as osp # typing ---------------------------------------------------------------------- -from typing import (Any, Callable) +from typing import (Any, Callable, TYPE_CHECKING) -from git.types import PathLike +from git.types import PathLike, _T + +if TYPE_CHECKING: + from git.index import IndexFile # --------------------------------------------------------------------------------- @@ -52,7 +55,7 @@ class TemporaryFileSwap(object): #{ Decorators -def post_clear_cache(func: Callable[..., Any]) -> Callable[..., Any]: +def post_clear_cache(func: Callable[..., _T]) -> Callable[..., _T]: """Decorator for functions that alter the index using the git command. This would invalidate our possibly existing entries dictionary which is why it must be deleted to allow it to be lazily reread later. @@ -63,7 +66,7 @@ def post_clear_cache(func: Callable[..., Any]) -> Callable[..., Any]: """ @wraps(func) - def post_clear_cache_if_not_raised(self, *args: Any, **kwargs: Any) -> Any: + def post_clear_cache_if_not_raised(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T: rval = func(self, *args, **kwargs) self._delete_entries_cache() return rval @@ -72,13 +75,13 @@ def post_clear_cache(func: Callable[..., Any]) -> Callable[..., Any]: return post_clear_cache_if_not_raised -def default_index(func: Callable[..., Any]) -> Callable[..., Any]: +def default_index(func: Callable[..., _T]) -> Callable[..., _T]: """Decorator assuring the wrapped method may only run if we are the default repository index. This is as we rely on git commands that operate on that index only. """ @wraps(func) - def check_default_index(self, *args: Any, **kwargs: Any) -> Any: + def check_default_index(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T: if self._file_path != self._index_path(): raise AssertionError( "Cannot call %r on indices that do not represent the default git index" % func.__name__) @@ -88,14 +91,14 @@ def default_index(func: Callable[..., Any]) -> Callable[..., Any]: return check_default_index -def git_working_dir(func: Callable[..., Any]) -> Callable[..., None]: +def git_working_dir(func: Callable[..., _T]) -> Callable[..., _T]: """Decorator which changes the current working dir to the one of the git repository in order to assure relative paths are handled correctly""" @wraps(func) - def set_git_working_dir(self, *args: Any, **kwargs: Any) -> None: + def set_git_working_dir(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T: cur_wd = os.getcwd() - os.chdir(self.repo.working_tree_dir) + os.chdir(str(self.repo.working_tree_dir)) try: return func(self, *args, **kwargs) finally: |