|
17 | 17 |
|
18 | 18 | from collections.abc import Mapping, MutableMapping, Sequence |
19 | 19 | from typing import Any, Callable, Final, TextIO, Union |
20 | | -from typing_extensions import TypeAlias, Never |
| 20 | +from typing_extensions import Never, TypeAlias |
21 | 21 |
|
22 | 22 | from mypy import defaults |
23 | 23 | from mypy.options import PER_MODULE_OPTIONS, Options |
@@ -63,15 +63,26 @@ def parse_version(v: str | float) -> tuple[int, int]: |
63 | 63 | def try_split(v: str | Sequence[str] | Any, split_regex: str = "[,]") -> list[str]: |
64 | 64 | """Split and trim a str or sequence (eg: list) of str into a list of str. |
65 | 65 | If an element of the input is not str, a type error will be raised.""" |
| 66 | + |
66 | 67 | def complain(x: object, additional_info: str = "") -> Never: |
67 | | - raise argparse.ArgumentTypeError(f"Expected a list or a stringified version thereof, but got: '{x}', of type {type(x)}.{additional_info}") |
| 68 | + raise argparse.ArgumentTypeError( |
| 69 | + f"Expected a list or a stringified version thereof, but got: '{x}', of type {type(x)}.{additional_info}" |
| 70 | + ) |
| 71 | + |
68 | 72 | if isinstance(v, str): |
69 | 73 | items = [p.strip() for p in re.split(split_regex, v)] |
70 | 74 | if items and items[-1] == "": |
71 | 75 | items.pop(-1) |
72 | 76 | return items |
73 | 77 | elif isinstance(v, Sequence): |
74 | | - return [p.strip() if isinstance(p, str) else complain(p, additional_info=" (As an element of the list.)") for p in v] |
| 78 | + return [ |
| 79 | + ( |
| 80 | + p.strip() |
| 81 | + if isinstance(p, str) |
| 82 | + else complain(p, additional_info=" (As an element of the list.)") |
| 83 | + ) |
| 84 | + for p in v |
| 85 | + ] |
75 | 86 | else: |
76 | 87 | complain(v) |
77 | 88 |
|
|
0 commit comments