1515
1616# typing ------------------------------------------------------------------
1717
18- from typing import Any ,Iterator ,List ,Match ,Optional ,Tuple ,Type ,Union ,TYPE_CHECKING
19- from git .types import PathLike ,TBD ,Literal , TypeGuard
18+ from typing import Any ,Iterator ,List ,Match ,Optional ,Tuple ,Type ,Union ,TYPE_CHECKING , cast
19+ from git .types import PathLike ,TBD ,Literal
2020
2121if TYPE_CHECKING :
2222from .objects .tree import Tree
2323from git .repo .base import Repo
2424
2525from subprocess import Popen
2626
27- Lit_change_type = Literal ['A' ,'C' ,'D' ,'M' ,'R' ,'T' ]
28-
29-
30- def is_change_type (inp :str )-> TypeGuard [Lit_change_type ]:
31- return inp in ('A' ,'D' ,'C' ,'M' ,'R' ,'T' )
27+ Lit_change_type = Literal ['A' ,'D' ,'C' ,'M' ,'R' ,'T' ]
3228
3329# ------------------------------------------------------------------------
3430
35-
3631__all__ = ('Diffable' ,'DiffIndex' ,'Diff' ,'NULL_TREE' )
3732
3833# Special object to compare against the empty tree in diffs
@@ -205,8 +200,8 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator['Diff']:
205200if change_type not in self .change_type :
206201raise ValueError ("Invalid change type: %s" % change_type )
207202
208- # diff: 'Diff'
209203for diff in self :
204+ diff = cast ('Diff' ,diff )
210205if diff .change_type == change_type :
211206yield diff
212207elif change_type == "A" and diff .new_file :
@@ -287,8 +282,7 @@ def __init__(self, repo: 'Repo',
287282a_mode :Union [bytes ,str ,None ],b_mode :Union [bytes ,str ,None ],
288283new_file :bool ,deleted_file :bool ,copied_file :bool ,
289284raw_rename_from :Optional [bytes ],raw_rename_to :Optional [bytes ],
290- diff :Union [str ,bytes ,None ],change_type :Union [Lit_change_type ,None ],
291- score :Optional [int ])-> None :
285+ diff :Union [str ,bytes ,None ],change_type :Optional [str ],score :Optional [int ])-> None :
292286
293287assert a_rawpath is None or isinstance (a_rawpath ,bytes )
294288assert b_rawpath is None or isinstance (b_rawpath ,bytes )
@@ -505,15 +499,13 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
505499for line in lines .split (':' )[1 :]:
506500meta ,_ ,path = line .partition ('\x00 ' )
507501path = path .rstrip ('\x00 ' )
508- a_blob_id :Union [str , None ]
509- b_blob_id :Union [str , None ]
502+ a_blob_id :Optional [str ]
503+ b_blob_id :Optional [str ]
510504old_mode ,new_mode ,a_blob_id ,b_blob_id ,_change_type = meta .split (None ,4 )
511- #_Change_type can be R100
505+ #Change type can be R100
512506# R: status letter
513507# 100: score (in case of copy and rename)
514-
515- assert is_change_type (_change_type [0 ]),"Unexpected _change_type recieved in Diff"
516- change_type :Lit_change_type = _change_type [0 ]
508+ change_type :Lit_change_type = _change_type [0 ]# type: ignore
517509score_str = '' .join (_change_type [1 :])
518510score = int (score_str )if score_str .isdigit ()else None
519511path = path .strip ()
@@ -528,7 +520,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
528520# NOTE: We cannot conclude from the existence of a blob to change type
529521# as diffs with the working do not have blobs yet
530522if change_type == 'D' :
531- b_blob_id = None
523+ b_blob_id = None # Optional[str]
532524deleted_file = True
533525elif change_type == 'A' :
534526a_blob_id = None