From 1d9a154d5b8810a21e7c6b9488084708f8895489 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Mon, 26 Aug 2024 16:26:17 -0700 Subject: [PATCH] guess_type: if the type is optional, treat it like it's "not None" (#3839) * guess_type: if the type is optional, treat it like it's "not None" When guessing the type for an Optional annotation, the Optional was already being stripped off, but this value was being ignored, except for error messages. So actually use the Optional-stripped value. * Strip Optional when casting Var .to --- reflex/ivars/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/reflex/ivars/base.py b/reflex/ivars/base.py index de970ff64..3ccbb5393 100644 --- a/reflex/ivars/base.py +++ b/reflex/ivars/base.py @@ -362,7 +362,11 @@ class ImmutableVar(Var, Generic[VAR_TYPE]): from .object import ObjectVar, ToObjectOperation from .sequence import ArrayVar, StringVar, ToArrayOperation, ToStringOperation - fixed_type = get_origin(var_type) or var_type + base_type = var_type + if types.is_optional(base_type): + base_type = types.get_args(base_type)[0] + + fixed_type = get_origin(base_type) or base_type fixed_output_type = get_origin(output) or output