|
16 | 16 | # typing ------------------------------------------------------------------ |
17 | 17 |
|
18 | 18 | fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,Union,TYPE_CHECKING,cast |
19 | | -fromgit.typesimportPathLike,TBD,Literal |
| 19 | +fromgit.typesimportPathLike,TBD,Literal,TypeGuard |
20 | 20 |
|
21 | 21 | ifTYPE_CHECKING: |
22 | 22 | from .objects.treeimportTree |
|
26 | 26 |
|
27 | 27 | Lit_change_type=Literal['A','D','C','M','R','T'] |
28 | 28 |
|
| 29 | + |
| 30 | +defis_change_type(inp:str)->TypeGuard[Lit_change_type]: |
| 31 | +returninpin ['A','D','C','M','R','T'] |
| 32 | + |
29 | 33 | # ------------------------------------------------------------------------ |
30 | 34 |
|
| 35 | + |
31 | 36 | __all__= ('Diffable','DiffIndex','Diff','NULL_TREE') |
32 | 37 |
|
33 | 38 | # 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']: |
202 | 207 |
|
203 | 208 | fordiffinself: |
204 | 209 | diff=cast('Diff',diff) |
| 210 | + |
205 | 211 | ifdiff.change_type==change_type: |
206 | 212 | yielddiff |
207 | 213 | elifchange_type=="A"anddiff.new_file: |
@@ -505,7 +511,8 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non |
505 | 511 | # Change type can be R100 |
506 | 512 | # R: status letter |
507 | 513 | # 100: score (in case of copy and rename) |
508 | | -change_type:Lit_change_type=_change_type[0]# type: ignore |
| 514 | +assertis_change_type(_change_type[0]) |
| 515 | +change_type:Lit_change_type=_change_type[0] |
509 | 516 | score_str=''.join(_change_type[1:]) |
510 | 517 | score=int(score_str)ifscore_str.isdigit()elseNone |
511 | 518 | path=path.strip() |
|