From 595181da70978ed44983a6c0ca4cb6d982ba0e8b Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sun, 16 May 2021 21:21:44 +0100 Subject: flake8 and mypy fixes --- git/cmd.py | 8 ++++---- git/db.py | 12 ++++++------ git/index/base.py | 2 +- git/index/util.py | 5 +---- git/refs/log.py | 4 ++-- git/repo/fun.py | 4 ++-- git/util.py | 5 ++++- 7 files changed, 20 insertions(+), 20 deletions(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index d46ccef3..d8b82352 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -615,7 +615,7 @@ class Git(LazyMixin): # 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 @@ -1187,7 +1187,7 @@ class Git(LazyMixin): 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. @@ -1198,7 +1198,7 @@ class Git(LazyMixin): 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""" @@ -1207,7 +1207,7 @@ class Git(LazyMixin): 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) diff --git a/git/db.py b/git/db.py index dc60c555..47cccda8 100644 --- a/git/db.py +++ b/git/db.py @@ -12,7 +12,7 @@ from git.exc import GitCommandError # typing------------------------------------------------- -from typing import TYPE_CHECKING, AnyStr +from typing import TYPE_CHECKING from git.types import PathLike if TYPE_CHECKING: @@ -39,18 +39,18 @@ class GitCmdObjectDB(LooseObjectDB): 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: diff --git a/git/index/base.py b/git/index/base.py index 54f73617..2bb62f32 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -272,7 +272,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return self @classmethod - def new(cls, repo: 'Repo', *tree_sha: bytes) -> 'IndexFile': + def new(cls, repo: 'Repo', *tree_sha: Union[str, Tree]) -> 'IndexFile': """ Merge the given treeish revisions into a new index which is returned. This method behaves like git-read-tree --aggressive when doing the merge. diff --git a/git/index/util.py b/git/index/util.py index ccdc5c1c..471e9262 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -11,13 +11,10 @@ import os.path as osp # typing ---------------------------------------------------------------------- -from typing import (Any, Callable, List, Sequence, TYPE_CHECKING, Tuple, cast) +from typing import (Any, Callable) from git.types import PathLike -if TYPE_CHECKING: - from git.repo import Repo - # --------------------------------------------------------------------------------- diff --git a/git/refs/log.py b/git/refs/log.py index fcd2c23c..363c3c5d 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -97,8 +97,8 @@ class RefLogEntry(tuple): " Got %s" % repr(line)) # END handle first split - oldhexsha = info[:40] - newhexsha = info[41:81] + oldhexsha = info[:40] # type: str + newhexsha = info[41:81] # type: str for hexsha in (oldhexsha, newhexsha): if not cls._re_hexsha_only.match(hexsha): raise ValueError("Invalid hexsha: %r" % (hexsha,)) diff --git a/git/repo/fun.py b/git/repo/fun.py index 70394081..e96b62e0 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -18,7 +18,7 @@ from git.cmd import Git # Typing ---------------------------------------------------------------------- -from typing import AnyStr, Union, Optional, cast, TYPE_CHECKING +from typing import Union, Optional, cast, TYPE_CHECKING from git.types import PathLike if TYPE_CHECKING: from .base import Repo @@ -103,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: str) -> 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""" diff --git a/git/util.py b/git/util.py index 220901a4..581bf877 100644 --- a/git/util.py +++ b/git/util.py @@ -24,6 +24,7 @@ from urllib.parse import urlsplit, urlunsplit from typing import (Any, AnyStr, BinaryIO, Callable, Dict, Generator, IO, Iterator, List, Optional, Pattern, Sequence, Tuple, Union, cast, TYPE_CHECKING, overload) +import pathlib if TYPE_CHECKING: from git.remote import Remote @@ -379,7 +380,9 @@ def expand_path(p: PathLike, expand_vars: bool = ...) -> str: ... -def expand_path(p: Union[None, PathLike], expand_vars: bool = True) -> Optional[str]: +def expand_path(p: Union[None, PathLike], expand_vars: bool = True) -> Optional[PathLike]: + if isinstance(p, pathlib.Path): + return p.resolve() try: p = osp.expanduser(p) # type: ignore if expand_vars: -- cgit v1.2.1