diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2020-03-04 13:04:24 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2020-03-05 09:58:52 -0800 |
commit | 581d69a8d3a726dea06e8bf0cd18bb901692b56f (patch) | |
tree | a35887377e1967b4d9fb2f9280e8d3bd410e4cb1 /mesonbuild/mesonlib.py | |
parent | b231ff36df8e5cb21fa41a6380516c6cf5bf9c4e (diff) | |
download | meson-581d69a8d3a726dea06e8bf0cd18bb901692b56f.zip meson-581d69a8d3a726dea06e8bf0cd18bb901692b56f.tar.gz meson-581d69a8d3a726dea06e8bf0cd18bb901692b56f.tar.bz2 |
remove ability to pass multiple keys to extract_as_list
This makes the typing annotations basically impossible to get right, but
if we only have one key then it's easy. Fortunately python provides
comprehensions, so we don't even need the ability to pass multiple keys,
we can just [extract_as_list(kwargs, c) for c in ('a', 'b', 'c')] and
get the same result.
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r-- | mesonbuild/mesonlib.py | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index e93b66f..e215dcd 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -1075,22 +1075,15 @@ def listify(item: T.Any, flatten: bool = True) -> T.List[T.Any]: return result -def extract_as_list(dict_object: T.Dict[_T, _U], *keys: _T, pop: bool = False, - flatten: bool = True) -> T.List[T.Union[_U, T.List[_U]]]: +def extract_as_list(dict_object: T.Dict[_T, _U], key: _T, pop: bool = False) -> T.List[_U]: ''' Extracts all values from given dict_object and listifies them. ''' - result = [] # type: T.List[T.Union[_U, T.List[_U]]] fetch = dict_object.get if pop: fetch = dict_object.pop # If there's only one key, we don't return a list with one element - if len(keys) == 1: - return listify(fetch(keys[0], []), flatten=True) - # Return a list of values corresponding to *keys - for key in keys: - result.append(listify(fetch(key, []), flatten=True)) - return result + return listify(fetch(key, []), flatten=True) def typeslistify(item: 'T.Union[_T, T.Sequence[_T]]', |