4 ms·
Subtle bug in that toppings has a mutable default argument [1]. [1] https://docs.python-guide.org/writing/gotchas/ https://docs.python-guide.org/writing/gotcha
by scwoodal 4y ago
Subtle bug in that toppings has a mutable default argument [1].
[1] https://docs.python-guide.org/writing/gotchas/ https://docs.python-guide.org/writing/gotchas/
- danuker 4y agoThere is no bug... yet. Unless you modify the default argument. Sometimes I just want to monkeypatch the list to be immutable in my app.
- scwoodal 4y agoI'd consider this a bug and not expected behavior. def make_pizza(crust=THIN, toppings=[], cheese=REGULAR, sauce=TOMATO): // first call: toppings=["peperoni"] // second call: toppings=["peperoni", "sausage"] // third call: toppings=["peperoni", "sausage"] make_pizza(toppings=["peperoni"]) make_pizza(toppings=["sausage"]) make_pizza()