Skip to content

Commit 39d37d5

Browse files
committed
replace some TBDs wiht runtime types
1 parent 2a350b5 commit 39d37d5

File tree

8 files changed

+19
-33
lines changed

8 files changed

+19
-33
lines changed

‎git/cmd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# Documentation
6969
## @{
7070

71-
def handle_process_output(process: subprocess.Popen,
71+
def handle_process_output(process: Union[subprocess.Popen, 'Git.AutoInterrupt'],
7272
stdout_handler: Union[None,
7373
Callable[[AnyStr], None],
7474
Callable[[List[AnyStr]], None],
@@ -77,7 +77,7 @@ def handle_process_output(process: subprocess.Popen,
7777
Callable[[AnyStr], None],
7878
Callable[[List[AnyStr]], None]],
7979
finalizer: Union[None,
80-
Callable[[subprocess.Popen], None]] = None,
80+
Callable[[Union[subprocess.Popen, 'Git.AutoInterrupt']], None]] = None,
8181
decode_streams: bool = True) -> None:
8282
"""Registers for notifications to learn that process output is ready to read, and dispatches lines to
8383
the respective line handlers.

‎git/compat.py

-18
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
Union,
3030
overload,
3131
)
32-
from git.types import TBD
33-
3432
# ---------------------------------------------------------------------------
3533

3634

@@ -97,19 +95,3 @@ def win_encode(s: Optional[AnyStr]) -> Optional[bytes]:
9795
elif s is not None:
9896
raise TypeError('Expected bytes or text, but got %r' % (s,))
9997
return None
100-
101-
102-
# type: ignore ## mypy cannot understand dynamic class creation
103-
def with_metaclass(meta: Type[Any], *bases: Any) -> TBD:
104-
"""copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15"""
105-
106-
class metaclass(meta): # type: ignore
107-
__call__ = type.__call__
108-
__init__ = type.__init__ # type: ignore
109-
110-
def __new__(cls, name: str, nbases: Optional[Tuple[int, ...]], d: Dict[str, Any]) -> TBD:
111-
if nbases is None:
112-
return type.__new__(cls, name, (), d)
113-
return meta(name, bases, d)
114-
115-
return metaclass(meta.__name__ + 'Helper', None, {}) # type: ignore

‎git/diff.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
# typing ------------------------------------------------------------------
1717

1818
from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING, cast
19-
from git.types import PathLike, TBD, Literal
19+
from git.types import PathLike, Literal
2020

2121
if TYPE_CHECKING:
2222
from .objects.tree import Tree
2323
from .objects import Commit
2424
from git.repo.base import Repo
2525
from git.objects.base import IndexObject
2626
from subprocess import Popen
27+
from git import Git
2728

2829
Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T', 'U']
2930

@@ -442,7 +443,7 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
442443
return None
443444

444445
@ classmethod
445-
def _index_from_patch_format(cls, repo: 'Repo', proc: TBD) -> DiffIndex:
446+
def _index_from_patch_format(cls, repo: 'Repo', proc: Union['Popen', 'Git.AutoInterrupt']) -> DiffIndex:
446447
"""Create a new DiffIndex from the given text which must be in patch format
447448
:param repo: is the repository we are operating on - it is required
448449
:param stream: result of 'git diff' as a stream (supporting file protocol)

‎git/index/base.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List, NoReturn,
7171
Sequence, TYPE_CHECKING, Tuple, Type, Union)
7272

73-
from git.types import Commit_ish, PathLike, TBD
73+
from git.types import Commit_ish, PathLike
7474

7575
if TYPE_CHECKING:
7676
from subprocess import Popen
@@ -181,7 +181,7 @@ def _deserialize(self, stream: IO) -> 'IndexFile':
181181
self.version, self.entries, self._extension_data, _conten_sha = read_cache(stream)
182182
return self
183183

184-
def _entries_sorted(self) -> List[TBD]:
184+
def _entries_sorted(self) -> List[IndexEntry]:
185185
""":return: list of entries, in a sorted fashion, first by path, then by stage"""
186186
return sorted(self.entries.values(), key=lambda e: (e.path, e.stage))
187187

@@ -427,8 +427,8 @@ def raise_exc(e: Exception) -> NoReturn:
427427
# END path exception handling
428428
# END for each path
429429

