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