Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf916c14

Browse files
committed
Improve Diffable method typing
1 parent7c6ae2b commitf916c14

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

‎git/diff.py‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
# typing ------------------------------------------------------------------
1717

1818
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING
19-
fromgit.typesimportHas_Repo,PathLike,TBD,Literal,TypeGuard
19+
fromgit.typesimportPathLike,TBD,Literal,TypeGuard
2020

2121
ifTYPE_CHECKING:
2222
from .objects.treeimportTree
2323
fromgit.repo.baseimportRepo
2424
fromgit.objects.baseimportIndexObject
25-
2625
fromsubprocessimportPopen
2726

2827
Lit_change_type=Literal['A','D','C','M','R','T','U']
@@ -82,15 +81,16 @@ class Diffable(object):
8281
classIndex(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
returnargs
9292

93-
defdiff(self,other:Union[Type[Index],Type['Tree'],object,None,str]=Index,
93+
defdiff(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
ifpathsisnotNoneandnotisinstance(paths, (tuple,list)):
142142
paths= [paths]
143143

144-
ifisinstance(self,Has_Repo):
144+
ifhasattr(self,'Has_Repo'):
145145
self.repo:Repo=self.repo
146146
else:
147147
raiseAttributeError("No repo member found, cannot create DiffIndex")
@@ -400,36 +400,36 @@ def __str__(self) -> str:
400400
# end
401401
returnres
402402

403-
@property
403+
@property
404404
defa_path(self)->Optional[str]:
405405
returnself.a_rawpath.decode(defenc,'replace')ifself.a_rawpathelseNone
406406

407-
@property
407+
@property
408408
defb_path(self)->Optional[str]:
409409
returnself.b_rawpath.decode(defenc,'replace')ifself.b_rawpathelseNone
410410

411-
@property
411+
@property
412412
defrename_from(self)->Optional[str]:
413413
returnself.raw_rename_from.decode(defenc,'replace')ifself.raw_rename_fromelseNone
414414

415-
@property
415+
@property
416416
defrename_to(self)->Optional[str]:
417417
returnself.raw_rename_to.decode(defenc,'replace')ifself.raw_rename_toelseNone
418418

419-
@property
419+
@property
420420
defrenamed(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
returnself.renamed_file
425425

426-
@property
426+
@property
427427
defrenamed_file(self)->bool:
428428
""":returns: True if the blob of our diff has been renamed
429429
"""
430430
returnself.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
ifpath_match:
435435
returndecode_path(path_match)
@@ -442,7 +442,7 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
442442

443443
returnNone
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
returnindex
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"""

‎git/index/base.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# typing -----------------------------------------------------------------------------
6969

7070
fromtypingimport (Any,BinaryIO,Callable,Dict,IO,Iterable,Iterator,List,NoReturn,
71-
Sequence,TYPE_CHECKING,Tuple,Union)
71+
Sequence,TYPE_CHECKING,Tuple,Type,Union)
7272

7373
fromgit.typesimportCommit_ish,PathLike,TBD
7474

@@ -575,8 +575,8 @@ def write_tree(self) -> Tree:
575575
root_tree._cache=tree_items# type: ignore
576576
returnroot_tree
577577

578-
def_process_diff_args(self,args:List[Union[str,git_diff.Diffable,object]]
579-
)->List[Union[str,git_diff.Diffable,object]]:
578+
def_process_diff_args(self,args:List[Union[PathLike,'git_diff.Diffable',Type['git_diff.Diffable.Index']]]
579+
)->List[Union[PathLike,'git_diff.Diffable',Type['git_diff.Diffable.Index']]]:
580580
try:
581581
args.pop(args.index(self))
582582
exceptIndexError:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp