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

Commitaba4d9b

Browse files
committed
replace cast()s with asserts in fun.py
1 parent7b09003 commitaba4d9b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

‎git/index/fun.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
fromtypingimport (Dict,IO,List,Sequence,TYPE_CHECKING,Tuple,Type,Union,cast)
5555

56-
fromgit.typesimportPathLike
56+
fromgit.typesimportPathLike,TypeGuard
5757

5858
ifTYPE_CHECKING:
5959
from .baseimportIndexFile
@@ -185,11 +185,17 @@ def read_header(stream: IO[bytes]) -> Tuple[int, int]:
185185
defentry_key(*entry:Union[BaseIndexEntry,PathLike,int])->Tuple[PathLike,int]:
186186
""":return: Key suitable to be used for the index.entries dictionary
187187
:param entry: One instance of type BaseIndexEntry or the path and the stage"""
188+
189+
defis_entry_tuple(entry:Tuple)->TypeGuard[Tuple[PathLike,int]]:
190+
returnisinstance(entry,tuple)andlen(entry)==2
191+
188192
iflen(entry)==1:
189-
entry_first=cast(BaseIndexEntry,entry[0])# type: BaseIndexEntry
193+
entry_first=entry[0]
194+
assertisinstance(entry_first,BaseIndexEntry)
190195
return (entry_first.path,entry_first.stage)
191196
else:
192-
entry=cast(Tuple[PathLike,int],tuple(entry))
197+
# entry = tuple(entry)
198+
assertis_entry_tuple(entry)
193199
returnentry
194200
# END handle entry
195201

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp