Skip to content

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

Open
abhu85 wants to merge 1 commit intoaws:developfrom
abhu85:fix/pep-765-return-in-finally-9985
Open

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

Conversation

@abhu85
Copy link

@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>
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

2 participants

Comments