430-
def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item: TBD, fmakeexc: Callable[..., GitError],
431-
fprogress: Callable[[PathLike, bool, TBD], None],
430+
def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item: PathLike, fmakeexc: Callable[..., GitError],
431+
fprogress: Callable[[PathLike, bool, PathLike], None],
432432
read_from_stdout: bool = True) -> Union[None, str]:
433433
"""Write path to proc.stdin and make sure it processes the item, including progress.
434434
@@ -492,12 +492,13 @@ def unmerged_blobs(self) -> Dict[PathLike, List[Tuple[StageType, Blob]]]:
492492
are at stage 3 will not have a stage 3 entry.
493493
"""
494494
is_unmerged_blob = lambda t: t[0] != 0
495-
path_map: Dict[PathLike, List[Tuple[TBD, Blob]]] = {}
495+
path_map: Dict[PathLike, List[Tuple[StageType, Blob]]] = {}
496496
for stage, blob in self.iter_blobs(is_unmerged_blob):
497497
path_map.setdefault(blob.path, []).append((stage, blob))
498498
# END for each unmerged blob
499499
for line in path_map.values():
500500
line.sort()
501+
501502
return path_map
502503

503504
@ classmethod

‎git/objects/submodule/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
379379
:return: The newly created submodule instance
380380
:note: works atomically, such that no change will be done if the repository
381381
update fails for instance"""
382+
382383
if repo.bare:
383384
raise InvalidGitRepositoryError("Cannot add submodules to bare repositories")
384385
# END handle bare repos
@@ -434,7 +435,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
434435
url = urls[0]
435436
else:
436437
# clone new repo
437-
kwargs: Dict[str, Union[bool, int, Sequence[TBD]]] = {'n': no_checkout}
438+
kwargs: Dict[str, Union[bool, int, str, Sequence[TBD]]] = {'n': no_checkout}
438439
if not branch_is_default:
439440
kwargs['b'] = br.name
440441
# END setup checkout-branch

‎git/refs/reference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# typing ------------------------------------------------------------------
99

1010
from typing import Any, Callable, Iterator, Type, Union, TYPE_CHECKING # NOQA
11-
from git.types import Commit_ish, PathLike, TBD, Literal, _T # NOQA
11+
from git.types import Commit_ish, PathLike, _T # NOQA
1212

1313
if TYPE_CHECKING:
1414
from git.repo import Repo

‎git/refs/symbolic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
# typing ------------------------------------------------------------------
2323

24-
from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING, cast # NOQA
25-
from git.types import Commit_ish, PathLike, TBD, Literal # NOQA
24+
from typing import Any, Iterator, List, Tuple, Type, TypeVar, Union, TYPE_CHECKING, cast # NOQA
25+
from git.types import Commit_ish, PathLike # NOQA
2626

2727
if TYPE_CHECKING:
2828
from git.repo import Repo

‎git/util.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from git.remote import Remote
3939
from git.repo.base import Repo
4040
from git.config import GitConfigParser, SectionConstraint
41+
from git import Git
4142
# from git.objects.base import IndexObject
4243

4344

@@ -379,7 +380,7 @@ def get_user_id() -> str:
379380
return "%s@%s" % (getpass.getuser(), platform.node())
380381

381382

382-
def finalize_process(proc: subprocess.Popen, **kwargs: Any) -> None:
383+
def finalize_process(proc: Union[subprocess.Popen, 'Git.AutoInterrupt'], **kwargs: Any) -> None:
383384
"""Wait for the process (clone, fetch, pull or push) and handle its errors accordingly"""
384385
# TODO: No close proc-streams??
385386
proc.wait(**kwargs)
@@ -1033,7 +1034,7 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:
10331034

10341035
class IterableClassWatcher(type):
10351036
""" Metaclass that watches """
1036-
def __init__(cls, name: str, bases: List, clsdict: Dict) -> None:
1037+
def __init__(cls, name: str, bases: Tuple, clsdict: Dict) -> None:
10371038
for base in bases:
10381039
if type(base) == IterableClassWatcher:
10391040
warnings.warn(f"GitPython Iterable subclassed by {name}. "

0 commit comments

Comments
 (0)