Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello @acsoto, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue in the Python SDK's Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Superseded by #226 (same change with branch/title/template aligned). Closing this one to avoid confusion. |
There was a problem hiding this comment.
Code Review
This pull request effectively corrects a misleading example regarding session reuse in the Python SDK. By changing the demonstration from in-memory variable persistence (which doesn't work) to file-system persistence, the example now accurately reflects the SDK's behavior. The accompanying updates to comments and documentation are clear and helpful for users. The change is a valuable improvement for the SDK's usability and correctness.
| client2 = CodeInterpreterClient(session_id=session_id, verbose=True) | ||
| result = client2.run_code("python", "print(f'x = {x}')") | ||
| print(f"Result: {result.strip()}") # Should print "x = 42" | ||
| result = client2.run_code("python", "print(open('/tmp/value.txt').read())") |
There was a problem hiding this comment.
While this code works for this simple case, it's a best practice in Python to use a with statement when dealing with files. This ensures the file is properly closed even if errors occur. Using with open(...) is more robust and idiomatic, which is a good pattern to show in an example.
| result = client2.run_code("python", "print(open('/tmp/value.txt').read())") | |
| result = client2.run_code("python", "with open('/tmp/value.txt') as f: print(f.read())") |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #225 +/- ##
==========================================
+ Coverage 35.60% 41.70% +6.09%
==========================================
Files 29 30 +1
Lines 2533 2611 +78
==========================================
+ Hits 902 1089 +187
+ Misses 1505 1390 -115
- Partials 126 132 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
This PR fixes a misleading Python SDK example for session reuse.
The runtime behavior is that each
/api/executeinvocation runs in a fresh process. Reusingsession_idpreserves filesystem state in the same sandbox, but does not preserve in-memory Python variables across separaterun_codecalls.User Impact
Users running
sdk-python/examples/basic_usage.pycould see aNameErrorin the session reuse section (xnot defined) and assume session reuse was broken, even though the actual limitation is process-level execution semantics.Root Cause
The SDK docs and code comments were already clarified in prior work, but
sdk-python/examples/basic_usage.pystill demonstrated variable reuse (x = 42across calls), which contradicted real behavior and the docs.Fix
Updated
sdk-python/examples/basic_usage.pyto demonstrate file-based persistence across reused sessions:/tmp/value.txtin the first client and reading it in the reused client.Validation
python3 -m py_compile sdk-python/examples/basic_usage.pyRelated