Skip to content

Commit 7b09003

Browse files
committed
replace cast()s with asserts in remote.py
1 parent dc8d23d commit 7b09003

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

git/refs/log.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,23 @@ def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): # skipcq:
8282
return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message))
8383

8484
@classmethod
85-
def from_line(cls, line):
85+
def from_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
if len(fields) == 1:
9292
info, msg = fields[0], None
9393
elif len(fields) == 2:
9494
info, msg = fields
9595
else:
9696
raise ValueError("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
for hexsha in (oldhexsha, newhexsha):
103103
if not cls._re_hexsha_only.match(hexsha):
104104
raise ValueError("Invalid hexsha: %r" % (hexsha,))

git/remote.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

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

39-
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, TYPE_CHECKING, Union, cast, overload
39+
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, TYPE_CHECKING, Union, overload
4040

4141
from git.types import PathLike, Literal, TBD, TypeGuard
4242

@@ -559,8 +559,8 @@ def delete_url(self, url: str, **kwargs: Any) -> 'Remote':
559559
def urls(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+
assert isinstance(remote_details, str)
564564
for line in remote_details.split('\n'):
565565
yield line
566566
except GitCommandError as ex:
@@ -571,14 +571,16 @@ def urls(self) -> Iterator[str]:
571571
#
572572
if 'Unknown subcommand: get-url' in str(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+
assert isinstance(remote_details, str)
575576
for line in remote_details.split('\n'):
576577
if ' Push URL:' in line:
577578
yield line.split(': ')[-1]
578579
except GitCommandError as _ex:
579580
if any(msg in str(_ex) for msg in ['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+
assert isinstance(remote_details, str)
582584
for line in remote_details.split('\n'):
583585
yield line
584586
else:

0 commit comments

Comments
 (0)