From dd788f9eee9b37f1884b649a468e6fd035f83fd2 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Tue, 5 Apr 2022 10:13:50 +0200 Subject: [PATCH] add assert statements following .communicate() to help type checkers After calling .communicate() on an asyncio.subprocess.Process object, the attribute returncode gets set to a non-None value. Type checkers are not able to figure this out. Fixed by adding an assert to help type checkers out. Signed-off-by: Olivier Gayot --- subiquity/server/runner.py | 2 ++ subiquitycore/utils.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/subiquity/server/runner.py b/subiquity/server/runner.py index d196cc4c..f4e602d7 100644 --- a/subiquity/server/runner.py +++ b/subiquity/server/runner.py @@ -78,6 +78,8 @@ class LoggedCommandRunner: async def wait(self, proc: asyncio.subprocess.Process) \ -> subprocess.CompletedProcess: stdout, stderr = await proc.communicate() + # .communicate() forces returncode to be set to a value + assert(proc.returncode is not None) if proc.returncode != 0: raise subprocess.CalledProcessError(proc.returncode, proc.args) else: diff --git a/subiquitycore/utils.py b/subiquitycore/utils.py index e790cf8d..dcaa86fd 100644 --- a/subiquitycore/utils.py +++ b/subiquitycore/utils.py @@ -84,6 +84,8 @@ async def arun_command(cmd: List[str], *, if stderr is not None: stderr = stderr.decode(encoding) log.debug("arun_command %s exited with code %s", cmd, proc.returncode) + # .communicate() forces returncode to be set to a value + assert(proc.returncode is not None) if check and proc.returncode != 0: raise subprocess.CalledProcessError(proc.returncode, cmd) else: