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
This commit is contained in:
parent
953f336790
commit
bd1bda1325
@ -362,7 +362,11 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
|
|||||||
from .object import ObjectVar, ToObjectOperation
|
from .object import ObjectVar, ToObjectOperation
|
||||||
from .sequence import ArrayVar, StringVar, ToArrayOperation, ToStringOperation
|
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
|
fixed_output_type = get_origin(output) or output
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user