SyntaxWarning: 'return' in a 'finally' block (Python 3.14)
還沒有人認領這個 Issue。
評估
研究方向
從 datadog_lambda/wrapper.py 中的 _LambdaDecorator.call 開始,檢查 try/except/finally 控制流程,尤其是第 203 行回報的 return。驗證 issue 中描述的四條執行路徑,並新增或更新測試,以確保在 Python 3.14 中匯入時不會發出 SyntaxWarning,同時阻塞回應和正常回應仍然正確。
由索引模型根據 Issue 內容生成。
描述
Expected Behavior
No warnings emitted during Lambda cold start when importing datadog_lambda.
Actual Behavior
A SyntaxWarning is emitted at module import time (cold start) on Python 3.14:
/var/task/datadog_lambda/wrapper.py:203: SyntaxWarning: 'return' in a 'finally' block
return self.blocking_response
This warning fires every cold start and pollutes CloudWatch logs. Python 3.14 introduced SyntaxWarning for return/break/continue inside finally blocks because such a return silently suppresses any exception that was actively propagating through the try/except.
Steps to Reproduce the Problem
- Deploy a Lambda function using
datadog-lambdaon the Python 3.14 runtime - Trigger a cold start (first invocation or new sandbox)
- Observe the
SyntaxWarningin CloudWatch logs duringINIT_START
Specifications
- Datadog Lambda Library version: 8.123.0
- Python version: 3.14
Root Cause
In _LambdaDecorator.__call__, the finally block contains a return:
finally:
self._after(event, context)
if self.blocking_response:
return self.blocking_response # ← triggers SyntaxWarning in Python 3.14
Proposed Fix
Remove return self.response from the try block and return self.blocking_response from the finally block, deferring both to after the entire try/except/finally:
try:
if self.blocking_response:
return self.blocking_response
self.response = self.func(event, context, **kwargs)
except BlockingException:
self.blocking_response = get_asm_blocked_response(self.event_source)
except Exception:
...
raise
finally:
self._after(event, context)
if self.blocking_response:
return self.blocking_response
return self.response
All four execution paths (block before, block during, block after, normal) remain correct. Happy to open a PR with this fix and updated tests.
Stacktrace
/var/task/datadog_lambda/wrapper.py:203: SyntaxWarning: 'return' in a 'finally' block
return self.blocking_response
- 主要語言
- Python
- 星號
- 102
- 分支
- 52
- 平均合併
- 5 天 19 小時
- 30 天內合併 PR
- 2
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
DataDog/datadog-lambda-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
DataDog/datadog-lambda-python#755 ·
-
難度 4/5 3-5 天 新手友好度 30/100
DataDog/datadog-lambda-python#688 ·
-
難度 4/5 3-5 天 新手友好度 35/100
DataDog/datadog-lambda-python#682 · 1 則留言 ·
-
難度 3/5 1-2 天 新手友好度 45/100
DataDog/datadog-lambda-python#666 · 1 個 reaction ·
-
DataDog/datadog-lambda-python#633 · 2 則留言 · 已指派 1 人 ·
查看 DataDog/datadog-lambda-python 的全部 Issue
相似的 Issue
-
documentation help wanted
難度 2/5 1-3 小時 新手友好度 90/100
-
難度 2/5 1-3 小時 新手友好度 90/100
simonw/sqlite-utils#872 ·
-
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 82/100
-
難度 2/5 1-3 小時 新手友好度 78/100