Skip to content

Added types to Index submodule #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def _set_cache_(self, attr: str) -> None:
# END handle version info

@property
def working_dir(self) -> Union[None, str]:
def working_dir(self) -> Union[None, PathLike]:
""":return: Git directory we are working on"""
return self._working_dir

Expand Down Expand Up @@ -1187,7 +1187,7 @@ def __get_object_header(self, cmd, ref: AnyStr) -> Tuple[str, str, int]:
cmd.stdin.flush()
return self._parse_object_header(cmd.stdout.readline())

def get_object_header(self, ref: AnyStr) -> Tuple[str, str, int]:
def get_object_header(self, ref: str) -> Tuple[str, str, int]:
""" Use this method to quickly examine the type and size of the object behind
the given ref.

Expand All @@ -1198,7 +1198,7 @@ def get_object_header(self, ref: AnyStr) -> Tuple[str, str, int]:
cmd = self._get_persistent_cmd("cat_file_header", "cat_file", batch_check=True)
return self.__get_object_header(cmd, ref)

def get_object_data(self, ref: AnyStr) -> Tuple[str, str, int, bytes]:
def get_object_data(self, ref: str) -> Tuple[str, str, int, bytes]:
""" As get_object_header, but returns object data as well
:return: (hexsha, type_string, size_as_int,data_string)
:note: not threadsafe"""
Expand All @@ -1207,7 +1207,7 @@ def get_object_data(self, ref: AnyStr) -> Tuple[str, str, int, bytes]:
del(stream)
return (hexsha, typename, size, data)

def stream_object_data(self, ref: AnyStr) -> Tuple[str, str, int, 'Git.CatFileContentStream']:
def stream_object_data(self, ref: str) -> Tuple[str, str, int, 'Git.CatFileContentStream']:
""" As get_object_header, but returns the data as a stream

:return: (hexsha, type_string, size_as_int, stream)
Expand Down
12 changes: 6 additions & 6 deletions git/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# typing-------------------------------------------------

from typing import TYPE_CHECKING, AnyStr
from typing import TYPE_CHECKING
from git.types import PathLike

if TYPE_CHECKING:
Expand All @@ -39,18 +39,18 @@ def __init__(self, root_path: PathLike, git: 'Git') -> None:
super(GitCmdObjectDB, self).__init__(root_path)
self._git = git

def info(self, sha: bytes) -> OInfo:
hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha))
def info(self, binsha: bytes) -> OInfo:
hexsha, typename, size = self._git.get_object_header(bin_to_hex(binsha))
return OInfo(hex_to_bin(hexsha), typename, size)

def stream(self, sha: bytes) -> OStream:
def stream(self, binsha: bytes) -> OStream:
"""For now, all lookup is done by git itself"""
hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(sha))
hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(binsha))
return OStream(hex_to_bin(hexsha), typename, size, stream)

# { Interface

def partial_to_complete_sha_hex(self, partial_hexsha: AnyStr) -> bytes:
def partial_to_complete_sha_hex(self, partial_hexsha: str) -> bytes:
""":return: Full binary 20 byte sha from the given partial hexsha
:raise AmbiguousObjectName:
:raise BadObject:
Expand Down
4 changes: 2 additions & 2 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# typing ------------------------------------------------------------------

from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING
from git.types import TBD, Final, Literal
from git.types import PathLike, TBD, Final, Literal

if TYPE_CHECKING:
from .objects.tree import Tree
Expand Down Expand Up @@ -84,7 +84,7 @@ def _process_diff_args(self, args: List[Union[str, 'Diffable', object]]) -> List
return args

def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Index,
paths: Union[str, List[str], Tuple[str, ...], None] = None,
paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None,
create_patch: bool = False, **kwargs: Any) -> 'DiffIndex':
"""Creates diffs between two items being trees, trees and index or an
index and the working tree. It will detect renames automatically.
Expand Down
4 changes: 2 additions & 2 deletions git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# typing ----------------------------------------------------

from typing import List, Optional, Tuple, Union, TYPE_CHECKING
from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
from git.types import PathLike

if TYPE_CHECKING:
Expand Down Expand Up @@ -113,7 +113,7 @@ class CheckoutError(GitError):
were checked out successfully and hence match the version stored in the
index"""

def __init__(self, message: str, failed_files: List[PathLike], valid_files: List[PathLike],
def __init__(self, message: str, failed_files: Sequence[PathLike], valid_files: List[PathLike],
failed_reasons: List[str]) -> None:

Exception.__init__(self, message)
Expand Down
Loading