Skip to content

Commit 77fb5f0

Browse files
committed
Specify DiffIndex generic type
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]
1 parent 59a0c88 commit 77fb5f0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

git/diff.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def diff(
187187
paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None,
188188
create_patch: bool = False,
189189
**kwargs: Any,
190-
) -> "DiffIndex":
190+
) -> "DiffIndex[Diff]":
191191
"""Create diffs between two items being trees, trees and index or an index and
192192
the working tree. Detects renames automatically.
193193
@@ -581,7 +581,7 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
581581
return None
582582

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

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

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

749749
@classmethod
750-
def _index_from_raw_format(cls, repo: "Repo", proc: "Popen") -> "DiffIndex":
750+
def _index_from_raw_format(cls, repo: "Repo", proc: "Popen") -> "DiffIndex[Diff]":
751751
"""Create a new :class:`DiffIndex` from the given process output which must be
752752
in raw format.
753753

git/index/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ def diff(
14781478
paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None,
14791479
create_patch: bool = False,
14801480
**kwargs: Any,
1481-
) -> git_diff.DiffIndex:
1481+
) -> git_diff.DiffIndex[git_diff.Diff]:
14821482
"""Diff this index against the working copy or a :class:`~git.objects.tree.Tree`
14831483
or :class:`~git.objects.commit.Commit` object.
14841484

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy