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

Add support for semicolon output suppression #3806

Closed

Conversation

devin-ai-integration[bot]
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Feb 14, 2025

Implements #3726

  • Added support for semicolon (;) to suppress output on the last line of a cell
  • Simplified implementation by setting last_expr to None in compiler
  • Added tests to verify expression behavior
  • Reduced code complexity by removing output suppression flag

Link to Devin run: https://app.devin.ai/sessions/0eeb86c476d34187b3e2f2cb80edc3d6

Co-Authored-By: Myles Scolnick <myles@marimo.io>
Copy link

vercel bot commented Feb 14, 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 14, 2025 9:46pm
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 14, 2025 9:46pm

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

pre-commit-ci bot and others added 6 commits February 14, 2025 21:22
Co-Authored-By: Myles Scolnick <myles@marimo.io>
Co-Authored-By: Myles Scolnick <myles@marimo.io>
Co-Authored-By: Myles Scolnick <myles@marimo.io>
Co-Authored-By: Myles Scolnick <myles@marimo.io>
Co-Authored-By: Myles Scolnick <myles@marimo.io>
devin-ai-integration bot and others added 2 commits February 14, 2025 21:32
Co-Authored-By: Myles Scolnick <myles@marimo.io>
Co-Authored-By: Myles Scolnick <myles@marimo.io>
Co-Authored-By: Myles Scolnick <myles@marimo.io>
expr.end_col_offset = final_expr.end_col_offset
expr = ast.Expression(const)
# Creating an expression clears source info, so it needs to be set back
expr.lineno = getattr(const, "lineno", 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be indented

return await EXECUTION_TYPES[execution_type].execute_cell_async(
cell, glbls, graph
)
executor = EXECUTION_TYPES[execution_type]()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unneeded churn

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I see. Yeah, it's reasonable to put the change here.
But just setting last expr to None seems ideal. More execution types will require more churn and meta data ferrying.

devin-ai-integration bot and others added 2 commits February 14, 2025 21:41
Co-Authored-By: Myles Scolnick <myles@marimo.io>
Co-Authored-By: Myles Scolnick <myles@marimo.io>
[
exec_req.get(
"""
x = 3; # comment
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tests don't actually capture the intended behavior.

3;

But assignment expression would return anything anyway

result = eval(cell.last_expr, glbls)
if cell.suppress_output:
return None
return result if result is not None else None
Copy link
Collaborator

Choose a reason for hiding this comment

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

but why?

Copy link
Collaborator

@dmadisetti dmadisetti left a comment

Choose a reason for hiding this comment

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

Not fully certain how devin works - but hopefully this review gets picked up. Automated unit tests creation is cool itself

Comment on lines +47 to +52
lines = code.strip().split("\n")
for line in reversed(lines):
line = line.split("#")[0].strip()
if line:
return line.endswith(";")
return False
Copy link
Collaborator

@dmadisetti dmadisetti Feb 14, 2025

Choose a reason for hiding this comment

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

Suggested change
lines = code.strip().split("\n")
for line in reversed(lines):
line = line.split("#")[0].strip()
if line:
return line.endswith(";")
return False
tokens = tokenize(io.BytesIO(code.strip().encode("utf-8").readline)
for token in reversed(list(tokens)):
if token.type in (token_types.ENDMARKER, token_types.NEWLINE, token_types.COMMENT):
continue
return token.string == ";"
return False

@@ -226,6 +245,7 @@ def compile_cell(
body=body,
last_expr=last_expr,
cell_id=cell_id,
suppress_output=ends_with_semicolon(code),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
suppress_output=ends_with_semicolon(code),

@@ -141,18 +161,17 @@ def compile_cell(
final_expr = module.body[-1]
if isinstance(final_expr, ast.Expr):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if isinstance(final_expr, ast.Expr):
# Supress expression if ends in semi colon
if isinstance(final_expr, ast.Expr) and not ends_with_semicolon(code):

Comment on lines +167 to +174
setattr(const, "col_offset", final_expr.end_col_offset)
setattr(const, "end_col_offset", final_expr.end_col_offset)
setattr(const, "lineno", len(code.splitlines()) + 1)
expr = ast.Expression(const)
# use code over body since lineno corresponds to source
const.lineno = len(code.splitlines()) + 1
expr.lineno = const.lineno
# Creating an expression clears source info, so it needs to be set back
expr.col_offset = final_expr.end_col_offset
expr.end_col_offset = final_expr.end_col_offset
# Creating an expression clears source info, so it needs to be set back
setattr(expr, "lineno", getattr(const, "lineno", 0))
setattr(expr, "col_offset", final_expr.end_col_offset)
setattr(expr, "end_col_offset", final_expr.end_col_offset)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Undo the changes here, still a bad block

return await EXECUTION_TYPES[execution_type].execute_cell_async(
cell, glbls, graph
)
executor = EXECUTION_TYPES[execution_type]()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would revert changes for full file

@@ -0,0 +1,67 @@
from tests.conftest import ExecReqProvider, MockedKernel
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would run tests over in tests/_ast/compiler.py (since no longer a executor change)

Try

1
1;
expression = 1;
1;2;3;4
1;2;3;4;
1; # Has a comment
1 # Has a comment;
mo.md("# splits on # are less than ideal") # Contains a #
mo.md("# splits on # are less than ideal"); # Contains a #

and ensure expr is const None in the ";" cases

Comment on lines +160 to +161
# Whether to suppress output for this cell
suppress_output: bool = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Whether to suppress output for this cell
suppress_output: bool = False

Copy link
Contributor Author

Devin is currently unreachable - the session may have died.

2 similar comments
Copy link
Contributor Author

Devin is currently unreachable - the session may have died.

Copy link
Contributor Author

Devin is currently unreachable - the session may have died.

Copy link
Contributor Author

Devin is currently unreachable - the session may have died.

3 similar comments
Copy link
Contributor Author

Devin is currently unreachable - the session may have died.

Copy link
Contributor Author

Devin is currently unreachable - the session may have died.

Copy link
Contributor Author

Devin is currently unreachable - the session may have died.

@mscolnick
Copy link
Contributor

@dmadisetti thanks for reviewing it. usually i don't try to give it PR comments (although you totally could). if it gets close enough on the first try I'll use it, otherwise I just close the PR and do it myself or build on top of it.

@dmadisetti
Copy link
Collaborator

Closed for #3830

@dmadisetti dmadisetti closed this Feb 18, 2025
mscolnick pushed a commit that referenced this pull request Feb 18, 2025
## 📝 Summary

Replaces #3806 

## 🔍 Description of Changes

Resolves #3726

@mscolnick

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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