Skip to content

Commit

Permalink
Specify DiffIndex generic type
Browse files Browse the repository at this point in the history
Example before this commit:

repo = git.Repo(path_dir)
diff = repo.index.diff(None)
modified_files = [d for d in repo.index.diff(None)]
reveal_type(modified_files) # list[Unknown] instead of list[Diff]
  • Loading branch information
Andrej730 committed Jun 2, 2024
1 parent 59a0c88 commit 77fb5f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def diff(
paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None,
create_patch: bool = False,
**kwargs: Any,
) -> "DiffIndex":
) -> "DiffIndex[Diff]":
"""Create diffs between two items being trees, trees and index or an index and
the working tree. Detects renames automatically.
Expand Down Expand Up @@ -581,7 +581,7 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
return None

@classmethod
def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoInterrupt"]) -> DiffIndex:
def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoInterrupt"]) -> DiffIndex["Diff"]:
"""Create a new :class:`DiffIndex` from the given process output which must be
in patch format.
Expand Down Expand Up @@ -674,7 +674,7 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn
return index

@staticmethod
def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> None:
def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex["Diff"]) -> None:
lines = lines_bytes.decode(defenc)

# Discard everything before the first colon, and the colon itself.
Expand Down Expand Up @@ -747,7 +747,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non
index.append(diff)

@classmethod
def _index_from_raw_format(cls, repo: "Repo", proc: "Popen") -> "DiffIndex":
def _index_from_raw_format(cls, repo: "Repo", proc: "Popen") -> "DiffIndex[Diff]":
"""Create a new :class:`DiffIndex` from the given process output which must be
in raw format.
Expand Down
2 changes: 1 addition & 1 deletion git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ def diff(
paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None,
create_patch: bool = False,
**kwargs: Any,
) -> git_diff.DiffIndex:
) -> git_diff.DiffIndex[git_diff.Diff]:
"""Diff this index against the working copy or a :class:`~git.objects.tree.Tree`
or :class:`~git.objects.commit.Commit` object.
Expand Down

0 comments on commit 77fb5f0

Please sign in to comment.