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

Commit7b09003

Browse files
committed
replace cast()s with asserts in remote.py
1 parentdc8d23d commit7b09003

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

‎git/refs/log.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,23 @@ def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): # skipcq:
8282
returnRefLogEntry((oldhexsha,newhexsha,actor, (time,tz_offset),message))
8383

8484
@classmethod
85-
deffrom_line(cls,line):
85+
deffrom_line(cls,line:bytes)->'RefLogEntry':
8686
""":return: New RefLogEntry instance from the given revlog line.
8787
:param line: line bytes without trailing newline
8888
:raise ValueError: If line could not be parsed"""
89-
line=line.decode(defenc)
90-
fields=line.split('\t',1)
89+
line_str=line.decode(defenc)
90+
fields=line_str.split('\t',1)
9191
iflen(fields)==1:
9292
info,msg=fields[0],None
9393
eliflen(fields)==2:
9494
info,msg=fields
9595
else:
9696
raiseValueError("Line must have up to two TAB-separated fields."
97-
" Got %s"%repr(line))
97+
" Got %s"%repr(line_str))
9898
# END handle first split
9999

100-
oldhexsha=info[:40]# type: str
101-
newhexsha=info[41:81]# type: str
100+
oldhexsha=info[:40]
101+
newhexsha=info[41:81]
102102
forhexshain (oldhexsha,newhexsha):
103103
ifnotcls._re_hexsha_only.match(hexsha):
104104
raiseValueError("Invalid hexsha: %r"% (hexsha,))

‎git/remote.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# typing-------------------------------------------------------
3838

39-
fromtypingimportAny,Callable,Dict,Iterator,List,Optional,Sequence,TYPE_CHECKING,Union,cast,overload
39+
fromtypingimportAny,Callable,Dict,Iterator,List,Optional,Sequence,TYPE_CHECKING,Union,overload
4040

4141
fromgit.typesimportPathLike,Literal,TBD,TypeGuard
4242

@@ -559,8 +559,8 @@ def delete_url(self, url: str, **kwargs: Any) -> 'Remote':
559559
defurls(self)->Iterator[str]:
560560
""":return: Iterator yielding all configured URL targets on a remote as strings"""
561561
try:
562-
# can replace cast with type assert?
563-
remote_details=cast(str,self.repo.git.remote("get-url","--all",self.name))
562+
remote_details=self.repo.git.remote("get-url","--all",self.name)
563+
assertisinstance(remote_details,str)
564564
forlineinremote_details.split('\n'):
565565
yieldline
566566
exceptGitCommandErrorasex:
@@ -571,14 +571,16 @@ def urls(self) -> Iterator[str]:
571571
#
572572
if'Unknown subcommand: get-url'instr(ex):
573573
try:
574-
remote_details=cast(str,self.repo.git.remote("show",self.name))
574+
remote_details=self.repo.git.remote("show",self.name)
575+
assertisinstance(remote_details,str)
575576
forlineinremote_details.split('\n'):
576577
if' Push URL:'inline:
577578
yieldline.split(': ')[-1]
578579
exceptGitCommandErroras_ex:
579580
ifany(msginstr(_ex)formsgin ['correct access rights','cannot run ssh']):
580581
# If ssh is not setup to access this repository, see issue 694
581-
remote_details=cast(str,self.repo.git.config('--get-all','remote.%s.url'%self.name))
582+
remote_details=self.repo.git.config('--get-all','remote.%s.url'%self.name)
583+
assertisinstance(remote_details,str)
582584
forlineinremote_details.split('\n'):
583585
yieldline
584586
else:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp