Skip to content

Conversation

@adhami3310
Copy link
Member

No description provided.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 28, 2025

CodSpeed Performance Report

Merging #5936 will not alter performance

Comparing fix-problems-with-does_obj_satisfy_typed_dict (15de11c) with main (c4254ed)

Summary

✅ 8 untouched

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

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, and treat_mutable_obj_as_immutable parameters
  • 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=False and total=True scenarios

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
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@adhami3310 adhami3310 merged commit 9661561 into main Oct 30, 2025
57 of 59 checks passed
@adhami3310 adhami3310 deleted the fix-problems-with-does_obj_satisfy_typed_dict branch October 30, 2025 20:11
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.

3 participants