Skip to content

Conversation

Bastian-Krause
Copy link
Member

Description
Exceptions in finally clauses containing return statements are swallowed [1]. That means any exception raised in the try block and a subsequent KeyError in the finally block leads to the original exception being swallowed.

Since Python 3.14 "the compiler emits a SyntaxWarning when a return, break or continue appears in a finally block (see PEP 765)." [2].

Fix this by moving the code relying on the session into the try clause making the return in the except clause obsolete.

[1] https://peps.python.org/pep-0765/#motivation
[2] https://docs.python.org/3.14/reference/compound_stmts.html#finally-clause

Checklist

  • PR has been tested

Fixes #1469

Exceptions in finally clauses containing return statements are
swallowed [1]. That means any exception raised in the try block and a
subsequent KeyError in the finally block leads to the original exception
being swallowed.

Since Python 3.14 "the compiler emits a SyntaxWarning when a return,
break or continue appears in a finally block (see PEP 765)." [2].

Fix this by moving the code relying on the session into the try clause
making the return in the except clause obsolete.

[1] https://peps.python.org/pep-0765/#motivation
[2] https://docs.python.org/3.14/reference/compound_stmts.html#finally-clause

Signed-off-by: Bastian Krause <[email protected]>
@Bastian-Krause Bastian-Krause requested a review from jluebbe August 28, 2025 13:07
@Bastian-Krause Bastian-Krause added fix pick to stable Needs a pick to the latest stable branch labels Aug 28, 2025
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.6%. Comparing base (ae2f2a5) to head (11dc2c4).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/remote/coordinator.py 0.0% 7 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1722   +/-   ##
======================================
  Coverage    55.6%   55.6%           
======================================
  Files         172     172           
  Lines       13495   13493    -2     
======================================
  Hits         7514    7514           
+ Misses       5981    5979    -2     
Flag Coverage Δ
3.10 55.6% <0.0%> (+<0.1%) ⬆️
3.11 55.6% <0.0%> (+<0.1%) ⬆️
3.12 55.6% <0.0%> (+<0.1%) ⬆️
3.13 55.6% <0.0%> (+<0.1%) ⬆️
3.9 55.7% <0.0%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Bastian-Krause Bastian-Krause mentioned this pull request Aug 28, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix pick to stable Needs a pick to the latest stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant