fix problems with does_obj_satisfy_typed_dict#5936
Merged
adhami3310 merged 1 commit intomainfrom Oct 30, 2025
Merged
Conversation
CodSpeed Performance ReportMerging #5936 will not alter performanceComparing Summary
|
Contributor
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
Fixed a critical bug in does_obj_satisfy_typed_dict where required key validation always returned True due to checking required_keys.issubset(required_keys) instead of required_keys.issubset(frozenset(obj)).
- Fixed the required keys validation logic at reflex/utils/types.py:689
- Added support for nested type checking with new
nested,treat_var_as_type, andtreat_mutable_obj_as_immutableparameters - Implemented PEP 728 TypedDict features:
__closed__and__extra_items__attributes for better type validation - Enhanced nested validation to recursively check dictionary values against their expected types
- Added comprehensive test coverage for TypedDict validation with both
total=Falseandtotal=Truescenarios
Confidence Score: 5/5
- This PR is safe to merge with minimal risk - it fixes a critical bug and adds proper test coverage.
- The PR addresses a clear bug where required key validation was broken (always returning True). The fix is straightforward and correct. All changes are well-tested with comprehensive test cases covering edge cases. The new functionality for PEP 728 support is implemented correctly with proper handling of closed TypedDicts and extra items.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| reflex/utils/types.py | 5/5 | Fixed critical bug in does_obj_satisfy_typed_dict where required keys validation always returned True. Added support for nested type checking and PEP 728 TypedDict features (__closed__, __extra_items__). |
| tests/units/utils/test_types.py | 5/5 | Added comprehensive test cases for TypedDict validation covering both total=False and total=True scenarios, including tests for required keys, type validation, and extra keys. |
Sequence Diagram
sequenceDiagram
participant Caller
participant _isinstance
participant does_obj_satisfy_typed_dict
participant get_type_hints
Caller->>_isinstance: Check if obj matches TypedDict
_isinstance->>_isinstance: Check if cls is TypedDict
alt nested > 0
_isinstance->>does_obj_satisfy_typed_dict: Validate with nested checking
does_obj_satisfy_typed_dict->>get_type_hints: Get expected types for keys
loop For each key-value pair in obj
alt is_closed and key not in expected
does_obj_satisfy_typed_dict-->>_isinstance: Return False (extra key in closed dict)
else nested > 0
alt key in expected types
does_obj_satisfy_typed_dict->>_isinstance: Recursively check value type (nested-1)
_isinstance-->>does_obj_satisfy_typed_dict: Return result
else key not in expected
does_obj_satisfy_typed_dict->>_isinstance: Check against extra_items_type (nested-1)
_isinstance-->>does_obj_satisfy_typed_dict: Return result
end
end
end
does_obj_satisfy_typed_dict->>does_obj_satisfy_typed_dict: Verify required_keys ⊆ obj.keys() [BUG FIX]
does_obj_satisfy_typed_dict-->>_isinstance: Return validation result
else nested = 0
_isinstance->>_isinstance: Check if obj is dict
_isinstance-->>Caller: Return basic type check
end
2 files reviewed, no comments
masenf
approved these changes
Oct 30, 2025
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.
No description provided.