I have a function that has a following signature:
def function(a=None, b=None, c=None):
# ... some more code ...
If passed, a, b and c can only be booleans.
I want to know all the valid combinations of a, b and c.
Note that a, b and c are optional, so this function can be called with as little as 0 parameters and as much as 3 parameters.
I'm able to get all the possible argument combinations:
arg_names = ['a', 'b', 'c']
arg_values = [None, True, False]
arg_combinations = []
for i in range(len(arg_names)):
arg_combinations += list(
itertools.combinations(arg_names, i + 1)
)
Which produces:
[('a',), ('b',), ('c',), ('a', 'b'), ('a', 'c'), ('b', 'c'), ('a', 'b', 'c')]
However I'm not able to move further, creating all possible combinations of parameters and values:
arg_value_combinations = []
for c in arg_combinations:
arg_value_combinations += list(
itertools.product(c, arg_values)
)
print arg_value_combinations
Which produces:
[('a', None), ('a', True), ('a', False), ('b', None), ('b', True), ('b', False), ('c', None), ('c', True), ('c', False), ('a', None), ('a', True), ('a', False), ('b', None), ('b', True), ('b', False), ('a', None), ('a', True), ('a', False), ('c', None), ('c', True), ('c', False), ('b', None), ('b', True), ('b', False), ('c', None), ('c', True), ('c', False), ('a', None), ('a', True), ('a', False), ('b', None), ('b', True), ('b', False), ('c', None), ('c', True), ('c', False)]
Definitely wrong path.