From f8846c198d8fbddc18e129e8ff3f77cb6fb941b9 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Sun, 13 Sep 2020 10:52:02 +0200 Subject: [PATCH] Update types and docstrings --- spacy/cli/_util.py | 11 +++++++++-- spacy/util.py | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spacy/cli/_util.py b/spacy/cli/_util.py index 360d2439a..573b63562 100644 --- a/spacy/cli/_util.py +++ b/spacy/cli/_util.py @@ -387,8 +387,15 @@ def _from_http_to_git(repo: str) -> str: return repo -def string_to_list(value, intify=False): - """Parse a comma-separated string to a list""" +def string_to_list(value: str, intify: bool = False) -> Union[List[str], List[int]]: + """Parse a comma-separated string to a list and account for various + formatting options. Mostly used to handle CLI arguments that take a list of + comma-separated values. + + value (str): The value to parse. + intify (bool): Whether to convert values to ints. + RETURNS (Union[List[str], List[int]]): A list of strings or ints. + """ if not value: return [] if value.startswith("[") and value.endswith("]"): diff --git a/spacy/util.py b/spacy/util.py index d8df04554..6f1efe926 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -648,12 +648,20 @@ def join_command(command: List[str]) -> str: return " ".join(shlex.quote(cmd) for cmd in command) -def run_command(command: Union[str, List[str]], *, capture=False, stdin=None): +def run_command( + command: Union[str, List[str]], + *, + capture: bool = False, + stdin: Optional[Any] = None, +) -> Optional[subprocess.CompletedProcess]: """Run a command on the command line as a subprocess. If the subprocess returns a non-zero exit code, a system exit is performed. command (str / List[str]): The command. If provided as a string, the string will be split using shlex.split. + stdin (Optional[Any]): stdin to read from or None. + capture (bool): Whether to capture the output. + RETURNS (Optional[CompletedProcess]): The process object. """ if isinstance(command, str): command = split_command(command)