15
15
16
16
# typing ------------------------------------------------------------------
17
17
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
20
20
21
21
if TYPE_CHECKING :
22
22
from .objects .tree import Tree
23
23
from git .repo .base import Repo
24
24
25
25
from subprocess import Popen
26
26
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' ]
32
28
33
29
# ------------------------------------------------------------------------
34
30
35
-
36
31
__all__ = ('Diffable' , 'DiffIndex' , 'Diff' , 'NULL_TREE' )
37
32
38
33
# 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']:
205
200
if change_type not in self .change_type :
206
201
raise ValueError ("Invalid change type: %s" % change_type )
207
202
208
- # diff: 'Diff'
209
203
for diff in self :
204
+ diff = cast ('Diff' , diff )
210
205
if diff .change_type == change_type :
211
206
yield diff
212
207
elif change_type == "A" and diff .new_file :
@@ -287,8 +282,7 @@ def __init__(self, repo: 'Repo',
287
282
a_mode : Union [bytes , str , None ], b_mode : Union [bytes , str , None ],
288
283
new_file : bool , deleted_file : bool , copied_file : bool ,
289
284
raw_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 :
292
286
293
287
assert a_rawpath is None or isinstance (a_rawpath , bytes )
294
288
assert 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
505
499
for line in lines .split (':' )[1 :]:
506
500
meta , _ , path = line .partition ('\x00 ' )
507
501
path = 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 ]
510
504
old_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
512
506
# R: status letter
513
507
# 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
517
509
score_str = '' .join (_change_type [1 :])
518
510
score = int (score_str ) if score_str .isdigit () else None
519
511
path = path .strip ()
@@ -528,7 +520,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
528
520
# NOTE: We cannot conclude from the existence of a blob to change type
529
521
# as diffs with the working do not have blobs yet
530
522
if change_type == 'D' :
531
- b_blob_id = None
523
+ b_blob_id = None # Optional[str]
532
524
deleted_file = True
533
525
elif change_type == 'A' :
534
526
a_blob_id = None
0 commit comments