Skip to content

refactor(web): remove unreachable resp checks from the async request loop - #2085

Merged
WilliamBergamin merged 2 commits into
mainfrom
refactor/async-request-unreachable-resp
Nov 26, 2026
Merged

WilliamBergamin merged 2 commits into
mainfrom
refactor/async-request-unreachable-resp

Conversation

@WilliamBergamin

Copy link
Copy Markdown
Contributor

Summary

This pull request removes unreachable code from the async _request_with_session retry loop.

  • Cause: resp is declared None and never assigned, so if resp is not None: return resp never runs.
  • The trailing return response after the try/finally is unreachable too: the try body always returns or raises.
  • raise last_error is kept exactly as is. The sync client, webhook, audit_logs, and scim all assign resp, so their checks are live and untouched.

No behavior change, no generated code changes.

Testing

Nothing in slack_sdk/web/async_internal_utils.py assigns resp (grep -n "resp�" slack_sdk/web/async_internal_utils.py). The existing async web client and retry tests cover the loop; mypy accepts the function ending in raise.

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I have signed the Salesforce CLA (required before your PR can be reviewed or merged).
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

🤖 Generated with Claude Code

…loop

`resp` in `_request_with_session` is declared `None` and never assigned,
so `if resp is not None: return resp` never runs. The trailing
`return response` after the try/finally is unreachable too: the try body
always returns or raises. `raise last_error` is kept as is.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@WilliamBergamin
WilliamBergamin requested a review from a team as a code owner November 26, 2026 17:25
@WilliamBergamin WilliamBergamin added this to the 3.48.1 milestone Nov 26, 2026
@WilliamBergamin WilliamBergamin added enhancement M-T: A feature request for new functionality semver:patch web-client area:async labels Nov 26, 2026
@WilliamBergamin WilliamBergamin self-assigned this Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.79%. Comparing base (87d7305) to head (c8470c9).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2085      +/-   ##
==========================================
+ Coverage   84.78%   84.79%   +0.01%     
==========================================
  Files         118      118              
  Lines       14132    14129       -3     
==========================================
- Hits        11982    11981       -1     
+ Misses       2150     2148       -2     

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

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ Thanks @WilliamBergamin, nice tidy-up and the PR body made the dead paths easy to verify.


if resp is not None:
return resp
raise last_error # type: ignore[misc]

@mwbrooks mwbrooks Nov 26, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thought: After 100 response-driven retries (say a handler that keeps retrying 429s), last_error is still None here and this raises a TypeError, while the sync client returns its last resp. Not from this PR, but it could make a good follow-up to bring the two in line.

@WilliamBergamin
WilliamBergamin merged commit d5492a5 into main Nov 26, 2026
19 checks passed
@WilliamBergamin
WilliamBergamin deleted the refactor/async-request-unreachable-resp branch November 26, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:async enhancement M-T: A feature request for new functionality semver:patch web-client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants