Compare commits
1 Commits
main
...
masenf/opt
Author | SHA1 | Date | |
---|---|---|---|
![]() |
732459c9d2 |
@ -129,7 +129,7 @@ class Foreach(Component):
|
|||||||
iterable_state=str(tag.iterable),
|
iterable_state=str(tag.iterable),
|
||||||
arg_name=tag.arg_var_name,
|
arg_name=tag.arg_var_name,
|
||||||
arg_index=tag.get_index_var_arg(),
|
arg_index=tag.get_index_var_arg(),
|
||||||
iterable_type=tag.iterable._var_type.mro()[0].__name__,
|
iterable_type=tag.get_iterable_var_type().__name__,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import inspect
|
|||||||
from typing import TYPE_CHECKING, Any, Callable, Iterable, Tuple, Type, Union, get_args
|
from typing import TYPE_CHECKING, Any, Callable, Iterable, Tuple, Type, Union, get_args
|
||||||
|
|
||||||
from reflex.components.tags.tag import Tag
|
from reflex.components.tags.tag import Tag
|
||||||
|
from reflex.utils.types import is_optional
|
||||||
from reflex.vars import LiteralArrayVar, Var, get_unique_variable_name
|
from reflex.vars import LiteralArrayVar, Var, get_unique_variable_name
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -38,15 +39,18 @@ class IterTag(Tag):
|
|||||||
The type of the iterable var.
|
The type of the iterable var.
|
||||||
"""
|
"""
|
||||||
iterable = self.iterable
|
iterable = self.iterable
|
||||||
|
var_type = iterable._var_type
|
||||||
|
if is_optional(var_type):
|
||||||
|
var_type = get_args(var_type)[0]
|
||||||
try:
|
try:
|
||||||
if iterable._var_type.mro()[0] is dict:
|
if var_type.mro()[0] is dict:
|
||||||
# Arg is a tuple of (key, value).
|
# Arg is a tuple of (key, value).
|
||||||
return Tuple[get_args(iterable._var_type)] # type: ignore
|
return Tuple[get_args(var_type)] # type: ignore
|
||||||
elif iterable._var_type.mro()[0] is tuple:
|
elif var_type.mro()[0] is tuple:
|
||||||
# Arg is a union of any possible values in the tuple.
|
# Arg is a union of any possible values in the tuple.
|
||||||
return Union[get_args(iterable._var_type)] # type: ignore
|
return Union[get_args(var_type)] # type: ignore
|
||||||
else:
|
else:
|
||||||
return get_args(iterable._var_type)[0]
|
return get_args(var_type)[0]
|
||||||
except Exception:
|
except Exception:
|
||||||
return Any
|
return Any
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user