Skip to content

Commit

Permalink
More types
Browse files Browse the repository at this point in the history
  • Loading branch information
singiamtel committed Nov 20, 2024
1 parent 219850c commit 52650d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions alibuild_helpers/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from alibuild_helpers.log import debug, warning, dieOnError

def decode_with_fallback(data):
def decode_with_fallback(data : bytes | str) -> str:
"""Try to decode DATA as utf-8; if that doesn't work, fall back to latin-1.
This combination should cover every possible byte string, as latin-1 covers
Expand All @@ -23,7 +23,7 @@ def decode_with_fallback(data):
return str(data)


def getoutput(command, timeout=None):
def getoutput(command:str, timeout=None) -> str:
"""Run command, check it succeeded, and return its stdout as a string."""
proc = Popen(command, shell=isinstance(command, str), stdout=PIPE, stderr=PIPE)
try:
Expand All @@ -37,7 +37,7 @@ def getoutput(command, timeout=None):
return decode_with_fallback(stdout)


def getstatusoutput(command, timeout=None):
def getstatusoutput(command:str, timeout: int | None = None) -> tuple[int, str]:
"""Run command and return its return code and output (stdout and stderr)."""
proc = Popen(command, shell=isinstance(command, str), stdout=PIPE, stderr=STDOUT)
try:
Expand Down
3 changes: 2 additions & 1 deletion alibuild_helpers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def getRetry(self, url, dest=None, returnResult=False, log=True, session=None, p
reportTime = time.time()
result = []

destFp = None
try:
destFp = open(dest+".tmp", "wb") if dest else None
if dest: destFp = open(dest+".tmp", "wb")
for chunk in filter(bool, resp.iter_content(chunk_size=32768)):
if destFp:
destFp.write(chunk)
Expand Down

0 comments on commit 52650d4

Please sign in to comment.