Add type hint to utils.run_command to fix pytype checker error. (#779)
diff --git a/mobly/utils.py b/mobly/utils.py
index e3c69aa..4c5880d 100644
--- a/mobly/utils.py
+++ b/mobly/utils.py
@@ -29,6 +29,9 @@
import threading
import time
import traceback
+from typing import overload, Tuple
+# TODO(ericth): Use Literal from typing if we only run on Python 3.8 or later.
+from typing_extensions import Literal
import portpicker
@@ -304,6 +307,33 @@
return return_vals
+# Provide hint for pytype checker to avoid the Union[bytes, str] case.
+@overload
+def run_command(cmd,
+ stdout=...,
+ stderr=...,
+ shell=...,
+ timeout=...,
+ cwd=...,
+ env=...,
+ universal_newlines: Literal[False] = ...
+ ) -> Tuple[int, bytes, bytes]:
+ ...
+
+
+@overload
+def run_command(cmd,
+ stdout=...,
+ stderr=...,
+ shell=...,
+ timeout=...,
+ cwd=...,
+ env=...,
+ universal_newlines: Literal[True] = ...
+ ) -> Tuple[int, str, str]:
+ ...
+
+
def run_command(cmd,
stdout=None,
stderr=None,
diff --git a/setup.py b/setup.py
index a1f91e6..3861009 100755
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,8 @@
import sys
install_requires = [
- 'portpicker', 'psutil>=5.4.4', 'pyserial', 'pyyaml', 'timeout_decorator'
+ 'portpicker', 'psutil>=5.4.4', 'pyserial', 'pyyaml', 'timeout_decorator',
+ 'typing_extensions'
]
if platform.system() == 'Windows':