[Python] Remove all to_js usage from bindings examples
Summary
Removes remaining pyodide.ffi.to_js usage from workers bindings documentation. Python workers team has improved the SDK so that users does not have to manually convert Python objects into JS-serializable object before passing to RPC boundary.
Screenshots (optional)
Documentation checklist
- [x] The change adheres to the documentation style guide.
Review
🚨 1 critical, ⚠️ 5 warnings, 💡 2 suggestions found in commit 0ef25e0.
Code Review
This code review is in beta and may not always be helpful — use your judgment.
Critical (1)
| File | Issue |
|---|---|
workers/examples/modify-request-property.mdx line 191 |
Invalid Response API in Python example — Line 191 returns Response.join({"error": str(e)}, status=500), but Response.join is not a valid Response constructor or factory method in the Python Workers environment. The equivalent JavaScript/TypeScript examples use new Response(...). Fix: Replace Response.join(...) with the correct Python Workers Response constructor, such as Response(json.dumps({"error": str(e)}), status=500) or Response.new(json.dumps({"error": str(e)}), status=500), matching the environment's actual API. |
Warnings (5)
| File | Issue |
|---|---|
workers/examples/cors-header-proxy.mdx line 563 |
Response status lost when recreating response — Response(response.body, headers=dict(response.headers)) constructs a new Response without copying the upstream status or status_text, so any non-200 response from the proxied API will be rewritten as 200 OK. Fix: Pass the original status and status text when reconstructing the response, e.g. Response(response.body, status=response.status, status_text=response.status_text, headers=response.headers). |
workers/examples/cache-using-fetch.mdx line 154 |
Reconstructed Response drops upstream status — Python rebuilds the response with only headers=dict(response.headers), so the upstream HTTP status code and status text default to 200/OK. The JavaScript equivalent passes the original response object as the init argument, which also carries over status and statusText. Fix: Forward the original status and status text when constructing the new Response, e.g. Response(response.body, status=response.status, status_text=response.status_text, headers=dict(response.headers)), using the attribute names exposed by the Python runtime. |
workflows/python/bindings.mdx line 103 |
Mixed tabs and spaces in Python example — The added comment line begins with three tab characters (\t\t\t) while the surrounding async def fetch body and the following instances = [ line use spaces. Python raises TabError: inconsistent use of tabs and spaces in indentation for this block. Fix: Replace the leading tabs on line 103 with 8 spaces so the comment aligns with the rest of the method body. |
workers/examples/cache-tags.mdx line 169 |
Unhandled fetch failure — The awaited fetch(url, cf={"cacheTags": tags}) has no error handling. If the upstream request fails or the URL is invalid, the exception propagates instead of returning a JSON 500 response like the JavaScript and Hono tabs. Fix: Wrap the fetch call in a try/except and return Response.json({"error": ...}, status=500) on failure, matching the other language tabs. |
workers/languages/python/examples.mdx line 151 |
Inconsistent indentation in Python example — The added comment line in the 'Publish to a Queue' example is indented with tab characters (\t\t\t) while the surrounding method body uses spaces. Copying the snippet will cause Python to raise a TabError/IndentationError. Fix: Replace the leading tabs with 8 spaces so the comment matches the surrounding fetch body indentation. |
Suggestions (2)
| File | Issue |
|---|---|
catalog-models/google-gemini-3-flash.json line 365 |
Unrelated file change in Python PR — The PR title and branch describe a Python bindings change ('[Python] Remove all to_js usage from bindings examples'), but this file is an AI model catalog JSON whose added lines define JSON schemas for a Google Gemini model. Fix: Confirm whether this catalog-model update is intentional for this PR; if not, move it to a separate PR or revert the change. |
astro.config.ts line 310 |
Vite server config clobbers nimbus target settings — The vite.server block is declared after spreading nimbus.vite, so any server property exported by the Nimbus config would be replaced rather than merged with the watch ignore patterns. Fix: Merge nimbus.vite.server with the new watch.ignored list (for example via a deep merge) or document that Nimbus cannot configure dev server options. |
Conventions
Checks PR title, description, and redirect checklist.
No convention issues found.
Style Guide Review
No style-guide issues found.
Redirects
No missing redirect entries found.
Commands
Only codeowners can run commands. Post a comment with the command to trigger it.
| Command | Description |
|---|---|
/review |
Runs a review now. Incremental if a prior review exists, full if not. |
/full-review |
Re-reviews the entire PR diff from scratch, ignoring incremental history. Useful after a rebase, when you want a fresh review, or if the bot gets out of sync and reports issues that no longer exist. |
/ignore-review-limit |
Permanently lifts the 2-review automatic limit for this PR. Future pushes will trigger reviews as normal. |
/disable-auto-review |
Stops automatic reviews from triggering on future pushes to this PR. Codeowners can still run /review or /full-review manually. |
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
| Pattern | Owners |
|---|---|
/src/content/docs/queues/ |
@elithrar, @jonesphillip, @harshil1712, @mia303, @cloudflare/product-owners |
/src/content/docs/workers/ |
@cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/product-owners, @cloudflare/wrangler, @MattieTK, @cloudflare/dev-plat-leads, @vy-ton |
/src/content/docs/workflows/ |
@elithrar, @rita3ko, @irvinebroque, @vy-ton, @celso, @deloreyj, @mia303, @jonesphillip, @cloudflare/product-owners |
Preview URL: https://0ef25e01.preview.developers.cloudflare.com Preview Branch URL: https://python-workers-ga-to-js-removal.preview.developers.cloudflare.com
Files with changes (up to 15)