diff options
author | yobmod <yobmod@gmail.com> | 2021-05-03 15:59:07 +0100 |
---|---|---|
committer | yobmod <yobmod@gmail.com> | 2021-05-03 15:59:07 +0100 |
commit | 6752fad0e93d1d2747f56be30a52fea212bd15d6 (patch) | |
tree | a0618d53d06f35d7326fcacdcaf1832d7ab55b8c /git/repo/fun.py | |
parent | 2fd9f6ee5c8b4ae4e01a40dc398e2768d838210d (diff) | |
download | gitpython-6752fad0e93d1d2747f56be30a52fea212bd15d6.tar.gz |
add initial types to remote.py
Diffstat (limited to 'git/repo/fun.py')
-rw-r--r-- | git/repo/fun.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/git/repo/fun.py b/git/repo/fun.py index b8184593..70394081 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -18,11 +18,12 @@ from git.cmd import Git # Typing ---------------------------------------------------------------------- -from .base import Repo -from git.db import GitCmdObjectDB -from git.objects import Commit, TagObject, Blob, Tree -from typing import AnyStr, Union, Optional, cast +from typing import AnyStr, Union, Optional, cast, TYPE_CHECKING from git.types import PathLike +if TYPE_CHECKING: + from .base import Repo + from git.db import GitCmdObjectDB + from git.objects import Commit, TagObject, Blob, Tree # ---------------------------------------------------------------------------- @@ -102,7 +103,7 @@ def find_submodule_git_dir(d: PathLike) -> Optional[PathLike]: return None -def short_to_long(odb: GitCmdObjectDB, hexsha: AnyStr) -> Optional[bytes]: +def short_to_long(odb: 'GitCmdObjectDB', hexsha: AnyStr) -> Optional[bytes]: """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha or None if no candidate could be found. :param hexsha: hexsha with less than 40 byte""" @@ -113,8 +114,8 @@ def short_to_long(odb: GitCmdObjectDB, hexsha: AnyStr) -> Optional[bytes]: # END exception handling -def name_to_object(repo: Repo, name: str, return_ref: bool = False, - ) -> Union[SymbolicReference, Commit, TagObject, Blob, Tree]: +def name_to_object(repo: 'Repo', name: str, return_ref: bool = False + ) -> Union[SymbolicReference, 'Commit', 'TagObject', 'Blob', 'Tree']: """ :return: object specified by the given name, hexshas ( short and long ) as well as references are supported @@ -161,7 +162,7 @@ def name_to_object(repo: Repo, name: str, return_ref: bool = False, return Object.new_from_sha(repo, hex_to_bin(hexsha)) -def deref_tag(tag: Tag) -> TagObject: +def deref_tag(tag: Tag) -> 'TagObject': """Recursively dereference a tag and return the resulting object""" while True: try: @@ -172,7 +173,7 @@ def deref_tag(tag: Tag) -> TagObject: return tag -def to_commit(obj: Object) -> Union[Commit, TagObject]: +def to_commit(obj: Object) -> Union['Commit', 'TagObject']: """Convert the given object to a commit if possible and return it""" if obj.type == 'tag': obj = deref_tag(obj) @@ -183,7 +184,7 @@ def to_commit(obj: Object) -> Union[Commit, TagObject]: return obj -def rev_parse(repo: Repo, rev: str) -> Union[Commit, Tag, Tree, Blob]: +def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']: """ :return: Object at the given revision, either Commit, Tag, Tree or Blob :param rev: git-rev-parse compatible revision specification as string, please see |