Skip to content

Commit c1989ab

Browse files
committed
Remove 3 occurences of typing.cast
Signed-off-by: Vincent Michel <vincent.michel@vates.tech>
1 parent b69821b commit c1989ab

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

lib/host.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from lib.vm import VM
3232
from lib.xo import xo_cli, xo_object_exists
3333

34-
from typing import TYPE_CHECKING, Literal, TypedDict, cast, overload
34+
from typing import TYPE_CHECKING, Literal, TypedDict, overload
3535

3636
if TYPE_CHECKING:
3737
from lib.pool import Pool
@@ -121,9 +121,8 @@ def ssh(self, cmd: str, *, check: bool = True, simple_output: bool = True,
121121

122122
@overload
123123
def ssh(self, cmd: str, *, check: bool = True, simple_output: bool = True,
124-
suppress_fingerprint_warnings: bool = True, background: bool = False, decode: bool = True,
125-
multiplexing: bool = True) \
126-
-> str | bytes | commands.SSHResult[str] | commands.SSHResult[bytes] | None:
124+
suppress_fingerprint_warnings: bool = True, background: Literal[False] = False,
125+
decode: Literal[True] = True, multiplexing: bool = True) -> str | commands.SSHResult[str]:
127126
...
128127

129128
def ssh(self, cmd: str, *, check: bool = True, simple_output: bool = True,
@@ -258,7 +257,7 @@ def execute_script(self, script_contents: str, shebang: str = 'sh',
258257

259258
try:
260259
logging.debug(f"[{self}] # Will execute this temporary script:\n{script_contents.strip()}")
261-
return cast(str | commands.SSHResult, self.ssh(remote_path, simple_output=simple_output))
260+
return self.ssh(remote_path, simple_output=simple_output)
262261
finally:
263262
self.ssh(f'rm -f {remote_path}')
264263

lib/vm.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from lib.vdi import VDI
2828
from lib.vif import VIF
2929

30-
from typing import TYPE_CHECKING, Iterable, List, Literal, cast, overload
30+
from typing import TYPE_CHECKING, Iterable, List, Literal, overload
3131

3232
if TYPE_CHECKING:
3333
from lib.host import Host
@@ -130,8 +130,8 @@ def ssh(self, cmd: str, *, check: bool = True, simple_output: bool = True,
130130
...
131131

132132
@overload
133-
def ssh(self, cmd: str, *, check: bool = True, simple_output: bool = True, background: bool = False,
134-
decode: bool = True) -> str | bytes | commands.SSHResult[str] | commands.SSHResult[bytes] | None:
133+
def ssh(self, cmd: str, *, check: bool = True, simple_output: bool = True,
134+
background: Literal[False] = False, decode: Literal[True] = True) -> str | commands.SSHResult[str]:
135135
...
136136

137137
def ssh(self, cmd: str, *, check: bool = True, simple_output: bool = True, background: bool = False,
@@ -463,7 +463,7 @@ def execute_script(self, script_contents: str, simple_output: bool = True) -> st
463463
logging.debug(f"[{self.ip}] # Will execute this temporary script:\n{script_contents.strip()}")
464464
# Use bash to run the script, to avoid being hit by differences between shells, for example on FreeBSD
465465
# It is a documented requirement that bash is present on all test VMs.
466-
res = cast(str | commands.SSHResult, self.ssh(f'bash {f.name}', simple_output=simple_output))
466+
res = self.ssh(f'bash {f.name}', simple_output=simple_output)
467467
return res
468468
finally:
469469
self.ssh(f'rm -f {f.name}')
@@ -801,10 +801,10 @@ def execute_powershell_script(
801801
if prepend is not None:
802802
script_contents = prepend + script_contents
803803
cmd = commands.encode_powershell_command(script_contents)
804-
return cast(str | commands.SSHResult, self.ssh(
804+
return self.ssh(
805805
f"powershell.exe -nologo -noprofile -noninteractive -encodedcommand {cmd}",
806806
simple_output=simple_output,
807-
))
807+
)
808808

809809
def run_powershell_command(self, program: str, args: str) -> int:
810810
"""

0 commit comments

Comments
 (0)