Repository navigation
fix(vars): treat typing_extensions TypedDict state vars as TypedDicts - #8024
cestercian wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Re-trigger cubic
[Medium impact] The change affects TypedDict state access and value checks in Reflex. The PR still needs the earlier fix for known TypedDict fields becoming unreadable when another annotation cannot be resolved. Findings
SummaryRecognizes both
Reviews (2) · Last reviewed commit: "address review: use get_typed_dict_field..." · Reviewed by Greptile |
| ) | ||
| from typing import Any, NoReturn, TypeVar, get_args, get_type_hints, overload | ||
|
|
||
| from typing_extensions import is_typeddict |
There was a problem hiding this comment.
Known fields become unreadable
The new import sends bare typing_extensions.TypedDict fields through get_attribute_access_type, which resolves every annotation at once. If one field names a type imported only under TYPE_CHECKING, reading even a different, fully defined field now raises VarAttributeError. Previously that read returned an Any-typed var, so this can break existing app expressions.
Use get_typed_dict_field_types for TypedDict field lookup. It already keeps known field types and treats unresolved names as Any.
All Submissions:
Type of change
Changes To Core Features:
Fixes #7996
vars/object.pyandutils/types.pyimportedis_typeddictfromtyping, which returns False fortyping_extensions.TypedDictclasses on 3.11+ with typing_extensions 4.16. So a var typed with one hadAnykeys, no error on unknown keys, and_isinstancedidn't check the fields. Both modules now usetyping_extensions.is_typeddict, which handles both flavors.types.pyalready calledtyping_extensions.is_typeddictin a few places, so those now just use the imported name.Tests:
test_typed_dict_key_accessruns key access with atyping.TypedDictand atyping_extensions.TypedDict(field types plusVarAttributeErrorfor a missing key)test_isinstance_typing_extensions_typed_dictchecks_isinstanceagainst atyping_extensions.TypedDictThe 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.