Added Type Annotation Error Message Indexing/Foreach (#530)
This commit is contained in:
parent
6553be524f
commit
adf5b7fb1b
@ -28,11 +28,18 @@ class Foreach(Component):
|
||||
|
||||
Returns:
|
||||
The foreach component.
|
||||
|
||||
Raises:
|
||||
TypeError: If the iterable is of type Any.
|
||||
"""
|
||||
try:
|
||||
type_ = iterable.type_.__args__[0]
|
||||
except Exception:
|
||||
type_ = Any
|
||||
if iterable.type_ == Any:
|
||||
raise TypeError(
|
||||
f"Could not foreach over var of type Any. (If you are trying to foreach over a state var, add a type annotation to the var.)"
|
||||
)
|
||||
arg = BaseVar(name="_", type_=type_, is_local=True)
|
||||
return cls(
|
||||
iterable=iterable,
|
||||
|
@ -149,6 +149,10 @@ class Var(ABC):
|
||||
utils._issubclass(self.type_, Union[List, Dict])
|
||||
or utils.is_dataframe(self.type_)
|
||||
):
|
||||
if self.type_ == Any:
|
||||
raise TypeError(
|
||||
f"Could not index into var of type Any. (If you are trying to index into a state var, add a type annotation to the var.)"
|
||||
)
|
||||
raise TypeError(
|
||||
f"Var {self.name} of type {self.type_} does not support indexing."
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user