Skip to content

refactor(web): collapse the to_dict isinstance chain in _parse_web_class_objects - #2086

Merged
WilliamBergamin merged 1 commit into
mainfrom
refactor/web-class-objects-isinstance
Nov 26, 2026
Merged

WilliamBergamin merged 1 commit into
mainfrom
refactor/web-class-objects-isinstance

Conversation

@WilliamBergamin

Copy link
Copy Markdown
Contributor

Summary

This pull request collapses the six isinstance branches in _parse_web_class_objects' nested to_dict into one tuple check over the same six types.

  • Every branch returned obj.to_dict(), so order never mattered.
  • The metadata guard's three isinstance calls become one tuple too (one step past the six branches). The guard stays, so a Block passed as metadata is still not converted.
  • The type set is unchanged: not widened to JsonObject or hasattr(obj, "to_dict"), which would start converting other objects.

Testing

New tests in test_internal_utils.py pin the edge cases and pass on main before the refactor:

  • Metadata, EntityMetadata, and EventAndEntityMetadata in metadata become their to_dict() (the last two had no unit test).
  • A dict, or a non-metadata object (DividerBlock), in metadata is kept as the same instance.
  • A JsonObject outside the six types (PlainTextObject) in blocks is kept as the same instance; a Chunk in blocks is converted.

Each riskier rewrite fails one of them: widening to hasattr(obj, "to_dict"), dropping EntityMetadata or EventAndEntityMetadata, or dropping the metadata guard.

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

…ass_objects

The nested to_dict had six isinstance branches that all returned
obj.to_dict(); one tuple isinstance over the same six types does the
same. The metadata guard's three isinstance calls become one tuple too.

New tests pin the edge cases first: each metadata type converts, a dict
or a non-metadata object in metadata is kept as is, and an object outside
the six types (PlainTextObject) in blocks is kept as the same instance.

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 tests M-T: Testing work only semver:patch web-client 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.78%. Comparing base (838e3e4) to head (5465af8).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2086   +/-   ##
=======================================
  Coverage   84.78%   84.78%           
=======================================
  Files         118      118           
  Lines       14142    14132   -10     
=======================================
- Hits        11990    11982    -8     
+ Misses       2152     2150    -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.

✅ Appreciate this one @WilliamBergamin, six branches down to one tuple and the behaviour stays exactly the same.

_parse_web_class_objects(kwargs)
assert kwargs["metadata"] is metadata

def test_keeps_non_metadata_objects_in_metadata(self):

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.

praise: Love that these edge-case tests pass on main first, so the guard on metadata is pinned before the refactor touches it.

@WilliamBergamin
WilliamBergamin merged commit 87d7305 into main Nov 26, 2026
19 checks passed
@WilliamBergamin
WilliamBergamin deleted the refactor/web-class-objects-isinstance branch November 26, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality semver:patch tests M-T: Testing work only web-client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants