fix pyright issues

This commit is contained in:
Khaleel Al-Adhami 2024-11-13 18:40:06 -08:00
parent f4aa1f58c3
commit 9d7e353ed3
5 changed files with 62 additions and 57 deletions

View File

@ -75,7 +75,7 @@ from reflex.utils.types import (
if TYPE_CHECKING: if TYPE_CHECKING:
from reflex.state import BaseState from reflex.state import BaseState
from .function import ArgsFunctionOperation, ReflexCallable from .function import ArgsFunctionOperation
from .number import BooleanVar, NumberVar from .number import BooleanVar, NumberVar
from .object import ObjectVar from .object import ObjectVar
from .sequence import ArrayVar, StringVar from .sequence import ArrayVar, StringVar
@ -930,7 +930,7 @@ class Var(Generic[VAR_TYPE]):
""" """
from .number import equal_operation from .number import equal_operation
return ~equal_operation(self, other) return (~equal_operation(self, other)).guess_type()
def bool(self) -> BooleanVar: def bool(self) -> BooleanVar:
"""Convert the var to a boolean. """Convert the var to a boolean.
@ -940,7 +940,7 @@ class Var(Generic[VAR_TYPE]):
""" """
from .number import boolify from .number import boolify
return boolify(self) return boolify(self).guess_type()
def __and__(self, other: Var | Any) -> Var: def __and__(self, other: Var | Any) -> Var:
"""Perform a logical AND operation on the current instance and another variable. """Perform a logical AND operation on the current instance and another variable.
@ -992,7 +992,7 @@ class Var(Generic[VAR_TYPE]):
Returns: Returns:
A `BooleanVar` object representing the result of the logical NOT operation. A `BooleanVar` object representing the result of the logical NOT operation.
""" """
return ~self.bool() return (~self.bool()).guess_type()
def to_string(self, use_json: bool = True) -> StringVar: def to_string(self, use_json: bool = True) -> StringVar:
"""Convert the var to a string. """Convert the var to a string.
@ -1539,7 +1539,7 @@ def var_operation(
def var_operation( def var_operation(
func: Callable[..., CustomVarOperationReturn[T]], func: Callable[..., CustomVarOperationReturn[T]],
) -> ArgsFunctionOperation: ) -> ArgsFunctionOperation[ReflexCallable[..., T]]:
"""Decorator for creating a var operation. """Decorator for creating a var operation.
Example: Example:
@ -1604,7 +1604,7 @@ def var_operation(
function_name=func_name, function_name=func_name,
type_computer=custom_operation_return._type_computer, type_computer=custom_operation_return._type_computer,
_var_type=ReflexCallable[ _var_type=ReflexCallable[
tuple(arg_python_type for _, arg_python_type in args_with_type_hints), tuple(arg_python_type for _, arg_python_type in args_with_type_hints), # type: ignore
custom_operation_return._var_type, custom_operation_return._var_type,
], ],
) )
@ -3143,7 +3143,7 @@ def nary_type_computer(
def type_computer(*args: Var): def type_computer(*args: Var):
if len(args) != len(types): if len(args) != len(types):
return ( return (
ReflexCallable[[], types[len(args)]], ReflexCallable[[], types[len(args)]], # type: ignore
functools.partial(type_computer, *args), functools.partial(type_computer, *args),
) )
return ( return (

View File

@ -239,7 +239,7 @@ class FunctionVar(Var[CALLABLE_TYPE], default_type=ReflexCallable[Any, Any]):
""" """
args_types, return_type = unwrap_reflex_callalbe(self._var_type) args_types, return_type = unwrap_reflex_callalbe(self._var_type)
if isinstance(args_types, tuple): if isinstance(args_types, tuple):
return ReflexCallable[[*args_types[len(args) :]], return_type], None return ReflexCallable[[*args_types[len(args) :]], return_type], None # type: ignore
return ReflexCallable[..., return_type], None return ReflexCallable[..., return_type], None
def _arg_len(self) -> int | None: def _arg_len(self) -> int | None:
@ -507,9 +507,9 @@ class ArgsFunctionOperation(CachedVarOperation, FunctionVar[CALLABLE_TYPE]):
_cached_var_name = cached_property_no_lock(format_args_function_operation) _cached_var_name = cached_property_no_lock(format_args_function_operation)
_pre_check = pre_check_args _pre_check = pre_check_args # type: ignore
_partial_type = figure_partial_type _partial_type = figure_partial_type # type: ignore
@classmethod @classmethod
def create( def create(
@ -574,9 +574,9 @@ class ArgsFunctionOperationBuilder(
_cached_var_name = cached_property_no_lock(format_args_function_operation) _cached_var_name = cached_property_no_lock(format_args_function_operation)
_pre_check = pre_check_args _pre_check = pre_check_args # type: ignore
_partial_type = figure_partial_type _partial_type = figure_partial_type # type: ignore
@classmethod @classmethod
def create( def create(

View File

@ -70,7 +70,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
""" """
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("+", (type(self), type(other))) raise_unsupported_operand_types("+", (type(self), type(other)))
return number_add_operation(self, +other) return number_add_operation(self, +other).guess_type()
@overload @overload
def __radd__(self, other: number_types) -> NumberVar: ... def __radd__(self, other: number_types) -> NumberVar: ...
@ -89,7 +89,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
""" """
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("+", (type(other), type(self))) raise_unsupported_operand_types("+", (type(other), type(self)))
return number_add_operation(+other, self) return number_add_operation(+other, self).guess_type()
@overload @overload
def __sub__(self, other: number_types) -> NumberVar: ... def __sub__(self, other: number_types) -> NumberVar: ...
@ -109,7 +109,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("-", (type(self), type(other))) raise_unsupported_operand_types("-", (type(self), type(other)))
return number_subtract_operation(self, +other) return number_subtract_operation(self, +other).guess_type()
@overload @overload
def __rsub__(self, other: number_types) -> NumberVar: ... def __rsub__(self, other: number_types) -> NumberVar: ...
@ -129,7 +129,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("-", (type(other), type(self))) raise_unsupported_operand_types("-", (type(other), type(self)))
return number_subtract_operation(+other, self) return number_subtract_operation(+other, self).guess_type()
def __abs__(self): def __abs__(self):
"""Get the absolute value of the number. """Get the absolute value of the number.
@ -164,7 +164,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("*", (type(self), type(other))) raise_unsupported_operand_types("*", (type(self), type(other)))
return number_multiply_operation(self, +other) return number_multiply_operation(self, +other).guess_type()
@overload @overload
def __rmul__(self, other: number_types | boolean_types) -> NumberVar: ... def __rmul__(self, other: number_types | boolean_types) -> NumberVar: ...
@ -191,7 +191,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("*", (type(other), type(self))) raise_unsupported_operand_types("*", (type(other), type(self)))
return number_multiply_operation(+other, self) return number_multiply_operation(+other, self).guess_type()
@overload @overload
def __truediv__(self, other: number_types) -> NumberVar: ... def __truediv__(self, other: number_types) -> NumberVar: ...
@ -211,7 +211,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("/", (type(self), type(other))) raise_unsupported_operand_types("/", (type(self), type(other)))
return number_true_division_operation(self, +other) return number_true_division_operation(self, +other).guess_type()
@overload @overload
def __rtruediv__(self, other: number_types) -> NumberVar: ... def __rtruediv__(self, other: number_types) -> NumberVar: ...
@ -231,7 +231,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("/", (type(other), type(self))) raise_unsupported_operand_types("/", (type(other), type(self)))
return number_true_division_operation(+other, self) return number_true_division_operation(+other, self).guess_type()
@overload @overload
def __floordiv__(self, other: number_types) -> NumberVar: ... def __floordiv__(self, other: number_types) -> NumberVar: ...
@ -251,7 +251,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("//", (type(self), type(other))) raise_unsupported_operand_types("//", (type(self), type(other)))
return number_floor_division_operation(self, +other) return number_floor_division_operation(self, +other).guess_type()
@overload @overload
def __rfloordiv__(self, other: number_types) -> NumberVar: ... def __rfloordiv__(self, other: number_types) -> NumberVar: ...
@ -271,7 +271,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("//", (type(other), type(self))) raise_unsupported_operand_types("//", (type(other), type(self)))
return number_floor_division_operation(+other, self) return number_floor_division_operation(+other, self).guess_type()
@overload @overload
def __mod__(self, other: number_types) -> NumberVar: ... def __mod__(self, other: number_types) -> NumberVar: ...
@ -291,7 +291,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("%", (type(self), type(other))) raise_unsupported_operand_types("%", (type(self), type(other)))
return number_modulo_operation(self, +other) return number_modulo_operation(self, +other).guess_type()
@overload @overload
def __rmod__(self, other: number_types) -> NumberVar: ... def __rmod__(self, other: number_types) -> NumberVar: ...
@ -311,7 +311,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("%", (type(other), type(self))) raise_unsupported_operand_types("%", (type(other), type(self)))
return number_modulo_operation(+other, self) return number_modulo_operation(+other, self).guess_type()
@overload @overload
def __pow__(self, other: number_types) -> NumberVar: ... def __pow__(self, other: number_types) -> NumberVar: ...
@ -331,7 +331,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("**", (type(self), type(other))) raise_unsupported_operand_types("**", (type(self), type(other)))
return number_exponent_operation(self, +other) return number_exponent_operation(self, +other).guess_type()
@overload @overload
def __rpow__(self, other: number_types) -> NumberVar: ... def __rpow__(self, other: number_types) -> NumberVar: ...
@ -351,7 +351,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
if not isinstance(other, NUMBER_TYPES): if not isinstance(other, NUMBER_TYPES):
raise_unsupported_operand_types("**", (type(other), type(self))) raise_unsupported_operand_types("**", (type(other), type(self)))
return number_exponent_operation(+other, self) return number_exponent_operation(+other, self).guess_type()
def __neg__(self): def __neg__(self):
"""Negate the number. """Negate the number.
@ -874,7 +874,7 @@ def comparison_operator(
""" """
@var_operation @var_operation
def operation(lhs: Var, rhs: Var): def operation(lhs: Var[Any], rhs: Var[Any]):
return var_operation_return( return var_operation_return(
js_expression=func(lhs, rhs), js_expression=func(lhs, rhs),
var_type=bool, var_type=bool,
@ -890,7 +890,7 @@ def comparison_operator(
Returns: Returns:
The comparison operation. The comparison operation.
""" """
return operation(lhs, rhs) return operation(lhs, rhs).guess_type()
return wrapper return wrapper

View File

@ -91,7 +91,7 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=dict):
Returns: Returns:
The keys of the object. The keys of the object.
""" """
return object_keys_operation(self) return object_keys_operation(self).guess_type()
@overload @overload
def values( def values(
@ -107,7 +107,7 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=dict):
Returns: Returns:
The values of the object. The values of the object.
""" """
return object_values_operation(self) return object_values_operation(self).guess_type()
@overload @overload
def entries( def entries(
@ -123,7 +123,7 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=dict):
Returns: Returns:
The entries of the object. The entries of the object.
""" """
return object_entries_operation(self) return object_entries_operation(self).guess_type()
items = entries items = entries
@ -296,7 +296,7 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=dict):
Returns: Returns:
The result of the check. The result of the check.
""" """
return object_has_own_property_operation(self, key) return object_has_own_property_operation(self, key).guess_type()
@dataclasses.dataclass( @dataclasses.dataclass(
@ -445,6 +445,7 @@ def object_values_operation(value: Var):
ReflexCallable[[Any], List[Any]], ReflexCallable[[Any], List[Any]],
lambda x: List[x.to(ObjectVar)._value_type()], lambda x: List[x.to(ObjectVar)._value_type()],
), ),
var_type=List[Any],
) )
@ -465,6 +466,7 @@ def object_entries_operation(value: Var):
ReflexCallable[[Any], List[Tuple[str, Any]]], ReflexCallable[[Any], List[Tuple[str, Any]]],
lambda x: List[Tuple[str, x.to(ObjectVar)._value_type()]], lambda x: List[Tuple[str, x.to(ObjectVar)._value_type()]],
), ),
var_type=List[Tuple[str, Any]],
) )
@ -489,6 +491,7 @@ def object_merge_operation(lhs: Var, rhs: Var):
unionize(*[arg.to(ObjectVar)._value_type() for arg in args]), unionize(*[arg.to(ObjectVar)._value_type() for arg in args]),
], ],
), ),
var_type=Dict[Any, Any],
) )

View File

@ -168,7 +168,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
isinstance(i, NumberVar) and i._is_strict_float() isinstance(i, NumberVar) and i._is_strict_float()
): ):
raise_unsupported_operand_types("[]", (type(self), type(i))) raise_unsupported_operand_types("[]", (type(self), type(i)))
return string_item_operation(self, i) return string_item_operation(self, i).guess_type()
def length(self) -> NumberVar: def length(self) -> NumberVar:
"""Get the length of the string. """Get the length of the string.
@ -184,7 +184,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
Returns: Returns:
The string lower operation. The string lower operation.
""" """
return string_lower_operation(self) return string_lower_operation(self).guess_type()
def upper(self) -> StringVar: def upper(self) -> StringVar:
"""Convert the string to uppercase. """Convert the string to uppercase.
@ -192,7 +192,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
Returns: Returns:
The string upper operation. The string upper operation.
""" """
return string_upper_operation(self) return string_upper_operation(self).guess_type()
def strip(self) -> StringVar: def strip(self) -> StringVar:
"""Strip the string. """Strip the string.
@ -200,7 +200,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
Returns: Returns:
The string strip operation. The string strip operation.
""" """
return string_strip_operation(self) return string_strip_operation(self).guess_type()
def reversed(self) -> StringVar: def reversed(self) -> StringVar:
"""Reverse the string. """Reverse the string.
@ -235,8 +235,8 @@ class StringVar(Var[STRING_TYPE], python_types=str):
if field is not None: if field is not None:
if not isinstance(field, (StringVar, str)): if not isinstance(field, (StringVar, str)):
raise_unsupported_operand_types("contains", (type(self), type(field))) raise_unsupported_operand_types("contains", (type(self), type(field)))
return string_contains_field_operation(self, other, field) return string_contains_field_operation(self, other, field).guess_type()
return string_contains_operation(self, other) return string_contains_operation(self, other).guess_type()
@overload @overload
def split(self, separator: StringVar | str = "") -> ArrayVar[List[str]]: ... def split(self, separator: StringVar | str = "") -> ArrayVar[List[str]]: ...
@ -255,7 +255,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
""" """
if not isinstance(separator, (StringVar, str)): if not isinstance(separator, (StringVar, str)):
raise_unsupported_operand_types("split", (type(self), type(separator))) raise_unsupported_operand_types("split", (type(self), type(separator)))
return string_split_operation(self, separator) return string_split_operation(self, separator).guess_type()
@overload @overload
def startswith(self, prefix: StringVar | str) -> BooleanVar: ... def startswith(self, prefix: StringVar | str) -> BooleanVar: ...
@ -274,7 +274,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
""" """
if not isinstance(prefix, (StringVar, str)): if not isinstance(prefix, (StringVar, str)):
raise_unsupported_operand_types("startswith", (type(self), type(prefix))) raise_unsupported_operand_types("startswith", (type(self), type(prefix)))
return string_starts_with_operation(self, prefix) return string_starts_with_operation(self, prefix).guess_type()
@overload @overload
def __lt__(self, other: StringVar | str) -> BooleanVar: ... def __lt__(self, other: StringVar | str) -> BooleanVar: ...
@ -294,7 +294,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
if not isinstance(other, (StringVar, str)): if not isinstance(other, (StringVar, str)):
raise_unsupported_operand_types("<", (type(self), type(other))) raise_unsupported_operand_types("<", (type(self), type(other)))
return string_lt_operation(self, other) return string_lt_operation(self, other).guess_type()
@overload @overload
def __gt__(self, other: StringVar | str) -> BooleanVar: ... def __gt__(self, other: StringVar | str) -> BooleanVar: ...
@ -314,7 +314,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
if not isinstance(other, (StringVar, str)): if not isinstance(other, (StringVar, str)):
raise_unsupported_operand_types(">", (type(self), type(other))) raise_unsupported_operand_types(">", (type(self), type(other)))
return string_gt_operation(self, other) return string_gt_operation(self, other).guess_type()
@overload @overload
def __le__(self, other: StringVar | str) -> BooleanVar: ... def __le__(self, other: StringVar | str) -> BooleanVar: ...
@ -334,7 +334,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
if not isinstance(other, (StringVar, str)): if not isinstance(other, (StringVar, str)):
raise_unsupported_operand_types("<=", (type(self), type(other))) raise_unsupported_operand_types("<=", (type(self), type(other)))
return string_le_operation(self, other) return string_le_operation(self, other).guess_type()
@overload @overload
def __ge__(self, other: StringVar | str) -> BooleanVar: ... def __ge__(self, other: StringVar | str) -> BooleanVar: ...
@ -354,7 +354,7 @@ class StringVar(Var[STRING_TYPE], python_types=str):
if not isinstance(other, (StringVar, str)): if not isinstance(other, (StringVar, str)):
raise_unsupported_operand_types(">=", (type(self), type(other))) raise_unsupported_operand_types(">=", (type(self), type(other)))
return string_ge_operation(self, other) return string_ge_operation(self, other).guess_type()
@var_operation @var_operation
@ -796,7 +796,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
i._var_value if isinstance(i, LiteralStringVar) else i for i in args i._var_value if isinstance(i, LiteralStringVar) else i for i in args
) )
) )
return array_join_operation(self, sep) return array_join_operation(self, sep).guess_type()
def reverse(self) -> ArrayVar[ARRAY_VAR_TYPE]: def reverse(self) -> ArrayVar[ARRAY_VAR_TYPE]:
"""Reverse the array. """Reverse the array.
@ -804,7 +804,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
Returns: Returns:
The reversed array. The reversed array.
""" """
return array_reverse_operation(self) return array_reverse_operation(self).to(ArrayVar, self._var_type)
@overload @overload
def __add__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> ArrayVar[ARRAY_VAR_TYPE]: ... def __add__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> ArrayVar[ARRAY_VAR_TYPE]: ...
@ -824,7 +824,9 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
if not isinstance(other, ArrayVar): if not isinstance(other, ArrayVar):
raise_unsupported_operand_types("+", (type(self), type(other))) raise_unsupported_operand_types("+", (type(self), type(other)))
return array_concat_operation(self, other) return array_concat_operation(self, other).to(
ArrayVar, unionize(self._var_type, other._var_type)
)
@overload @overload
def __getitem__(self, i: slice) -> ArrayVar[ARRAY_VAR_TYPE]: ... def __getitem__(self, i: slice) -> ArrayVar[ARRAY_VAR_TYPE]: ...
@ -945,7 +947,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
Returns: Returns:
The length of the array. The length of the array.
""" """
return array_length_operation(self) return array_length_operation(self).guess_type()
@overload @overload
@classmethod @classmethod
@ -1002,7 +1004,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
start = first_endpoint start = first_endpoint
end = second_endpoint end = second_endpoint
return array_range_operation(start, end, step or 1) return array_range_operation(start, end, step or 1).guess_type()
@overload @overload
def contains(self, other: Any) -> BooleanVar: ... def contains(self, other: Any) -> BooleanVar: ...
@ -1023,8 +1025,8 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
if field is not None: if field is not None:
if not isinstance(field, (StringVar, str)): if not isinstance(field, (StringVar, str)):
raise_unsupported_operand_types("contains", (type(self), type(field))) raise_unsupported_operand_types("contains", (type(self), type(field)))
return array_contains_field_operation(self, other, field) return array_contains_field_operation(self, other, field).guess_type()
return array_contains_operation(self, other) return array_contains_operation(self, other).guess_type()
def pluck(self, field: StringVar | str) -> ArrayVar: def pluck(self, field: StringVar | str) -> ArrayVar:
"""Pluck a field from the array. """Pluck a field from the array.
@ -1057,7 +1059,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
): ):
raise_unsupported_operand_types("*", (type(self), type(other))) raise_unsupported_operand_types("*", (type(self), type(other)))
return repeat_array_operation(self, other) return repeat_array_operation(self, other).to(ArrayVar, self._var_type)
__rmul__ = __mul__ # type: ignore __rmul__ = __mul__ # type: ignore
@ -1079,7 +1081,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
if not isinstance(other, (ArrayVar, list, tuple)): if not isinstance(other, (ArrayVar, list, tuple)):
raise_unsupported_operand_types("<", (type(self), type(other))) raise_unsupported_operand_types("<", (type(self), type(other)))
return array_lt_operation(self, other) return array_lt_operation(self, other).guess_type()
@overload @overload
def __gt__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> BooleanVar: ... def __gt__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> BooleanVar: ...
@ -1099,7 +1101,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
if not isinstance(other, (ArrayVar, list, tuple)): if not isinstance(other, (ArrayVar, list, tuple)):
raise_unsupported_operand_types(">", (type(self), type(other))) raise_unsupported_operand_types(">", (type(self), type(other)))
return array_gt_operation(self, other) return array_gt_operation(self, other).guess_type()
@overload @overload
def __le__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> BooleanVar: ... def __le__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> BooleanVar: ...
@ -1119,7 +1121,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
if not isinstance(other, (ArrayVar, list, tuple)): if not isinstance(other, (ArrayVar, list, tuple)):
raise_unsupported_operand_types("<=", (type(self), type(other))) raise_unsupported_operand_types("<=", (type(self), type(other)))
return array_le_operation(self, other) return array_le_operation(self, other).guess_type()
@overload @overload
def __ge__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> BooleanVar: ... def __ge__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> BooleanVar: ...
@ -1139,7 +1141,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE], python_types=(list, tuple, set)):
if not isinstance(other, (ArrayVar, list, tuple)): if not isinstance(other, (ArrayVar, list, tuple)):
raise_unsupported_operand_types(">=", (type(self), type(other))) raise_unsupported_operand_types(">=", (type(self), type(other)))
return array_ge_operation(self, other) return array_ge_operation(self, other).guess_type()
def foreach(self, fn: Any): def foreach(self, fn: Any):
"""Apply a function to each element of the array. """Apply a function to each element of the array.
@ -1692,7 +1694,7 @@ def map_array_operation(
type_computer=nary_type_computer( type_computer=nary_type_computer(
ReflexCallable[[List[Any], ReflexCallable], List[Any]], ReflexCallable[[List[Any], ReflexCallable], List[Any]],
ReflexCallable[[ReflexCallable], List[Any]], ReflexCallable[[ReflexCallable], List[Any]],
computer=lambda args: List[unwrap_reflex_callalbe(args[1]._var_type)[1]], computer=lambda args: List[unwrap_reflex_callalbe(args[1]._var_type)[1]], # type: ignore
), ),
) )