When writing docstrings for my functions in python, I sometimes want to write something like this about argument specifications:
def foo(bar):
"""
Do some stuff.
bar : callable
must return True if XXX and False otherwise.
"""
if bar(...):
... # code goes here
However, this is not perfectly precise, because in this example bar
could be returning any object that will be evaluated to True
in the if-statement when the conditions XXX is fulfilled. Such a callable would be a perfectly valid argument to pass to foo
.
How should I formulate my documentation to reflect that foo
does not strictly requires bar
's output to be a boolean?
My first move was to write something like "[...] must return an object that will be evaluated to True if ...", but I find it obfuscated.