Repository navigation
refactor(web): collapse the to_dict isinstance chain in _parse_web_class_objects - #2086
Merged
Merged
Conversation
…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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. |
mwbrooks
approved these changes
Nov 26, 2026
mwbrooks
left a comment
Member
There was a problem hiding this comment.
✅ 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): |
Member
There was a problem hiding this comment.
praise: Love that these edge-case tests pass on main first, so the guard on metadata is pinned before the refactor touches it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request collapses the six
isinstancebranches in_parse_web_class_objects' nestedto_dictinto one tuple check over the same six types.obj.to_dict(), so order never mattered.metadataguard's threeisinstancecalls become one tuple too (one step past the six branches). The guard stays, so aBlockpassed asmetadatais still not converted.JsonObjectorhasattr(obj, "to_dict"), which would start converting other objects.Testing
New tests in
test_internal_utils.pypin the edge cases and pass onmainbefore the refactor:Metadata,EntityMetadata, andEventAndEntityMetadatainmetadatabecome theirto_dict()(the last two had no unit test).DividerBlock), inmetadatais kept as the same instance.JsonObjectoutside the six types (PlainTextObject) inblocksis kept as the same instance; aChunkinblocksis converted.Each riskier rewrite fails one of them: widening to
hasattr(obj, "to_dict"), droppingEntityMetadataorEventAndEntityMetadata, or dropping themetadataguard.Category
/docs(Documents)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.🤖 Generated with Claude Code