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

feat: top level functions #3755

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

feat: top level functions #3755

wants to merge 10 commits into from

Conversation

dmadisetti
Copy link
Collaborator

@dmadisetti dmadisetti commented Feb 11, 2025

📝 Summary

Adds top level functions

  • @app.fn (but maybe app.function is better) to wrap functions, register them but leave them directly exposed
  • Serialize to @app.fn if there are no dependencies

Just an intro PR for #2293

For completion of 2293, I think out standing changes are:

  • some UI aspect (maybe a new language toggle?)
  • Top level imports
  • Looser requirements for serialization (can use imports and other app.fns)

But this is hidden under App(_toplevel_fn=True)

🔍 Description of Changes

see the smoke test or:

@app.fn
def self_ref_fib(n: int) -> int:
    if n == 0:
        return 0
    if n == 1:
        return 1
    return self_ref_fib(n - 1) + self_ref_fib(n - 2)


@app.fn(disabled=True, hide_code=True)
def divide(x, y):
    return y / x


@app.fn
def subtraction(a: "int", b: "int") -> "int":
    return a - b


@app.fn
# Comments inbetween
def multiply(a, b) -> "int":
    return a * b


@app.fn
def addition(a: int, b: int) -> int:
    # int is considered no good, re-eval
    return a + b

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • I have added tests for the changes made.
  • I have run the code and verified that it works as expected.

📜 Reviewers

@akshayka OR @mscolnick

Copy link

vercel bot commented Feb 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 4:23am
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 4:23am

akshayka
akshayka previously approved these changes Feb 12, 2025
Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent. Saw the attention to detail with preserving comments in various locations — between the decorator invocation and function def, in the function body ... and really appreciate that. My only note is what you already called out, to rename app.fn to app.function.

akshayka
akshayka previously approved these changes Feb 12, 2025
Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! LGTM modulo failing tests, looks like just snapshots that need to be updated.

@akshayka
Copy link
Contributor

Weird, no idea what these failures are. They don't seem related ...

FAILED tests/_server/api/endpoints/test_execution.py::TestExecutionRoutes_EditMode::test_app_meta_request - KeyError: 'test-1'
FAILED tests/_server/test_sessions.py::test_kernel_manager_interrupt - assert False
 +  where False = empty()
 +    where empty = <multiprocessing.queues.Queue object at 0x0000028EAF598A60>.empty
 +      where <multiprocessing.queues.Queue object at 0x0000028EAF598A60> = <marimo._server.sessions.QueueManager object at 0x0000028EAF5983D0>.control_queue
= 2 failed, 2157 passed, 217 skipped, 82 deselected, 18 xfailed, 4 xpassed, 7 warnings in 298.97s (0:04:58) =

@akshayka
Copy link
Contributor

akshayka commented Feb 12, 2025

I'm also unable to reproduce the test_export_markdown failure, and we're also seeing it in other branches, so that seems unrelated.

On the surface it feels like it would be related to this PR, but I also see it failing in another PR ... https://github.com/marimo-team/marimo/actions/runs/13278229043/job/37071591905?pr=3760

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

Successfully merging this pull request may close these issues.

2 participants