Repository navigation
fix(vars): treat typing_extensions TypedDict state vars as TypedDicts #8024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| State vars typed with a `typing_extensions.TypedDict` now get typed key access and an error for unknown keys, and assignments to them are checked against the field types, same as `typing.TypedDict`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,15 +7,9 @@ | |
| import typing | ||
| from collections.abc import Mapping | ||
| from importlib.util import find_spec | ||
| from typing import ( | ||
| Any, | ||
| NoReturn, | ||
| TypeVar, | ||
| get_args, | ||
| get_type_hints, | ||
| is_typeddict, | ||
| overload, | ||
| ) | ||
| from typing import Any, NoReturn, TypeVar, get_args, get_type_hints, overload | ||
|
|
||
| from typing_extensions import is_typeddict | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new import sends bare Use |
||
|
|
||
| from reflex_base.utils import types | ||
| from reflex_base.utils.exceptions import VarAttributeError | ||
|
|
@@ -61,7 +55,10 @@ def _determine_value_type(var_type: GenericType): | |
| if arg is not type(None) | ||
| ]) | ||
|
|
||
| if is_typeddict(origin_var_type) or dataclasses.is_dataclass(origin_var_type): | ||
| if is_typeddict(origin_var_type): | ||
| return unionize(*types.get_typed_dict_field_types(var_type).values()) | ||
|
|
||
| if dataclasses.is_dataclass(origin_var_type): | ||
| annotations = get_type_hints(origin_var_type) | ||
| return unionize(*annotations.values()) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.