diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2020-03-02 11:11:17 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2020-03-05 09:31:29 -0800 |
commit | a8293dd59c0a22817f2336df8ae97dce1232f72a (patch) | |
tree | 123b316ad1bf34c52f75c29d05e8b94ab05d52be /mesonbuild/mesonlib.py | |
parent | 1a82880730e2d9f58eaa67179aa40c6976835278 (diff) | |
download | meson-a8293dd59c0a22817f2336df8ae97dce1232f72a.zip meson-a8293dd59c0a22817f2336df8ae97dce1232f72a.tar.gz meson-a8293dd59c0a22817f2336df8ae97dce1232f72a.tar.bz2 |
mesonlib: Replace unholder argument to listify
listify shouldn't be unholdering, it's a function to turn scalar values
into lists, or flatten lists. Having a separate function is clearer,
easier to understand, and can be run recursively if necessary.
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r-- | mesonbuild/mesonlib.py | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 49ddc94..07e30e2 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -1058,34 +1058,25 @@ def unholder(item): return item -def listify(item: T.Any, - flatten: bool = True, - unholder: bool = False) -> T.List[T.Any]: +def listify(item: T.Any, flatten: bool = True) -> T.List[T.Any]: ''' Returns a list with all args embedded in a list if they are not a list. This function preserves order. @flatten: Convert lists of lists to a flat list - @unholder: Replace each item with the object it holds, if required - - Note: unholding only works recursively when flattening ''' if not isinstance(item, list): - if unholder and hasattr(item, 'held_object'): - item = item.held_object return [item] result = [] # type: T.List[T.Any] for i in item: - if unholder and hasattr(i, 'held_object'): - i = i.held_object if flatten and isinstance(i, list): - result += listify(i, flatten=True, unholder=unholder) + result += listify(i, flatten=True) else: result.append(i) return result def extract_as_list(dict_object: T.Dict[_T, _U], *keys: _T, pop: bool = False, - **kwargs: T.Any) -> T.List[T.Union[_U, T.List[_U]]]: + flatten: bool = True) -> T.List[T.Union[_U, T.List[_U]]]: ''' Extracts all values from given dict_object and listifies them. ''' @@ -1095,10 +1086,10 @@ def extract_as_list(dict_object: T.Dict[_T, _U], *keys: _T, pop: bool = False, 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], []), **kwargs) + return listify(fetch(keys[0], []), flatten=True) # Return a list of values corresponding to *keys for key in keys: - result.append(listify(fetch(key, []), **kwargs)) + result.append(listify(fetch(key, []), flatten=True)) return result |