From 24e0774acee5036a9556360fef0fe2e76ea30e02 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sun, 1 Oct 2017 12:18:57 +0530 Subject: Always flatten in listify() since we always want that All our kwargs take lists that must be flattened Closes https://github.com/mesonbuild/meson/issues/2408 --- mesonbuild/mesonlib.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 71134a8..95af3ea 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -200,15 +200,7 @@ def classify_unity_sources(compilers, sources): return compsrclist def flatten(item): - if not isinstance(item, list): - return [item] - result = [] - for i in item: - if isinstance(i, list): - result += flatten(i) - else: - result.append(i) - return result + return listify(item, flatten=True) def is_osx(): return platform.system().lower() == 'darwin' @@ -475,23 +467,33 @@ def replace_if_different(dst, dst_tmp): os.unlink(dst_tmp) -def listify(*args): +def listify(item, flatten=True): ''' Returns a list with all args embedded in a list if they are not of type list. This function preserves order. ''' - if len(args) == 1: # Special case with one single arg - return args[0] if type(args[0]) is list else [args[0]] - return [item if type(item) is list else [item] for item in args] + if not isinstance(item, list): + return [item] + result = [] + if flatten: + for i in item: + if isinstance(i, list): + result += listify(i, flatten=True) + else: + result.append(i) + else: + for i in item: + result.append(i) + return result -def extract_as_list(dict_object, *keys, pop = False): +def extract_as_list(dict_object, *keys, pop=False): ''' Extracts all values from given dict_object and listifies them. ''' if pop: - return listify(*[dict_object.pop(key, []) for key in keys]) - return listify(*[dict_object.get(key, []) for key in keys]) + return flatten([dict_object.pop(key, []) for key in keys]) + return flatten([dict_object.get(key, []) for key in keys]) def typeslistify(item, types): -- cgit v1.1