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

Commitfb09bfa

Browse files
committed
Improve types of diff.py
1 parent6471018 commitfb09bfa

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

‎git/diff.py‎

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

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

2121
ifTYPE_CHECKING:
2222
from .objects.treeimportTree
@@ -200,7 +200,8 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator['Diff']:
200200
ifchange_typenotinself.change_type:
201201
raiseValueError("Invalid change type: %s"%change_type)
202202

203-
fordiffinself:# type: 'Diff'
203+
# diff: 'Diff'
204+
fordiffinself:
204205
ifdiff.change_type==change_type:
205206
yielddiff
206207
elifchange_type=="A"anddiff.new_file:
@@ -281,7 +282,8 @@ def __init__(self, repo: 'Repo',
281282
a_mode:Union[bytes,str,None],b_mode:Union[bytes,str,None],
282283
new_file:bool,deleted_file:bool,copied_file:bool,
283284
raw_rename_from:Optional[bytes],raw_rename_to:Optional[bytes],
284-
diff:Union[str,bytes,None],change_type:Optional[str],score:Optional[int])->None:
285+
diff:Union[str,bytes,None],change_type:Union[Lit_change_type,None],
286+
score:Optional[int])->None:
285287

286288
asserta_rawpathisNoneorisinstance(a_rawpath,bytes)
287289
assertb_rawpathisNoneorisinstance(b_rawpath,bytes)
@@ -498,12 +500,18 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
498500
forlineinlines.split(':')[1:]:
499501
meta,_,path=line.partition('\x00')
500502
path=path.rstrip('\x00')
501-
a_blob_id,b_blob_id=None,None# Type: Optional[str]
503+
a_blob_id:Union[str,None]
504+
b_blob_id:Union[str,None]
502505
old_mode,new_mode,a_blob_id,b_blob_id,_change_type=meta.split(None,4)
503506
# Change type can be R100
504507
# R: status letter
505508
# 100: score (in case of copy and rename)
506-
change_type=_change_type[0]
509+
510+
defis_change_type(inp:str)->TypeGuard[Lit_change_type]:
511+
returninpinLit_change_type.__args__# type: ignore
512+
513+
assertis_change_type(_change_type[0])
514+
change_type:Lit_change_type=_change_type[0]
507515
score_str=''.join(_change_type[1:])
508516
score=int(score_str)ifscore_str.isdigit()elseNone
509517
path=path.strip()
@@ -518,7 +526,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
518526
# NOTE: We cannot conclude from the existence of a blob to change type
519527
# as diffs with the working do not have blobs yet
520528
ifchange_type=='D':
521-
b_blob_id=None# Optional[str]
529+
b_blob_id=None
522530
deleted_file=True
523531
elifchange_type=='A':
524532
a_blob_id=None

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp