fix(vars): treat typing_extensions TypedDict state vars as TypedDicts

CE
6h ago
+68-15

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Fixes #7996

vars/object.py and utils/types.py imported is_typeddict from typing, which returns False for typing_extensions.TypedDict classes on 3.11+ with typing_extensions 4.16. So a var typed with one had Any keys, no error on unknown keys, and _isinstance didn't check the fields. Both modules now use typing_extensions.is_typeddict, which handles both flavors. types.py already called typing_extensions.is_typeddict in a few places, so those now just use the imported name.

Tests:

  • test_typed_dict_key_access runs key access with a typing.TypedDict and a typing_extensions.TypedDict (field types plus VarAttributeError for a missing key)
  • test_isinstance_typing_extensions_typed_dict checks _isinstance against a typing_extensions.TypedDict

The new tests fail on main and pass with the change. ruff and pyright are clean on the touched files. The full unit suite has the same 255 failures on main and on this branch here (mostly tests/units/reflex_cli, environment related), nothing new.