Skip to content

Conversation

@peter-gy
Copy link
Contributor

📝 Summary

Consolidate watch_and_export_bytes and watch_and_export implementations & represent ExportResult contents as bytes while still allowing string-based access.

Follow-up of #7997

🔍 Description of Changes

  • Main refactor is making ExportResult represent results as bytes instead of strings to support cases like PDF export
  • Implemented "contents is bytes, text is string" convention familiar from httpx, requests, etc.
  • killed watch_and_export_bytes instead of watch_and_export so that export_callback can keep returning ExportResult objects to (1) avoid duplicating encode / decode logic, (2) have a place for cross-cutting helpers like .text / .from_text and (3) keep the door open for additional metadata like e.g. warnings or execution stats

📋 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).
  • Tests have been added for the changes made.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Pull request title is a good summary of the changes - it will be used in the release notes.
@vercel
Copy link

vercel bot commented Jan 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jan 27, 2026 6:34pm

Request Review

@peter-gy
Copy link
Contributor Author

@mscolnick I deviated from #7997 (comment) in this refactor and kept ExportResult instead of using plain bytes as otherwise we would find ourselves in .encode / .decode duplication hell + no easy way to associate further metadata with results down the line. what do you think?

@dataclass
class ExportResult:
contents: str
contents: bytes
Copy link
Contributor

Choose a reason for hiding this comment

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

there might be a small inefficiency over converting from text to bytes and back. maybe we could do:

contents: bytes | str

with a @property (or @cached_property) for bytes and text that will check the contents type and convert or not convert

Copy link
Contributor Author

@peter-gy peter-gy Jan 27, 2026

Choose a reason for hiding this comment

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

Great point.

To make sure we don't shadow the built-in bytes via a def bytes(self) ...: how about contents: bytes | str and either as_bytes() / as_text() or via cached_property data_bytes / data_text ?

or just bytez? (:

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, great call

@mscolnick mscolnick added internal A refactor or improvement that is not user facing and removed internal A refactor or improvement that is not user facing labels Jan 27, 2026
@mscolnick mscolnick merged commit 47a782d into marimo-team:main Jan 27, 2026
34 of 46 checks passed
@github-actions
Copy link

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.19.7-dev23

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

Labels

None yet

2 participants