If you want a computed docstring, do so after the function is defined. It's a syntactic convenience that the function's __doc__
attribute is set to the first string literal found in the body of a def
statement. You can always set it manually once the function has been defined.
def bar():
pass
bar.__doc__ = "abc"f"def"
One way to "automate" this is to define a decorator that sets __doc__
from an argument.
def set_docstring(s):
def _(f):
f.__doc__ = s
return f
return _
@set_docstring("abc"f"def")
def foo():
pass
Since Python 3.9, you can define the decorator inline (though it's not exactly pretty):
@lambda f: setattr(f, '__doc__', "abc"f"def") or f
def foo():
pass