diff --git a/reflex/vars/sequence.py b/reflex/vars/sequence.py index 3374ee10f..9b65507b7 100644 --- a/reflex/vars/sequence.py +++ b/reflex/vars/sequence.py @@ -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 diff --git a/tests/units/test_var.py b/tests/units/test_var.py index 8f907c24a..c02acefe6 100644 --- a/tests/units/test_var.py +++ b/tests/units/test_var.py @@ -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