3 ms·
The code in the second example is horrible and for some reason used incorrectly by the author. My usual approach would be something like: def make_pizza(l
by contravariant 4y ago
The code in the second example is horrible and for some reason used incorrectly by the author.
My usual approach would be something like:
def make_pizza(left_toppings, right_toppings=None):
if right_toppings is None:
right_toppings = left_toppings
...
through really it should probably be
def make_pizza(toppings=None, **kwargs):
if toppings is not None:
kwargs['toppings_left'] = toppings
kwargs['toppings_right'] = toppings
return requests.post(PIZZA_URL, kwargs)
If this logic should even be handled in the application itself at all (not sure why you'd choose to make a breaking change to the API rather than extending the API, though changing the make_pizza function to keep the code working after an API change is the correct response).
I'm also not sure why the author chose to make the function capable of handling an arbitrary number of arguments, or why after doing so he chose to incorrectly invoke it on a list.