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 :
2222from .objects .tree import Tree
2323from git .repo .base import Repo
2424from git .objects .base import IndexObject
25-
2625from subprocess import Popen
2726
2827Lit_change_type = Literal ['A' ,'D' ,'C' ,'M' ,'R' ,'T' ,'U' ]
@@ -82,15 +81,16 @@ class Diffable(object):
8281class Index (object ):
8382pass
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"""
9191return 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 ,
9494paths :Union [PathLike ,List [PathLike ],Tuple [PathLike , ...],None ]= None ,
9595create_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' ]]] = [ ]
127127args .append ("--abbrev=40" )# we need full shas
128128args .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
141141if paths is not None and not isinstance (paths , (tuple ,list )):
142142paths = [paths ]
143143
144- if isinstance (self ,Has_Repo ):
144+ if hasattr (self ,' Has_Repo' ):
145145self .repo :Repo = self .repo
146146else :
147147raise AttributeError ("No repo member found, cannot create DiffIndex" )
@@ -400,36 +400,36 @@ def __str__(self) -> str:
400400# end
401401return res
402402
403- @property
403+ @property
404404def a_path (self )-> Optional [str ]:
405405return self .a_rawpath .decode (defenc ,'replace' )if self .a_rawpath else None
406406
407- @property
407+ @property
408408def b_path (self )-> Optional [str ]:
409409return self .b_rawpath .decode (defenc ,'replace' )if self .b_rawpath else None
410410
411- @property
411+ @property
412412def rename_from (self )-> Optional [str ]:
413413return self .raw_rename_from .decode (defenc ,'replace' )if self .raw_rename_from else None
414414
415- @property
415+ @property
416416def rename_to (self )-> Optional [str ]:
417417return self .raw_rename_to .decode (defenc ,'replace' )if self .raw_rename_to else None
418418
419- @property
419+ @property
420420def 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 """
424424return self .renamed_file
425425
426- @property
426+ @property
427427def renamed_file (self )-> bool :
428428""":returns: True if the blob of our diff has been renamed
429429 """
430430return self .rename_from != self .rename_to
431431
432- @classmethod
432+ @classmethod
433433def _pick_best_path (cls ,path_match :bytes ,rename_match :bytes ,path_fallback_match :bytes )-> Optional [bytes ]:
434434if path_match :
435435return decode_path (path_match )
@@ -442,7 +442,7 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
442442
443443return None
444444
445- @classmethod
445+ @classmethod
446446def _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
506506return index
507507
508- @staticmethod
508+ @staticmethod
509509def _handle_diff_line (lines_bytes :bytes ,repo :'Repo' ,index :DiffIndex )-> None :
510510lines = 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 )
560560index .append (diff )
561561
562- @classmethod
562+ @classmethod
563563def _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"""