diff options
-rw-r--r-- | git/remote.py | 28 | ||||
-rw-r--r-- | git/types.py | 5 |
2 files changed, 21 insertions, 12 deletions
diff --git a/git/remote.py b/git/remote.py index 194db938..8404b190 100644 --- a/git/remote.py +++ b/git/remote.py @@ -36,10 +36,13 @@ from .refs import ( # typing------------------------------------------------------- -from typing import TYPE_CHECKING +from typing import Any, Optional, Set, TYPE_CHECKING, Union + +from git.types import PathLike, Literal if TYPE_CHECKING: from git.repo.base import Repo + from git.objects.commit import Commit # ------------------------------------------------------------- @@ -52,7 +55,7 @@ __all__ = ('RemoteProgress', 'PushInfo', 'FetchInfo', 'Remote') #{ Utilities -def add_progress(kwargs, git, progress): +def add_progress(kwargs: Any, git: Git, progress: RemoteProgress) -> Any: """Add the --progress flag to the given kwargs dict if supported by the git command. If the actual progress in the given progress instance is not given, we do not request any progress @@ -68,7 +71,7 @@ def add_progress(kwargs, git, progress): #} END utilities -def to_progress_instance(progress): +def to_progress_instance(progress: Optional[RemoteProgress]) -> Union[RemoteProgress, CallableRemoteProgress]: """Given the 'progress' return a suitable object derived from RemoteProgress(). """ @@ -112,8 +115,8 @@ class PushInfo(object): '=': UP_TO_DATE, '!': ERROR} - def __init__(self, flags, local_ref, remote_ref_string, remote, old_commit=None, - summary=''): + def __init__(self, flags: Set[int], local_ref: SymbolicReference, remote_ref_string: str, remote, + old_commit: Optional[bytes] = None, summary: str = '') -> None: """ Initialize a new instance """ self.flags = flags self.local_ref = local_ref @@ -123,11 +126,11 @@ class PushInfo(object): self.summary = summary @property - def old_commit(self): + def old_commit(self) -> Optional[bool]: return self._old_commit_sha and self._remote.repo.commit(self._old_commit_sha) or None @property - def remote_ref(self): + def remote_ref(self) -> Union[RemoteReference, TagReference]: """ :return: Remote Reference or TagReference in the local repository corresponding @@ -229,7 +232,7 @@ class FetchInfo(object): } @classmethod - def refresh(cls): + def refresh(cls) -> Literal[True]: """This gets called by the refresh function (see the top level __init__). """ @@ -252,7 +255,8 @@ class FetchInfo(object): return True - def __init__(self, ref, flags, note='', old_commit=None, remote_ref_path=None): + def __init__(self, ref: SymbolicReference, flags: Set[int], note: str = '', old_commit: Optional[Commit] = None, + remote_ref_path: Optional[PathLike] = None): """ Initialize a new instance """ @@ -262,16 +266,16 @@ class FetchInfo(object): self.old_commit = old_commit self.remote_ref_path = remote_ref_path - def __str__(self): + def __str__(self) -> str: return self.name @property - def name(self): + def name(self) -> str: """:return: Name of our remote ref""" return self.ref.name @property - def commit(self): + def commit(self) -> 'Commit': """:return: Commit of our remote ref""" return self.ref.commit diff --git a/git/types.py b/git/types.py index 3e33ae0c..40d4f788 100644 --- a/git/types.py +++ b/git/types.py @@ -6,6 +6,11 @@ import os import sys from typing import Union, Any +if sys.version_info[:2] >= (3, 8): + from typing import Final, Literal # noqa: F401 +else: + from typing_extensions import Final, Literal # noqa: F401 + TBD = Any |