Skip to content

Commit 215abfd

Browse files
committed
Readd typeguard to Diff.py
1 parent 1eceb89 commit 215abfd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

git/diff.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# typing ------------------------------------------------------------------
1717

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

2121
if TYPE_CHECKING:
2222
from .objects.tree import Tree
@@ -26,8 +26,13 @@
2626

2727
Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T']
2828

29+
30+
def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
31+
return inp in ['A', 'D', 'C', 'M', 'R', 'T']
32+
2933
# ------------------------------------------------------------------------
3034

35+
3136
__all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE')
3237

3338
# Special object to compare against the empty tree in diffs
@@ -202,6 +207,7 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator['Diff']:
202207

203208
for diff in self:
204209
diff = cast('Diff', diff)
210+
205211
if diff.change_type == change_type:
206212
yield diff
207213
elif change_type == "A" and diff.new_file:
@@ -505,7 +511,8 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
505511
# Change type can be R100
506512
# R: status letter
507513
# 100: score (in case of copy and rename)
508-
change_type: Lit_change_type = _change_type[0] # type: ignore
514+
assert is_change_type(_change_type[0])
515+
change_type: Lit_change_type = _change_type[0]
509516
score_str = ''.join(_change_type[1:])
510517
score = int(score_str) if score_str.isdigit() else None
511518
path = path.strip()

0 commit comments

Comments
 (0)