TBH I think it's usually an anti-pattern when you have an API where the
absence of a parameter is not equivalent to some default value. It makes
wrapping such APIs awkward, e.g.
def logging_foo(*, arg1='something_other_than_spam', arg3=None,
arg4=
Hello,
There is a very common pattern for creating optional arguments when you can't use None:
_optional = object() def foo(*, arg1='spam', arg3=None, arg4=_optional): if arg4 is _optional: # caller didn't pass *anything* for arg4 else: # caller did pass some (maybe None) value for arg4
It's a bit annoying to create this marker objects, and also, if you try to render a signature of such function, you'll get something like:
"(*, arg1='spam', arg3=None, arg4=
What if we add a standard marker for this use-case: functools.optional or inspect.Parameter.optional?
Yury _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido)