Skip to content

Commit

Permalink
guess_type: if the type is optional, treat it like it's "not None" (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
masenf authored and adhami3310 committed Aug 27, 2024
1 parent 953f336 commit bd1bda1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion reflex/ivars/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,11 @@ def to(
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

Expand Down

0 comments on commit bd1bda1

Please sign in to comment.