fix: Determine var type from value. (#4143)
This commit is contained in:
parent
7a971e5842
commit
87648af3ee
@ -545,7 +545,7 @@ class LiteralStringVar(LiteralVar, StringVar):
|
||||
def create(
|
||||
cls,
|
||||
value: str,
|
||||
_var_type: GenericType | None = str,
|
||||
_var_type: GenericType | None = None,
|
||||
_var_data: VarData | None = None,
|
||||
) -> StringVar:
|
||||
"""Create a var from a string value.
|
||||
@ -558,6 +558,9 @@ class LiteralStringVar(LiteralVar, StringVar):
|
||||
Returns:
|
||||
The var.
|
||||
"""
|
||||
# Determine var type in case the value is inherited from str.
|
||||
_var_type = _var_type or type(value) or str
|
||||
|
||||
if REFLEX_VAR_OPENING_TAG in value:
|
||||
strings_and_vals: list[Var | str] = []
|
||||
offset = 0
|
||||
|
@ -1809,3 +1809,6 @@ def test_to_string_operation():
|
||||
|
||||
assert cast(Var, TestState.email)._var_type == Email
|
||||
assert cast(Var, TestState.optional_email)._var_type == Optional[Email]
|
||||
|
||||
single_var = Var.create(Email())
|
||||
assert single_var._var_type == Email
|
||||
|
Loading…
Reference in New Issue
Block a user