SyntaxWarning: 'return' in a 'finally' block (Python 3.14)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 70/100
Línea de trabajo
Comienza en datadog_lambda/wrapper.py, en _LambdaDecorator.call, e inspecciona el flujo de control try/except/finally, especialmente el return indicado en la línea 203. Verifica las cuatro rutas de ejecución descritas en el issue y añade o actualiza las pruebas para que la importación en Python 3.14 no emita ningún SyntaxWarning, mientras las respuestas bloqueantes y normales sigan siendo correctas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 102
- Forks
- 52
- Merge medio
- 5 d 19 h
- PR fusionados (30 d)
- 2
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de DataDog/datadog-lambda-python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
DataDog/datadog-lambda-python#755 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
DataDog/datadog-lambda-python#688 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
DataDog/datadog-lambda-python#682 · 1 comentario ·
-
Migrate from ujson to orjson Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
DataDog/datadog-lambda-python#666 · 1 reacción ·
-
DataDog/datadog-lambda-python#633 · 2 comentarios · 1 asignado ·
Todos los issues de DataDog/datadog-lambda-python
Issues similares
-
sponsored
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
opensubtitlescom: moviehash never sent when opensubtitles (.org) is not in the provider list Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
Diaoul/subliminal#1382 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
triage/confirmed
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
agentscope-ai/agentscope#2775 ·
-
worker.gpuVendors silently accepts unsupported/misspelled vendor names — no validation guard Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100