diff options
author | Yobmod <yobmod@gmail.com> | 2021-07-31 16:37:56 +0100 |
---|---|---|
committer | Yobmod <yobmod@gmail.com> | 2021-07-31 16:37:56 +0100 |
commit | 24c124208a870c6c041a304a12a7b91968225ac7 (patch) | |
tree | fe2b8d31e15bb5a8592aafbc1d97cc0018689c2f /git/refs/symbolic.py | |
parent | 7e972b982cea094b84df27a7b0be5a4dd13b8469 (diff) | |
download | gitpython-24c124208a870c6c041a304a12a7b91968225ac7.tar.gz |
Add type to symbolicreference()
Diffstat (limited to 'git/refs/symbolic.py')
-rw-r--r-- | git/refs/symbolic.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index d712e5a2..7da10cb2 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -36,7 +36,7 @@ T_References = TypeVar('T_References', bound='SymbolicReference') __all__ = ["SymbolicReference"] -def _git_dir(repo: 'Repo', path: PathLike) -> PathLike: +def _git_dir(repo: 'Repo', path: Union[PathLike, None]) -> PathLike: """ Find the git dir that's appropriate for the path""" name = f"{path}" if name in ['HEAD', 'ORIG_HEAD', 'FETCH_HEAD', 'index', 'logs']: @@ -136,26 +136,27 @@ class SymbolicReference(object): # alright. @classmethod - def dereference_recursive(cls, repo: 'Repo', ref_path: PathLike) -> str: + def dereference_recursive(cls, repo: 'Repo', ref_path: Union[None, PathLike]) -> str: """ :return: hexsha stored in the reference at the given ref_path, recursively dereferencing all intermediate references as required :param repo: the repository containing the reference at ref_path""" - while True: + while True: # loop that overwrites ref_path each loop hexsha, ref_path = cls._get_ref_info(repo, ref_path) if hexsha is not None: return hexsha # END recursive dereferencing @classmethod - def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, str]]: + def _get_ref_info_helper(cls, repo: 'Repo', ref_path: Union[PathLike, None] + ) -> Union[Tuple[str, None], Tuple[None, str]]: """Return: (str(sha), str(target_ref_path)) if available, the sha the file at rela_path points to, or None. target_ref_path is the reference we point to, or None""" tokens: Union[None, List[str], Tuple[str, str]] = None repodir = _git_dir(repo, ref_path) try: - with open(os.path.join(repodir, ref_path), 'rt', encoding='UTF-8') as fp: + with open(os.path.join(repodir, cast(str, ref_path)), 'rt', encoding='UTF-8') as fp: value = fp.read().rstrip() # Don't only split on spaces, but on whitespace, which allows to parse lines like # 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo @@ -187,7 +188,7 @@ class SymbolicReference(object): raise ValueError("Failed to parse reference information from %r" % ref_path) @classmethod - def _get_ref_info(cls, repo, ref_path): + def _get_ref_info(cls, repo: 'Repo', ref_path: Union[PathLike, None]) -> Union[Tuple[str, None], Tuple[None, str]]: """Return: (str(sha), str(target_ref_path)) if available, the sha the file at rela_path points to, or None. target_ref_path is the reference we point to, or None""" |