You can change the default value for the sentry:
_sentinel = object() def foo(a, optional=_sentinel): if optional is _sentinel: optional = 42 print "1 arg" else: print "2 args"
or by accessing it directly in the func_defaults tuple:
def foo(a, optional=object()): if optional is foo.func_defaults[0]: optional = 42 print "1 arg" else: print "2 args"
but in fact it is not used; this will just confuse those who are not familiar with the standard attributes of a function object.
Yes, the _sentinel object is introspective and can be obtained by a specific developer, but then the same developer can simply disable your function. _sentinel
source share