| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,18 @@ | |||
| 9 | 9 | import os.path as osp | |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | + # typing ---------------------------------------------------------------------- | ||
| 13 | + | ||
| 14 | + from typing import (Any, Callable, List, Sequence, TYPE_CHECKING, Tuple, cast) | ||
| 15 | + | ||
| 16 | + from git.types import PathLike | ||
| 17 | + | ||
| 18 | + if TYPE_CHECKING: | ||
| 19 | + from git.repo import Repo | ||
| 20 | + | ||
| 21 | + # --------------------------------------------------------------------------------- | ||
| 22 | + | ||
| 23 | + | ||
| 12 | 24 | __all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir') | |
| 13 | 25 | ||
| 14 | 26 | #{ Aliases | |
@@ -24,16 +36,16 @@ class TemporaryFileSwap(object): | |||
| 24 | 36 | and moving it back on to where on object deletion.""" | |
| 25 | 37 | __slots__ = ("file_path", "tmp_file_path") | |
| 26 | 38 | ||
| 27 | - def __init__(self, file_path): | ||
| 39 | + def __init__(self, file_path: PathLike) -> None: | ||
| 28 | 40 | self.file_path = file_path | |
| 29 | - self.tmp_file_path = self.file_path + tempfile.mktemp('', '', '') | ||
| 41 | + self.tmp_file_path = str(self.file_path) + tempfile.mktemp('', '', '') | ||
| 30 | 42 | # it may be that the source does not exist | |
| 31 | 43 | try: | |
| 32 | 44 | os.rename(self.file_path, self.tmp_file_path) | |
| 33 | 45 | except OSError: | |
| 34 | 46 | pass | |
| 35 | 47 | ||
| 36 | - def __del__(self): | ||
| 48 | + def __del__(self) -> None: | ||
| 37 | 49 | if osp.isfile(self.tmp_file_path): | |
| 38 | 50 | if is_win and osp.exists(self.file_path): | |
| 39 | 51 | os.remove(self.file_path) | |
@@ -43,7 +55,7 @@ def __del__(self): | |||
| 43 | 55 | ||
| 44 | 56 | #{ Decorators | |
| 45 | 57 | ||
| 46 | - def post_clear_cache(func): | ||
| 58 | + def post_clear_cache(func: Callable[..., Any]) -> Callable[..., Any]: | ||
| 47 | 59 | """Decorator for functions that alter the index using the git command. This would | |
| 48 | 60 | invalidate our possibly existing entries dictionary which is why it must be | |
| 49 | 61 | deleted to allow it to be lazily reread later. | |
@@ -54,7 +66,7 @@ def post_clear_cache(func): | |||
| 54 | 66 | """ | |
| 55 | 67 | ||
| 56 | 68 | @wraps(func) | |
| 57 | - def post_clear_cache_if_not_raised(self, *args, **kwargs): | ||
| 69 | + def post_clear_cache_if_not_raised(self, *args: Any, **kwargs: Any) -> Any: | ||
| 58 | 70 | rval = func(self, *args, **kwargs) | |
| 59 | 71 | self._delete_entries_cache() | |
| 60 | 72 | return rval | |
@@ -63,13 +75,13 @@ def post_clear_cache_if_not_raised(self, *args, **kwargs): | |||
| 63 | 75 | return post_clear_cache_if_not_raised | |
| 64 | 76 | ||
| 65 | 77 | ||
| 66 | - def default_index(func): | ||
| 78 | + def default_index(func: Callable[..., Any]) -> Callable[..., Any]: | ||
| 67 | 79 | """Decorator assuring the wrapped method may only run if we are the default | |
| 68 | 80 | repository index. This is as we rely on git commands that operate | |
| 69 | 81 | on that index only. """ | |
| 70 | 82 | ||
| 71 | 83 | @wraps(func) | |
| 72 | - def check_default_index(self, *args, **kwargs): | ||
| 84 | + def check_default_index(self, *args: Any, **kwargs: Any) -> Any: | ||
| 73 | 85 | if self._file_path != self._index_path(): | |
| 74 | 86 | raise AssertionError( | |
| 75 | 87 | "Cannot call %r on indices that do not represent the default git index" % func.__name__) | |
@@ -79,12 +91,12 @@ def check_default_index(self, *args, **kwargs): | |||
| 79 | 91 | return check_default_index | |
| 80 | 92 | ||
| 81 | 93 | ||
| 82 | - def git_working_dir(func): | ||
| 94 | + def git_working_dir(func: Callable[..., Any]) -> Callable[..., None]: | ||
| 83 | 95 | """Decorator which changes the current working dir to the one of the git | |
| 84 | 96 | repository in order to assure relative paths are handled correctly""" | |
| 85 | 97 | ||
| 86 | 98 | @wraps(func) | |
| 87 | - def set_git_working_dir(self, *args, **kwargs): | ||
| 99 | + def set_git_working_dir(self, *args: Any, **kwargs: Any) -> None: | ||
| 88 | 100 | cur_wd = os.getcwd() | |
| 89 | 101 | os.chdir(self.repo.working_tree_dir) | |
| 90 | 102 | try: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments