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/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git/index/util.py') diff --git a/git/index/util.py b/git/index/util.py index 471e9262..e0daef0c 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -13,7 +13,7 @@ import os.path as osp from typing import (Any, Callable) -from git.types import PathLike +from git.types import PathLike, _T # --------------------------------------------------------------------------------- @@ -88,12 +88,12 @@ 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, *args: Any, **kwargs: Any) -> _T: cur_wd = os.getcwd() os.chdir(self.repo.working_tree_dir) try: -- cgit v1.2.1 From 873ebe61431c50bb39afd5cafff498b3e1879342 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 17:56:24 +0100 Subject: Make diff.DiffIndex generic List['Diff'] --- git/index/util.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'git/index/util.py') diff --git a/git/index/util.py b/git/index/util.py index e0daef0c..3b3d6489 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -52,7 +52,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 +63,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, *args: Any, **kwargs: Any) -> _T: rval = func(self, *args, **kwargs) self._delete_entries_cache() return rval @@ -72,13 +72,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, *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__) -- 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/util.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'git/index/util.py') diff --git a/git/index/util.py b/git/index/util.py index 3b3d6489..4f8af553 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -11,10 +11,13 @@ import os.path as osp # typing ---------------------------------------------------------------------- -from typing import (Any, Callable) +from typing import (Any, Callable, TYPE_CHECKING) from git.types import PathLike, _T +if TYPE_CHECKING: + from git.index import IndexFile + # --------------------------------------------------------------------------------- @@ -63,7 +66,7 @@ def post_clear_cache(func: Callable[..., _T]) -> Callable[..., _T]: """ @wraps(func) - def post_clear_cache_if_not_raised(self, *args: Any, **kwargs: Any) -> _T: + 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 @@ -78,7 +81,7 @@ def default_index(func: Callable[..., _T]) -> Callable[..., _T]: on that index only. """ @wraps(func) - def check_default_index(self, *args: Any, **kwargs: Any) -> _T: + 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__) @@ -93,9 +96,9 @@ def git_working_dir(func: Callable[..., _T]) -> Callable[..., _T]: repository in order to assure relative paths are handled correctly""" @wraps(func) - def set_git_working_dir(self, *args: Any, **kwargs: Any) -> _T: + 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: -- cgit v1.2.1