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

Commit873ebe6

Browse files
committed
Make diff.DiffIndex generic List['Diff']
1 parente985851 commit873ebe6

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

‎git/diff.py‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
# typing ------------------------------------------------------------------
1717

18-
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,Union,TYPE_CHECKING,cast
18+
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING
1919
fromgit.typesimportPathLike,TBD,Literal,TypeGuard
2020

2121
ifTYPE_CHECKING:
2222
from .objects.treeimportTree
2323
fromgit.repo.baseimportRepo
24+
fromgit.objects.baseimportIndexObject
2425

2526
fromsubprocessimportPopen
2627

@@ -175,7 +176,10 @@ def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Inde
175176
returnindex
176177

177178

178-
classDiffIndex(list):
179+
T_Diff=TypeVar('T_Diff',bound='Diff')
180+
181+
182+
classDiffIndex(List[T_Diff]):
179183

180184
"""Implements an Index for diffs, allowing a list of Diffs to be queried by
181185
the diff properties.
@@ -189,7 +193,7 @@ class DiffIndex(list):
189193
# T = Changed in the type
190194
change_type= ("A","C","D","R","M","T")
191195

192-
defiter_change_type(self,change_type:Lit_change_type)->Iterator['Diff']:
196+
defiter_change_type(self,change_type:Lit_change_type)->Iterator[T_Diff]:
193197
"""
194198
:return:
195199
iterator yielding Diff instances that match the given change_type
@@ -207,8 +211,6 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator['Diff']:
207211
raiseValueError("Invalid change type: %s"%change_type)
208212

209213
fordiffinself:
210-
diff=cast('Diff',diff)
211-
212214
ifdiff.change_type==change_type:
213215
yielddiff
214216
elifchange_type=="A"anddiff.new_file:
@@ -289,7 +291,7 @@ def __init__(self, repo: 'Repo',
289291
a_mode:Union[bytes,str,None],b_mode:Union[bytes,str,None],
290292
new_file:bool,deleted_file:bool,copied_file:bool,
291293
raw_rename_from:Optional[bytes],raw_rename_to:Optional[bytes],
292-
diff:Union[str,bytes,None],change_type:Optional[str],score:Optional[int])->None:
294+
diff:Union[str,bytes,None],change_type:Optional[Lit_change_type],score:Optional[int])->None:
293295

294296
asserta_rawpathisNoneorisinstance(a_rawpath,bytes)
295297
assertb_rawpathisNoneorisinstance(b_rawpath,bytes)
@@ -308,19 +310,21 @@ def __init__(self, repo: 'Repo',
308310
repo=submodule.module()
309311
break
310312

313+
self.a_blob:Union['IndexObject',None]
311314
ifa_blob_idisNoneora_blob_id==self.NULL_HEX_SHA:
312315
self.a_blob=None
313316
else:
314317
self.a_blob=Blob(repo,hex_to_bin(a_blob_id),mode=self.a_mode,path=self.a_path)
315318

319+
self.b_blob:Union['IndexObject',None]
316320
ifb_blob_idisNoneorb_blob_id==self.NULL_HEX_SHA:
317321
self.b_blob=None
318322
else:
319323
self.b_blob=Blob(repo,hex_to_bin(b_blob_id),mode=self.b_mode,path=self.b_path)
320324

321-
self.new_file=new_file
322-
self.deleted_file=deleted_file
323-
self.copied_file=copied_file
325+
self.new_file:bool=new_file
326+
self.deleted_file:bool=deleted_file
327+
self.copied_file:bool=copied_file
324328

325329
# be clear and use None instead of empty strings
326330
assertraw_rename_fromisNoneorisinstance(raw_rename_from,bytes)
@@ -329,7 +333,7 @@ def __init__(self, repo: 'Repo',
329333
self.raw_rename_to=raw_rename_toorNone
330334

331335
self.diff=diff
332-
self.change_type=change_type
336+
self.change_type:Union[Lit_change_type,None]=change_type
333337
self.score=score
334338

335339
def__eq__(self,other:object)->bool:
@@ -449,7 +453,7 @@ def _index_from_patch_format(cls, repo: 'Repo', proc: TBD) -> DiffIndex:
449453

450454
# for now, we have to bake the stream
451455
text=b''.join(text_list)
452-
index=DiffIndex()
456+
index:'DiffIndex'=DiffIndex()
453457
previous_header=None
454458
header=None
455459
a_path,b_path=None,None# for mypy
@@ -560,7 +564,7 @@ def _index_from_raw_format(cls, repo: 'Repo', proc: 'Popen') -> 'DiffIndex':
560564
# handles
561565
# :100644 100644 687099101... 37c5e30c8... M .gitignore
562566

563-
index=DiffIndex()
567+
index:'DiffIndex'=DiffIndex()
564568
handle_process_output(proc,lambdabyt:cls._handle_diff_line(byt,repo,index),
565569
None,finalize_process,decode_streams=False)
566570

‎git/index/util.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __del__(self) -> None:
5252

5353
#{ Decorators
5454

55-
defpost_clear_cache(func:Callable[...,Any])->Callable[...,Any]:
55+
defpost_clear_cache(func:Callable[...,_T])->Callable[...,_T]:
5656
"""Decorator for functions that alter the index using the git command. This would
5757
invalidate our possibly existing entries dictionary which is why it must be
5858
deleted to allow it to be lazily reread later.
@@ -63,7 +63,7 @@ def post_clear_cache(func: Callable[..., Any]) -> Callable[..., Any]:
6363
"""
6464

6565
@wraps(func)
66-
defpost_clear_cache_if_not_raised(self,*args:Any,**kwargs:Any)->Any:
66+
defpost_clear_cache_if_not_raised(self,*args:Any,**kwargs:Any)->_T:
6767
rval=func(self,*args,**kwargs)
6868
self._delete_entries_cache()
6969
returnrval
@@ -72,13 +72,13 @@ def post_clear_cache_if_not_raised(self, *args: Any, **kwargs: Any) -> Any:
7272
returnpost_clear_cache_if_not_raised
7373

7474

75-
defdefault_index(func:Callable[...,Any])->Callable[...,Any]:
75+
defdefault_index(func:Callable[...,_T])->Callable[...,_T]:
7676
"""Decorator assuring the wrapped method may only run if we are the default
7777
repository index. This is as we rely on git commands that operate
7878
on that index only. """
7979

8080
@wraps(func)
81-
defcheck_default_index(self,*args:Any,**kwargs:Any)->Any:
81+
defcheck_default_index(self,*args:Any,**kwargs:Any)->_T:
8282
ifself._file_path!=self._index_path():
8383
raiseAssertionError(
8484
"Cannot call %r on indices that do not represent the default git index"%func.__name__)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp