summaryrefslogtreecommitdiff
path: root/git/diff.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/diff.py')
-rw-r--r--git/diff.py28
1 files changed, 10 insertions, 18 deletions
diff --git a/git/diff.py b/git/diff.py
index ac744999..879d5b55 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -15,8 +15,8 @@ from .objects.util import mode_str_to_int
# typing ------------------------------------------------------------------
-from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING
-from git.types import PathLike, TBD, Literal, TypeGuard
+from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING, cast
+from git.types import PathLike, TBD, Literal
if TYPE_CHECKING:
from .objects.tree import Tree
@@ -24,15 +24,10 @@ if TYPE_CHECKING:
from subprocess import Popen
-Lit_change_type = Literal['A', 'C', 'D', 'M', 'R', 'T']
-
-
-def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
- return inp in ('A', 'D', 'C', 'M', 'R', 'T')
+Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T']
# ------------------------------------------------------------------------
-
__all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE')
# Special object to compare against the empty tree in diffs
@@ -205,8 +200,8 @@ class DiffIndex(list):
if change_type not in self.change_type:
raise ValueError("Invalid change type: %s" % change_type)
- # diff: 'Diff'
for diff in self:
+ diff = cast('Diff', diff)
if diff.change_type == change_type:
yield diff
elif change_type == "A" and diff.new_file:
@@ -287,8 +282,7 @@ class Diff(object):
a_mode: Union[bytes, str, None], b_mode: Union[bytes, str, None],
new_file: bool, deleted_file: bool, copied_file: bool,
raw_rename_from: Optional[bytes], raw_rename_to: Optional[bytes],
- diff: Union[str, bytes, None], change_type: Union[Lit_change_type, None],
- score: Optional[int]) -> None:
+ diff: Union[str, bytes, None], change_type: Optional[str], score: Optional[int]) -> None:
assert a_rawpath is None or isinstance(a_rawpath, bytes)
assert b_rawpath is None or isinstance(b_rawpath, bytes)
@@ -505,15 +499,13 @@ class Diff(object):
for line in lines.split(':')[1:]:
meta, _, path = line.partition('\x00')
path = path.rstrip('\x00')
- a_blob_id: Union[str, None]
- b_blob_id: Union[str, None]
+ a_blob_id: Optional[str]
+ b_blob_id: Optional[str]
old_mode, new_mode, a_blob_id, b_blob_id, _change_type = meta.split(None, 4)
- # _Change_type can be R100
+ # Change type can be R100
# R: status letter
# 100: score (in case of copy and rename)
-
- assert is_change_type(_change_type[0]), "Unexpected _change_type recieved in Diff"
- change_type: Lit_change_type = _change_type[0]
+ change_type: Lit_change_type = _change_type[0] # type: ignore
score_str = ''.join(_change_type[1:])
score = int(score_str) if score_str.isdigit() else None
path = path.strip()
@@ -528,7 +520,7 @@ class Diff(object):
# NOTE: We cannot conclude from the existence of a blob to change type
# as diffs with the working do not have blobs yet
if change_type == 'D':
- b_blob_id = None
+ b_blob_id = None # Optional[str]
deleted_file = True
elif change_type == 'A':
a_blob_id = None