summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-07-31 22:59:11 +0100
committerYobmod <yobmod@gmail.com>2021-07-31 22:59:11 +0100
commitc878771e3a31c983a0c3468396ed33a532f87e98 (patch)
treeed7d6b93e0f72e25e52009d99a42cdfc6bcbb632
parent39d37d550963a6a64e66ba3d6b9f4b077270a3ad (diff)
downloadgitpython-c878771e3a31c983a0c3468396ed33a532f87e98.tar.gz
replace more TBDs wiht runtime types
-rw-r--r--git/cmd.py12
-rw-r--r--git/config.py11
-rw-r--r--git/remote.py10
-rw-r--r--git/repo/base.py9
4 files changed, 22 insertions, 20 deletions
diff --git a/git/cmd.py b/git/cmd.py
index cbfde74c..85a5fbe9 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -421,15 +421,15 @@ class Git(LazyMixin):
return getattr(self.proc, attr)
# TODO: Bad choice to mimic `proc.wait()` but with different args.
- def wait(self, stderr: Union[None, bytes] = b'') -> int:
+ def wait(self, stderr: Union[None, str, bytes] = b'') -> int:
"""Wait for the process and return its status code.
:param stderr: Previously read value of stderr, in case stderr is already closed.
:warn: may deadlock if output or error pipes are used and not handled separately.
:raise GitCommandError: if the return status is not 0"""
if stderr is None:
- stderr = b''
- stderr = force_bytes(data=stderr, encoding='utf-8')
+ stderr_b = b''
+ stderr_b = force_bytes(data=stderr, encoding='utf-8')
if self.proc is not None:
status = self.proc.wait()
@@ -437,11 +437,11 @@ class Git(LazyMixin):
def read_all_from_possibly_closed_stream(stream: Union[IO[bytes], None]) -> bytes:
if stream:
try:
- return stderr + force_bytes(stream.read())
+ return stderr_b + force_bytes(stream.read())
except ValueError:
- return stderr or b''
+ return stderr_b or b''
else:
- return stderr or b''
+ return stderr_b or b''
if status != 0:
errstr = read_all_from_possibly_closed_stream(self.proc.stderr)
diff --git a/git/config.py b/git/config.py
index 011d0e0b..3565eece 100644
--- a/git/config.py
+++ b/git/config.py
@@ -33,7 +33,7 @@ import configparser as cp
from typing import (Any, Callable, Generic, IO, List, Dict, Sequence,
TYPE_CHECKING, Tuple, TypeVar, Union, cast, overload)
-from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, TBD, assert_never, _T
+from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, assert_never, _T
if TYPE_CHECKING:
from git.repo.base import Repo
@@ -72,7 +72,7 @@ CONDITIONAL_INCLUDE_REGEXP = re.compile(r"(?<=includeIf )\"(gitdir|gitdir/i|onbr
class MetaParserBuilder(abc.ABCMeta):
"""Utlity class wrapping base-class methods into decorators that assure read-only properties"""
- def __new__(cls, name: str, bases: TBD, clsdict: Dict[str, Any]) -> TBD:
+ def __new__(cls, name: str, bases: Tuple, clsdict: Dict[str, Any]) -> 'MetaParserBuilder':
"""
Equip all base-class methods with a needs_values decorator, and all non-const methods
with a set_dirty_and_flush_changes decorator in addition to that."""
@@ -617,12 +617,12 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
def write_section(name: str, section_dict: _OMD) -> None:
fp.write(("[%s]\n" % name).encode(defenc))
- values: Sequence[Union[str, bytes, int, float, bool]]
+ values: Sequence[str] # runtime only gets str in tests, but should be whatever _OMD stores
+ v: str
for (key, values) in section_dict.items_all():
if key == "__name__":
continue
- v: Union[str, bytes, int, float, bool]
for v in values:
fp.write(("\t%s = %s\n" % (key, self._value_to_string(v).replace('\n', '\n\t'))).encode(defenc))
# END if key is not __name__
@@ -630,7 +630,8 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
if self._defaults:
write_section(cp.DEFAULTSECT, self._defaults)
- value: TBD
+ value: _OMD
+
for name, value in self._sections.items():
write_section(name, value)
diff --git a/git/remote.py b/git/remote.py
index 11007cb6..c141519a 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -37,10 +37,10 @@ from .refs import (
# typing-------------------------------------------------------
-from typing import (Any, Callable, Dict, Iterator, List, NoReturn, Optional, Sequence, # NOQA[TC002]
+from typing import (Any, Callable, Dict, Iterator, List, NoReturn, Optional, Sequence,
TYPE_CHECKING, Type, Union, cast, overload)
-from git.types import PathLike, Literal, TBD, Commit_ish # NOQA[TC002]
+from git.types import PathLike, Literal, Commit_ish
if TYPE_CHECKING:
from git.repo.base import Repo
@@ -50,7 +50,6 @@ if TYPE_CHECKING:
flagKeyLiteral = Literal[' ', '!', '+', '-', '*', '=', 't', '?']
-
# def is_flagKeyLiteral(inp: str) -> TypeGuard[flagKeyLiteral]:
# return inp in [' ', '!', '+', '-', '=', '*', 't', '?']
@@ -707,9 +706,10 @@ class Remote(LazyMixin, IterableObj):
self.repo.git.remote(scmd, self.name, **kwargs)
return self
- def _get_fetch_info_from_stderr(self, proc: TBD,
+ def _get_fetch_info_from_stderr(self, proc: 'Git.AutoInterrupt',
progress: Union[Callable[..., Any], RemoteProgress, None]
) -> IterableList['FetchInfo']:
+
progress = to_progress_instance(progress)
# skip first line as it is some remote info we are not interested in
@@ -768,7 +768,7 @@ class Remote(LazyMixin, IterableObj):
log.warning("Git informed while fetching: %s", err_line.strip())
return output
- def _get_push_info(self, proc: TBD,
+ def _get_push_info(self, proc: 'Git.AutoInterrupt',
progress: Union[Callable[..., Any], RemoteProgress, None]) -> IterableList[PushInfo]:
progress = to_progress_instance(progress)
diff --git a/git/repo/base.py b/git/repo/base.py
index 5581233b..07cf7adf 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -235,7 +235,7 @@ class Repo(object):
def __enter__(self) -> 'Repo':
return self
- def __exit__(self, exc_type: TBD, exc_value: TBD, traceback: TBD) -> None:
+ def __exit__(self, *args: Any) -> None:
self.close()
def __del__(self) -> None:
@@ -445,7 +445,7 @@ class Repo(object):
:return: TagReference object """
return TagReference.create(self, path, ref, message, force, **kwargs)
- def delete_tag(self, *tags: TBD) -> None:
+ def delete_tag(self, *tags: TagReference) -> None:
"""Delete the given tag references"""
return TagReference.delete(self, *tags)
@@ -795,7 +795,7 @@ class Repo(object):
# reveal_type(self.head.reference) # => Reference
return self.head.reference
- def blame_incremental(self, rev: TBD, file: TBD, **kwargs: Any) -> Optional[Iterator['BlameEntry']]:
+ def blame_incremental(self, rev: Union[str, HEAD], file: str, **kwargs: Any) -> Iterator['BlameEntry']:
"""Iterator for blame information for the given file at the given revision.
Unlike .blame(), this does not return the actual file's contents, only
@@ -809,6 +809,7 @@ class Repo(object):
If you combine all line number ranges outputted by this command, you
should get a continuous range spanning all line numbers in the file.
"""
+
data = self.git.blame(rev, '--', file, p=True, incremental=True, stdout_as_string=False, **kwargs)
commits: Dict[str, Commit] = {}
@@ -870,7 +871,7 @@ class Repo(object):
safe_decode(orig_filename),
range(orig_lineno, orig_lineno + num_lines))
- def blame(self, rev: TBD, file: TBD, incremental: bool = False, **kwargs: Any
+ def blame(self, rev: Union[str, HEAD], file: str, incremental: bool = False, **kwargs: Any
) -> Union[List[List[Union[Optional['Commit'], List[str]]]], Optional[Iterator[BlameEntry]]]:
"""The blame information for the given file at the given revision.