I would like to extract the docstring of a function once it has been wrapped in lambda
.
Consider the following example:
def foo(a=1):
"""Foo docstring"""
return a
dct = {
"a": foo,
"b": lambda: foo(2),
}
for k, v in dct.items()
print(k, v(), v.__doc__)
I get:
a 1 Foo docstring
b 2 None
How can I reference the function called on "calling" the lambda
one?
Update
Thanks for all answers:
from functools import partial
def foo(a=1):
"""Foo docstring"""
return a
dct = {
"a": foo,
"b": partial(foo, 2),
}
for k, v in dct.items():
if hasattr(v, "func"):
print(k, v(), v.func.__doc__)
else:
print(k, v(), v.__doc__)
a 1 Foo docstring
b 2 Foo docstring