review · gitpython-developers/GitPython@be1f168 · GitHub
Skip to content

Commit be1f168

Browse files
Byroncodex
andcommitted
review
- also fixup typing Assisted-by: GPT 6.0 Co-authored-by: GPT 6.0 <codex@openai.com>
1 parent fa93137 commit be1f168

20 files changed

Lines changed: 772 additions & 1049 deletions

File tree

.basedpyright/baseline.json

Lines changed: 500 additions & 964 deletions
Large diffs are not rendered by default.

git/cmd.py

Lines changed: 86 additions & 26 deletions

git/index/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ def _read_commit_editmsg(self) -> str:
12351235
def _commit_editmsg_filepath(self) -> str:
12361236
return osp.join(self.repo.common_dir, "COMMIT_EDITMSG")
12371237

1238-
def _flush_stdin_and_wait(cls, proc: "Popen[bytes]", ignore_stdout: bool = False) -> bytes:
1238+
def _flush_stdin_and_wait(self, proc: "Popen[bytes]", ignore_stdout: bool = False) -> bytes:
12391239
stdin_IO = proc.stdin
12401240
if stdin_IO:
12411241
stdin_IO.flush()

git/index/fun.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from git.types import PathLike
4747

4848
if TYPE_CHECKING:
49-
from git.db import GitCmdObjectDB
49+
from gitdb.db.base import ObjectDBR, ObjectDBW
5050
from git.objects.tree import TreeCacheTup
5151

5252
from .base import IndexFile
@@ -412,7 +412,7 @@ def read_cache(
412412

413413

414414
def write_tree_from_cache(
415-
entries: List[IndexEntry], odb: "GitCmdObjectDB", sl: slice, si: int = 0
415+
entries: List[IndexEntry], odb: "ObjectDBW", sl: slice, si: int = 0
416416
) -> Tuple[bytes, List["TreeCacheTup"]]:
417417
R"""Create a tree from the given sorted list of entries and put the respective
418418
trees into the given object database.
@@ -484,7 +484,7 @@ def _tree_entry_to_baseindexentry(tree_entry: "TreeCacheTup", stage: int) -> Bas
484484
return BaseIndexEntry((tree_entry[1], tree_entry[0], stage << CE_STAGESHIFT, tree_entry[2]))
485485

486486

487-
def aggressive_tree_merge(odb: "GitCmdObjectDB", tree_shas: Sequence[bytes]) -> List[BaseIndexEntry]:
487+
def aggressive_tree_merge(odb: "ObjectDBR", tree_shas: Sequence[bytes]) -> List[BaseIndexEntry]:
488488
R"""
489489
:return:
490490
List of :class:`~git.index.typ.BaseIndexEntry`\s representing the aggressive

git/index/typ.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
from pathlib import Path
1010

1111
from git.objects import Blob
12+
from git.objects.base import IndexObject
1213

1314
from .util import pack, unpack
1415

1516
# typing ----------------------------------------------------------------------
1617

17-
from typing import NamedTuple, Sequence, TYPE_CHECKING, Tuple, Union, cast
18+
from typing import NamedTuple, Sequence, TYPE_CHECKING, Tuple, Type, TypeVar, Union, cast
1819

1920
from git.types import PathLike
2021

2122
if TYPE_CHECKING:
2223
from git.repo import Repo
2324

2425
StageType = int
26+
_T_IndexEntry = TypeVar("_T_IndexEntry", bound="BaseIndexEntry")
2527

2628
# ---------------------------------------------------------------------------------
2729

@@ -104,15 +106,20 @@ class BaseIndexEntry(BaseIndexEntryHelper):
104106
"""
105107

106108
def __new__(
107-
cls,
109+
cls: Type[_T_IndexEntry],
108110
inp_tuple: Union[
109111
Tuple[int, bytes, int, PathLike],
112+
Tuple[int, bytes, int, PathLike, bytes, bytes, int, int, int, int, int],
110113
Tuple[int, bytes, int, PathLike, bytes, bytes, int, int, int, int, int, int],
111114
],
112-
) -> "BaseIndexEntry":
115+
) -> _T_IndexEntry:
113116
"""Override ``__new__`` to allow construction from a tuple for backwards
114117
compatibility."""
115-
return super().__new__(cls, *inp_tuple)
118+
if len(inp_tuple) == 4:
119+
return BaseIndexEntryHelper.__new__(cls, *inp_tuple)
120+
if len(inp_tuple) == 11:
121+
return BaseIndexEntryHelper.__new__(cls, *inp_tuple)
122+
return BaseIndexEntryHelper.__new__(cls, *inp_tuple)
116123

117124
def __str__(self) -> str:
118125
return "%o %s %i\t%s" % (self.mode, self.hexsha, self.stage, self.path)
@@ -148,7 +155,7 @@ def intent_to_add(self) -> bool:
148155
return (self.extended_flags & CE_EXT_INTENT_TO_ADD) > 0
149156

150157
@classmethod
151-
def from_blob(cls, blob: Blob, stage: int = 0) -> "BaseIndexEntry":
158+
def from_blob(cls, blob: IndexObject, stage: int = 0) -> "BaseIndexEntry":
152159
""":return: Fully equipped BaseIndexEntry at the given stage"""
153160
return cls((blob.mode, blob.binsha, stage << CE_STAGESHIFT, blob.path))
154161

@@ -192,10 +199,10 @@ def from_base(cls, base: "BaseIndexEntry") -> "IndexEntry":
192199
Instance of type :class:`BaseIndexEntry`.
193200
"""
194201
time = pack(">LL", 0, 0)
195-
return IndexEntry((base.mode, base.binsha, base.flags, base.path, time, time, 0, 0, 0, 0, 0)) # type: ignore[arg-type]
202+
return IndexEntry((base.mode, base.binsha, base.flags, base.path, time, time, 0, 0, 0, 0, 0))
196203

197204
@classmethod
198-
def from_blob(cls, blob: Blob, stage: int = 0) -> "IndexEntry":
205+
def from_blob(cls, blob: IndexObject, stage: int = 0) -> "IndexEntry":
199206
""":return: Minimal entry resembling the given blob object"""
200207
time = pack(">LL", 0, 0)
201208
return IndexEntry(
@@ -211,5 +218,5 @@ def from_blob(cls, blob: Blob, stage: int = 0) -> "IndexEntry":
211218
0,
212219
0,
213220
blob.size,
214-
) # type: ignore[arg-type]
221+
)
215222
)

git/objects/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from typing import Any, TYPE_CHECKING, Union
2020

21-
from git.types import AnyGitObject, GitObjectTypeString, PathLike
21+
from git.types import AnyGitObject, GitObjectTypeString, PathLike, SupportsWrite
2222

2323
if TYPE_CHECKING:
2424
from gitdb.base import OStream
@@ -200,7 +200,7 @@ def data_stream(self) -> "OStream":
200200
"""
201201
return self.repo.odb.stream(self.binsha)
202202

203-
def stream_data(self, ostream: "OStream") -> "Object":
203+
def stream_data(self, ostream: SupportsWrite[bytes]) -> "Object":
204204
"""Write our data directly to the given output stream.
205205
206206
:param ostream:

git/objects/commit.py

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)