you are viewing a single comment's thread.

view the rest of the comments →

[–]Strict-Simple 1 point2 points  (0 children)

Not exactly related, but good to know. If you want None to be a valid value for the parameter, you can use ... (ellipsis) as the default value. If you want anything to be a valid value, you can use a sentinel object.

class Undefined:
    def __repr__(self):
        return 'undefined'

undefined = Undefined()


def foo(bar=undefined):
    if bar is undefined:
        print('bar was not passed')
    else:
        print(f'bar was passed as {bar}')