-
Notifications
You must be signed in to change notification settings - Fork 323
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
docstring support #719
Comments
Thanks for taking the time to write such a thoughtful feature request. Re: rendering docstrings as markdown We may be able to support something like this; an implementation quirk of our runtime is that cells are represented as just a block of code, not wrapped in a function ... but we could keep them as functions, which would let us easily access the docstring and include it as part of the cell's output. Stepping back, as a user, which would you prefer: rendering docstrings as markdown, or a WISYWIG markdown editor? |
I thought about this recently because I have the pattern @app.cell
def _my_fn(np, other_libs):
def fn(a,b,c):
"""doc string"""
# logic
return whatever
return fn and then in my def unwrap_mo(fn):
return fn()
from notebook import _my_fn
my_fn = unwrap(_my_fn) to enable easier importing from another notebook and using fn directly. Proposal for less friction: @app.fn
def my_fn(a, b, c, *, np, other_libs): # Abuse * to separate user vs graph arguments
"""doc string"""
# logic
return whatever Which is much cleaner than the nested functions for off editor changes. Implementation-wise, assertions
|
Description
Please render Python docstrings in cells as Markdown above the cell.
"The functions in this cell..."
I'm coming to Marimo as an old time Python programmer. I'm loving the predictable execution order—thanks!—but it feels odd to have to create dedicated cells to provide narrative text before some code.
Python, you see, has long provided a method for exactly this purpose: the humble docstring (Pandas docs).
Please render my docstrings as Markdown above the code whenever the code is hidden.
Suggested solution
I dug into the
app.cell
decorator, and confirmed it could take the function's docstring and put it somewhere useful. I tried hacking it in as a replacement for an emptylast_expr
, but that's a terrible idea. What if you need both? You'll know what to do. It might even be quick, and fun.Alternative
Marimo could support plain Markdown cells with always-hidden code, provide a WYSIWYG editor for them, and provide an upgrade path by spotting the characteristic shape of the older way of doing it:
That's has less of your "everything you type is Python" vibe, though.
Additional context
If you put a string at the top of a Python file, that string becomes that module's documentation, available as
__doc__
. You'll see it if you runhelp
on the REPL, and it's the basis for the automatically rendered docs for the Python standard library and other Python packages.You can also get to it from inside your Python code:
The same is true of a function:
Ruff's Black-compatible formatter can handle Markdown fenced code in docstrings as of astral-sh/ruff#9030. So, this change would go particularly well with #546 to cover the edge case of someone putting Python code in their Python docstrings.
The MyST Markdown parser includes support for LaTeX markup for math and equations, and can be used across any project's documentation including its docstrings with sphinx-autodoc2's autodoc2-docstring and other supported extensions. Imagine, out of the box, being able to type the following into the top of a cell:
… and have it come out like this:
The text was updated successfully, but these errors were encountered: