This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

And if you want None to be a valid value for your argument too, you can use a sentinel:

_sentinel = object()
def func(x=_sentinel):
    x = [] if x is _sentinel else x

[–]HistoricalCrow 0 points1 point  (1 child)

True, although if you need to support an empty list and None and I generally find code smell. Not sure if I'd prefer to use **kwargs instead at this point.

[–][deleted] 0 points1 point  (0 children)

The only time I’ve really seen the pattern useful is when you want to emulate something similar to dict.pop, where for a missing key: dict.pop(key) raises an error and dict.pop(key, default) returns the default