summaryrefslogtreecommitdiff
path: root/git/diff.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-07-06 16:36:16 +0100
committerYobmod <yobmod@gmail.com>2021-07-06 16:36:16 +0100
commit215abfda39c34aa125f9405d9bb848eb45ee7ac6 (patch)
treefbd3b8a5c3dc15fac7facede8a13df94570a289d /git/diff.py
parent1eceb8938ec98fad3a3aa2b8ffae5be8b7653976 (diff)
downloadgitpython-215abfda39c34aa125f9405d9bb848eb45ee7ac6.tar.gz
Readd typeguard to Diff.py
Diffstat (limited to 'git/diff.py')
-rw-r--r--git/diff.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/git/diff.py b/git/diff.py
index 879d5b55..a90b7758 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -16,7 +16,7 @@ from .objects.util import mode_str_to_int
# typing ------------------------------------------------------------------
from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING, cast
-from git.types import PathLike, TBD, Literal
+from git.types import PathLike, TBD, Literal, TypeGuard
if TYPE_CHECKING:
from .objects.tree import Tree
@@ -26,8 +26,13 @@ if TYPE_CHECKING:
Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T']
+
+def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
+ return inp in ['A', 'D', 'C', 'M', 'R', 'T']
+
# ------------------------------------------------------------------------
+
__all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE')
# Special object to compare against the empty tree in diffs
@@ -202,6 +207,7 @@ class DiffIndex(list):
for diff in self:
diff = cast('Diff', diff)
+
if diff.change_type == change_type:
yield diff
elif change_type == "A" and diff.new_file:
@@ -505,7 +511,8 @@ class Diff(object):
# Change type can be R100
# R: status letter
# 100: score (in case of copy and rename)
- change_type: Lit_change_type = _change_type[0] # type: ignore
+ assert is_change_type(_change_type[0])
+ change_type: Lit_change_type = _change_type[0]
score_str = ''.join(_change_type[1:])
score = int(score_str) if score_str.isdigit() else None
path = path.strip()