Setting Doc String
mhumpher opened this issue · comments
Is it possible to set the doc string for a cell outside of a module import? After creating a cell with new_cell, I want to add a doc string, but using the doc property or set_property method return an error.
The doc
property of a Cells is linked to the docstring in its Formula.
>>> foo.formula
def foo(x):
"""this is foo's doc"""
return x
>>> foo.doc
"this is foo's doc"
So to change doc
, you can redefine the Formula
>>> def temp(x):
... """foo's doc is updated"""
... return x
>>> foo.formula = temp
>>> foo.formula
def foo(x):
"""foo's doc is updated"""
return x
>>> foo.doc
"foo's doc is updated"
The name temp
can be anything. It gets replaced with foo
.
If Formula is defined by a lambda function, doc
is None
because lambda functions don't have docstrings.
I'm planning to enhance modelx so that Cells with lambda functions can have docs.
I also want to allow such operation as foo.doc = "foo's doc is updated"
, which updates the docstring in its Formula.
Thanks. Lambda functions are indeed my use case.
Let me see if I can make it work by the next release.
Just released v0.14.0 and this feature is now implemented.