fix(openai): remove return from finally blocks to fix SyntaxWarning on Python 3.14#3972
fix(openai): remove return from finally blocks to fix SyntaxWarning on Python 3.14#3972RRocaP wants to merge 1 commit intotraceloop:mainfrom
Conversation
…n Python 3.14 Move return statements out of finally blocks in ResponseStream.close() and ResponseStream.aclose(). Python 3.14 emits SyntaxWarning for return inside finally, because the return silently discards any pending exception. The cleanup (_ensure_cleanup) is idempotent and already guarded by a lock, so running it in try with an empty finally and then returning the wrapped method's result achieves the same behavior without the warning. Fixes traceloop#3969
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe changes refactor the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #3969
Python 3.14 emits
SyntaxWarning: 'return' in a 'finally' blockforResponseStream.close()andResponseStream.aclose()inresponses_wrappers.py.Problem
returninside afinallyblock silently discards any pending exception,which Python 3.14 now warns about:
Fix
Move the
returnstatements out of thefinallyblock. Since_ensure_cleanup()is idempotent and lock-guarded, this isbehaviorally equivalent — cleanup runs first, then the wrapped
stream's close/aclose is called.
Files changed
packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/responses_wrappers.pyTest plan
SyntaxWarningon Python 3.14Summary by CodeRabbit