Skip to content

Fix PEP-765 violation: return in finally block#10092

Merged
hssyoo merged 1 commit intoaws:developfrom
abhu85:fix/pep-765-return-in-finally-9985
Mar 3, 2026
Merged

Fix PEP-765 violation: return in finally block#10092
hssyoo merged 1 commit intoaws:developfrom
abhu85:fix/pep-765-return-in-finally-9985

Conversation

@abhu85
Copy link
Copy Markdown
Contributor

@abhu85 abhu85 commented Feb 19, 2026

Summary

This PR fixes the PEP-765 violation reported in #9985 by moving the return True statement outside of the finally block in LocalDeleteRequestSubmitter._submit_transfer_request().

Problem

Python 3.14 (per PEP-765) emits a SyntaxWarning for return, break, or continue statements directly within finally blocks. The current code has:

finally:
    # Return True to indicate that the transfer was submitted
    return True

Solution

Move the return True after the try-except block. This preserves the exact same behavior (always returning True regardless of success or failure) while avoiding the warning.

Behavior Verification

  • The function always returns True to indicate the transfer was submitted
  • Success: queues QueuedResult and SuccessResult, then returns True
  • Failure: queues QueuedResult and FailureResult, then returns True

Both existing tests (test_submit and test_submit_with_exception) verify this behavior and pass.

Test Plan

  • All 5 existing TestLocalDeleteRequestSubmitter tests pass
  • Verified no SyntaxWarning when importing the module
  • Verified the AST check finds no remaining PEP-765 violations in awscli/
$ python -m pytest tests/unit/customizations/s3/test_s3handler.py::TestLocalDeleteRequestSubmitter -v
# 5 passed

Fixes #9985

Move `return True` outside of the `finally` block in
LocalDeleteRequestSubmitter._submit_transfer_request() to comply with
PEP-765 recommendations. This change preserves the exact same behavior
(always returning True regardless of success or failure) while avoiding
the SyntaxWarning that Python 3.14 emits for return statements in
finally blocks.

Fixes aws#9985

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hssyoo hssyoo self-requested a review February 27, 2026 19:53
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.40%. Comparing base (c4681b5) to head (2c2b226).
⚠️ Report is 156 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #10092      +/-   ##
===========================================
+ Coverage    93.39%   93.40%   +0.01%     
===========================================
  Files          210      210              
  Lines        17052    17139      +87     
===========================================
+ Hits         15925    16009      +84     
- Misses        1127     1130       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@hssyoo hssyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hssyoo hssyoo merged commit af63d59 into aws:develop Mar 3, 2026
48 checks passed
@abhu85 abhu85 deleted the fix/pep-765-return-in-finally-9985 branch March 3, 2026 15:17
aws-sdk-python-automation added a commit that referenced this pull request Mar 3, 2026
* release-1.44.50:
  Bumping version to 1.44.50
  Update changelog based on model updates
  Fix PEP-765 violation: return in finally block (#10092)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source coude doesn't follow PEP-765 recommendations

4 participants