Skip to content

Commit bd1bda1

Browse files
masenfadhami3310
authored andcommitted
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
1 parent 953f336 commit bd1bda1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

reflex/ivars/base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,11 @@ def to(
362362
from .object import ObjectVar, ToObjectOperation
363363
from .sequence import ArrayVar, StringVar, ToArrayOperation, ToStringOperation
364364

365-
fixed_type = get_origin(var_type) or var_type
365+
base_type = var_type
366+
if types.is_optional(base_type):
367+
base_type = types.get_args(base_type)[0]
368+
369+
fixed_type = get_origin(base_type) or base_type
366370

367371
fixed_output_type = get_origin(output) or output
368372

0 commit comments

Comments
 (0)