Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Doc String #44

Open
mhumpher opened this issue Apr 26, 2021 · 4 comments
Open

Setting Doc String #44

mhumpher opened this issue Apr 26, 2021 · 4 comments

Comments

@mhumpher
Copy link

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.

@fumitoh
Copy link
Owner

fumitoh commented Apr 27, 2021

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.

@mhumpher
Copy link
Author

Thanks. Lambda functions are indeed my use case.

@fumitoh
Copy link
Owner

fumitoh commented Apr 27, 2021

Let me see if I can make it work by the next release.

@fumitoh fumitoh added this to the v0.14.0 milestone Apr 27, 2021
@fumitoh
Copy link
Owner

fumitoh commented May 2, 2021

Just released v0.14.0 and this feature is now implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants