1616# typing ------------------------------------------------------------------
1717
1818from 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
2020
2121if TYPE_CHECKING :
2222 from .objects .tree import Tree
2323 from git .repo .base import Repo
2424 from git .objects .base import IndexObject
25-
2625 from subprocess import Popen
2726
2827Lit_change_type = Literal ['A' , 'D' , 'C' , 'M' , 'R' , 'T' , 'U' ]
@@ -82,15 +81,16 @@ class Diffable(object):
8281 class Index (object ):
8382 pass
8483
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' ]]]:
8686 """
8787 :return:
8888 possibly altered version of the given args list.
8989 Method is called right before git command execution.
9090 Subclasses can use it to alter the behaviour of the superclass"""
9191 return args
9292
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 ,
9494 paths : Union [PathLike , List [PathLike ], Tuple [PathLike , ...], None ] = None ,
9595 create_patch : bool = False , ** kwargs : Any ) -> 'DiffIndex' :
9696 """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
123123 :note:
124124 On a bare repository, 'other' needs to be provided as Index or as
125125 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' ]]] = [ ]
127127 args .append ("--abbrev=40" ) # we need full shas
128128 args .append ("--full-index" ) # get full index paths, not only filenames
129129
@@ -141,7 +141,7 @@ def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Inde
141141 if paths is not None and not isinstance (paths , (tuple , list )):
142142 paths = [paths ]
143143
144- if isinstance (self , Has_Repo ):
144+ if hasattr (self , ' Has_Repo' ):
145145 self .repo : Repo = self .repo
146146 else :
147147 raise AttributeError ("No repo member found, cannot create DiffIndex" )
@@ -400,36 +400,36 @@ def __str__(self) -> str:
400400 # end
401401 return res
402402
403- @property
403+ @ property
404404 def a_path (self ) -> Optional [str ]:
405405 return self .a_rawpath .decode (defenc , 'replace' ) if self .a_rawpath else None
406406
407- @property
407+ @ property
408408 def b_path (self ) -> Optional [str ]:
409409 return self .b_rawpath .decode (defenc , 'replace' ) if self .b_rawpath else None
410410
411- @property
411+ @ property
412412 def rename_from (self ) -> Optional [str ]:
413413 return self .raw_rename_from .decode (defenc , 'replace' ) if self .raw_rename_from else None
414414
415- @property
415+ @ property
416416 def rename_to (self ) -> Optional [str ]:
417417 return self .raw_rename_to .decode (defenc , 'replace' ) if self .raw_rename_to else None
418418
419- @property
419+ @ property
420420 def renamed (self ) -> bool :
421421 """:returns: True if the blob of our diff has been renamed
422422 :note: This property is deprecated, please use ``renamed_file`` instead.
423423 """
424424 return self .renamed_file
425425
426- @property
426+ @ property
427427 def renamed_file (self ) -> bool :
428428 """:returns: True if the blob of our diff has been renamed
429429 """
430430 return self .rename_from != self .rename_to
431431
432- @classmethod
432+ @ classmethod
433433 def _pick_best_path (cls , path_match : bytes , rename_match : bytes , path_fallback_match : bytes ) -> Optional [bytes ]:
434434 if path_match :
435435 return decode_path (path_match )
@@ -442,7 +442,7 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
442442
443443 return None
444444
445- @classmethod
445+ @ classmethod
446446 def _index_from_patch_format (cls , repo : 'Repo' , proc : TBD ) -> DiffIndex :
447447 """Create a new DiffIndex from the given text which must be in patch format
448448 :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:
505505
506506 return index
507507
508- @staticmethod
508+ @ staticmethod
509509 def _handle_diff_line (lines_bytes : bytes , repo : 'Repo' , index : DiffIndex ) -> None :
510510 lines = lines_bytes .decode (defenc )
511511
@@ -559,7 +559,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
559559 '' , change_type , score )
560560 index .append (diff )
561561
562- @classmethod
562+ @ classmethod
563563 def _index_from_raw_format (cls , repo : 'Repo' , proc : 'Popen' ) -> 'DiffIndex' :
564564 """Create a new DiffIndex from the given stream which must be in raw format.
565565 :return: git.DiffIndex"""
0 commit comments