16
16
# typing ------------------------------------------------------------------
17
17
18
18
from typing import Any , Iterator , List , Match , Optional , Tuple , Type , TypeVar , Union , TYPE_CHECKING
19
- from git .types import Has_Repo , PathLike , TBD , Literal , TypeGuard
19
+ from git .types import PathLike , TBD , Literal , TypeGuard
20
20
21
21
if TYPE_CHECKING :
22
22
from .objects .tree import Tree
23
23
from git .repo .base import Repo
24
24
from git .objects .base import IndexObject
25
-
26
25
from subprocess import Popen
27
26
28
27
Lit_change_type = Literal ['A' , 'D' , 'C' , 'M' , 'R' , 'T' , 'U' ]
@@ -82,15 +81,16 @@ class Diffable(object):
82
81
class Index (object ):
83
82
pass
84
83
85
- def _process_diff_args (self , args : List [Union [str , 'Diffable' , object ]]) -> List [Union [str , 'Diffable' , object ]]:
84
+ def _process_diff_args (self , args : List [Union [PathLike , 'Diffable' , Type ['Diffable.Index' ]]]
85
+ ) -> List [Union [PathLike , 'Diffable' , Type ['Diffable.Index' ]]]:
86
86
"""
87
87
:return:
88
88
possibly altered version of the given args list.
89
89
Method is called right before git command execution.
90
90
Subclasses can use it to alter the behaviour of the superclass"""
91
91
return args
92
92
93
- def diff (self , other : Union [Type [Index ], Type [ 'Tree' ], object , None , str ] = Index ,
93
+ def diff (self , other : Union [Type [' Index' ], 'Tree' , None , str ] = Index ,
94
94
paths : Union [PathLike , List [PathLike ], Tuple [PathLike , ...], None ] = None ,
95
95
create_patch : bool = False , ** kwargs : Any ) -> 'DiffIndex' :
96
96
"""Creates diffs between two items being trees, trees and index or an
@@ -123,7 +123,7 @@ def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Inde
123
123
:note:
124
124
On a bare repository, 'other' needs to be provided as Index or as
125
125
as Tree/Commit, or a git command error will occur"""
126
- args = [] # type : List[Union[str , Diffable, object] ]
126
+ args : List [Union [PathLike , Diffable , Type [ 'Diffable.Index' ]]] = [ ]
127
127
args .append ("--abbrev=40" ) # we need full shas
128
128
args .append ("--full-index" ) # get full index paths, not only filenames
129
129
@@ -141,7 +141,7 @@ def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Inde
141
141
if paths is not None and not isinstance (paths , (tuple , list )):
142
142
paths = [paths ]
143
143
144
- if isinstance (self , Has_Repo ):
144
+ if hasattr (self , ' Has_Repo' ):
145
145
self .repo : Repo = self .repo
146
146
else :
147
147
raise AttributeError ("No repo member found, cannot create DiffIndex" )
@@ -400,36 +400,36 @@ def __str__(self) -> str:
400
400
# end
401
401
return res
402
402
403
- @property
403
+ @ property
404
404
def a_path (self ) -> Optional [str ]:
405
405
return self .a_rawpath .decode (defenc , 'replace' ) if self .a_rawpath else None
406
406
407
- @property
407
+ @ property
408
408
def b_path (self ) -> Optional [str ]:
409
409
return self .b_rawpath .decode (defenc , 'replace' ) if self .b_rawpath else None
410
410
411
- @property
411
+ @ property
412
412
def rename_from (self ) -> Optional [str ]:
413
413
return self .raw_rename_from .decode (defenc , 'replace' ) if self .raw_rename_from else None
414
414
415
- @property
415
+ @ property
416
416
def rename_to (self ) -> Optional [str ]:
417
417
return self .raw_rename_to .decode (defenc , 'replace' ) if self .raw_rename_to else None
418
418
419
- @property
419
+ @ property
420
420
def renamed (self ) -> bool :
421
421
""":returns: True if the blob of our diff has been renamed
422
422
:note: This property is deprecated, please use ``renamed_file`` instead.
423
423
"""
424
424
return self .renamed_file
425
425
426
- @property
426
+ @ property
427
427
def renamed_file (self ) -> bool :
428
428
""":returns: True if the blob of our diff has been renamed
429
429
"""
430
430
return self .rename_from != self .rename_to
431
431
432
- @classmethod
432
+ @ classmethod
433
433
def _pick_best_path (cls , path_match : bytes , rename_match : bytes , path_fallback_match : bytes ) -> Optional [bytes ]:
434
434
if path_match :
435
435
return decode_path (path_match )
@@ -442,7 +442,7 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
442
442
443
443
return None
444
444
445
- @classmethod
445
+ @ classmethod
446
446
def _index_from_patch_format (cls , repo : 'Repo' , proc : TBD ) -> DiffIndex :
447
447
"""Create a new DiffIndex from the given text which must be in patch format
448
448
:param repo: is the repository we are operating on - it is required
@@ -505,7 +505,7 @@ def _index_from_patch_format(cls, repo: 'Repo', proc: TBD) -> DiffIndex:
505
505
506
506
return index
507
507
508
- @staticmethod
508
+ @ staticmethod
509
509
def _handle_diff_line (lines_bytes : bytes , repo : 'Repo' , index : DiffIndex ) -> None :
510
510
lines = lines_bytes .decode (defenc )
511
511
@@ -559,7 +559,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
559
559
'' , change_type , score )
560
560
index .append (diff )
561
561
562
- @classmethod
562
+ @ classmethod
563
563
def _index_from_raw_format (cls , repo : 'Repo' , proc : 'Popen' ) -> 'DiffIndex' :
564
564
"""Create a new DiffIndex from the given stream which must be in raw format.
565
565
:return: git.DiffIndex"""
0 commit comments