Skip to content

Commit

Permalink
Merge pull request #1634 from madebylydia/main
Browse files Browse the repository at this point in the history
feat: full typing for "progress" parameter in Repo class
  • Loading branch information
Byron committed Aug 28, 2023
2 parents 1c8310d + 9f74c05 commit e19abe7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions git/repo/base.py
Expand Up @@ -60,6 +60,7 @@
PathLike,
Lit_config_levels,
Commit_ish,
CallableProgress,
Tree_ish,
assert_never,
)
Expand Down Expand Up @@ -1258,7 +1259,7 @@ def _clone(
def clone(
self,
path: PathLike,
progress: Optional[Callable] = None,
progress: Optional[CallableProgress] = None,
multi_options: Optional[List[str]] = None,
allow_unsafe_protocols: bool = False,
allow_unsafe_options: bool = False,
Expand Down Expand Up @@ -1297,7 +1298,7 @@ def clone_from(
cls,
url: PathLike,
to_path: PathLike,
progress: Optional[Callable] = None,
progress: CallableProgress = None,
env: Optional[Mapping[str, str]] = None,
multi_options: Optional[List[str]] = None,
allow_unsafe_protocols: bool = False,
Expand Down
22 changes: 11 additions & 11 deletions git/types.py
Expand Up @@ -8,42 +8,39 @@
from typing import (
Dict,
NoReturn,
Sequence,
Sequence as Sequence,
Tuple,
Union,
Any,
Optional,
Callable,
TYPE_CHECKING,
TypeVar,
) # noqa: F401

if sys.version_info[:2] >= (3, 8):
if sys.version_info >= (3, 8):
from typing import (
Literal,
SupportsIndex,
TypedDict,
Protocol,
SupportsIndex as SupportsIndex,
runtime_checkable,
) # noqa: F401
else:
from typing_extensions import (
Literal,
SupportsIndex, # noqa: F401
SupportsIndex as SupportsIndex,
TypedDict,
Protocol,
runtime_checkable,
) # noqa: F401

# if sys.version_info[:2] >= (3, 10):
# if sys.version_info >= (3, 10):
# from typing import TypeGuard # noqa: F401
# else:
# from typing_extensions import TypeGuard # noqa: F401


if sys.version_info[:2] < (3, 9):
PathLike = Union[str, os.PathLike]
else:
# os.PathLike only becomes subscriptable from Python 3.9 onwards
PathLike = Union[str, os.PathLike[str]]
PathLike = Union[str, "os.PathLike[str]"]

if TYPE_CHECKING:
from git.repo import Repo
Expand All @@ -62,6 +59,9 @@

Lit_config_levels = Literal["system", "global", "user", "repository"]

# Progress parameter type alias -----------------------------------------

CallableProgress = Optional[Callable[[int, Union[str, float], Union[str, float, None], str], None]]

# def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]:
# # return inp in get_args(Lit_config_level) # only py >= 3.8
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Expand Up @@ -10,4 +10,4 @@ pytest-icdiff
# pytest-profiling


tox
tox

0 comments on commit e19abe7

Please sign in to comment.