Skip to content

Commit 595181d

Browse files
committed
flake8 and mypy fixes
1 parent f58702b commit 595181d

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

git/cmd.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def _set_cache_(self, attr: str) -> None:
615615
# END handle version info
616616

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

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

1190-
def get_object_header(self, ref: AnyStr) -> Tuple[str, str, int]:
1190+
def get_object_header(self, ref: str) -> Tuple[str, str, int]:
11911191
""" Use this method to quickly examine the type and size of the object behind
11921192
the given ref.
11931193
@@ -1198,7 +1198,7 @@ def get_object_header(self, ref: AnyStr) -> Tuple[str, str, int]:
11981198
cmd = self._get_persistent_cmd("cat_file_header", "cat_file", batch_check=True)
11991199
return self.__get_object_header(cmd, ref)
12001200

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

1210-
def stream_object_data(self, ref: AnyStr) -> Tuple[str, str, int, 'Git.CatFileContentStream']:
1210+
def stream_object_data(self, ref: str) -> Tuple[str, str, int, 'Git.CatFileContentStream']:
12111211
""" As get_object_header, but returns the data as a stream
12121212
12131213
:return: (hexsha, type_string, size_as_int, stream)

git/db.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# typing-------------------------------------------------
1414

15-
from typing import TYPE_CHECKING, AnyStr
15+
from typing import TYPE_CHECKING
1616
from git.types import PathLike
1717

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

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

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

5151
# { Interface
5252

53-
def partial_to_complete_sha_hex(self, partial_hexsha: AnyStr) -> bytes:
53+
def partial_to_complete_sha_hex(self, partial_hexsha: str) -> bytes:
5454
""":return: Full binary 20 byte sha from the given partial hexsha
5555
:raise AmbiguousObjectName:
5656
:raise BadObject:

git/index/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def merge_tree(self, rhs: Treeish, base: Union[None, Treeish] = None) -> 'IndexF
272272
return self
273273

274274
@classmethod
275-
def new(cls, repo: 'Repo', *tree_sha: bytes) -> 'IndexFile':
275+
def new(cls, repo: 'Repo', *tree_sha: Union[str, Tree]) -> 'IndexFile':
276276
""" Merge the given treeish revisions into a new index which is returned.
277277
This method behaves like git-read-tree --aggressive when doing the merge.
278278

git/index/util.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111

1212
# typing ----------------------------------------------------------------------
1313

14-
from typing import (Any, Callable, List, Sequence, TYPE_CHECKING, Tuple, cast)
14+
from typing import (Any, Callable)
1515

1616
from git.types import PathLike
1717

18-
if TYPE_CHECKING:
19-
from git.repo import Repo
20-
2118
# ---------------------------------------------------------------------------------
2219

2320

git/refs/log.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ def from_line(cls, line):
9797
" Got %s" % repr(line))
9898
# END handle first split
9999

100-
oldhexsha = info[:40]
101-
newhexsha = info[41:81]
100+
oldhexsha = info[:40] # type: str
101+
newhexsha = info[41:81] # type: str
102102
for hexsha in (oldhexsha, newhexsha):
103103
if not cls._re_hexsha_only.match(hexsha):
104104
raise ValueError("Invalid hexsha: %r" % (hexsha,))

git/repo/fun.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Typing ----------------------------------------------------------------------
2020

21-
from typing import AnyStr, Union, Optional, cast, TYPE_CHECKING
21+
from typing import Union, Optional, cast, TYPE_CHECKING
2222
from git.types import PathLike
2323
if TYPE_CHECKING:
2424
from .base import Repo
@@ -103,7 +103,7 @@ def find_submodule_git_dir(d: PathLike) -> Optional[PathLike]:
103103
return None
104104

105105

106-
def short_to_long(odb: 'GitCmdObjectDB', hexsha: AnyStr) -> Optional[bytes]:
106+
def short_to_long(odb: 'GitCmdObjectDB', hexsha: str) -> Optional[bytes]:
107107
""":return: long hexadecimal sha1 from the given less-than-40 byte hexsha
108108
or None if no candidate could be found.
109109
:param hexsha: hexsha with less than 40 byte"""

git/util.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import (Any, AnyStr, BinaryIO, Callable, Dict, Generator, IO, Iterator, List,
2525
Optional, Pattern, Sequence, Tuple, Union, cast, TYPE_CHECKING, overload)
2626

27+
import pathlib
2728

2829
if TYPE_CHECKING:
2930
from git.remote import Remote
@@ -379,7 +380,9 @@ def expand_path(p: PathLike, expand_vars: bool = ...) -> str:
379380
...
380381

381382

382-
def expand_path(p: Union[None, PathLike], expand_vars: bool = True) -> Optional[str]:
383+
def expand_path(p: Union[None, PathLike], expand_vars: bool = True) -> Optional[PathLike]:
384+
if isinstance(p, pathlib.Path):
385+
return p.resolve()
383386
try:
384387
p = osp.expanduser(p) # type: ignore
385388
if expand_vars:

0 commit comments

Comments
 (0)