C. · @cazabon
171 followers · 4261 posts · Server mindly.social

@AugierLe42e

We don't actually need a special constant for this; this is a pretty standard Python :

NOT_SET = object()

def f(a: int, b: int = NOT_SET):
if b is NOT_SET:
# function called without second argument
...

NOT_SET is a bare object, which will never compare equal to anything else, and is a singleton so the natural test is . It absolutely distinguishes between "no argument" and "caller happened to pass the value ".

#idiom #object #identity #default #explicitly

Last updated 1 year ago

DavidV.TV Social ® · @DavidVTV
86 followers · 13753 posts · Server masthead.social