i hate rufffff (no i don't)

This commit is contained in:
Khaleel Al-Adhami 2024-08-05 15:20:21 -07:00
parent de1fbdbe5b
commit 1eecd1f9a7
5 changed files with 23 additions and 44 deletions

View File

@ -6,7 +6,6 @@ import dataclasses
import functools import functools
import inspect import inspect
import sys import sys
import traceback
from typing import ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
@ -41,21 +40,17 @@ from reflex.vars import (
) )
if TYPE_CHECKING: if TYPE_CHECKING:
from reflex.state import BaseState
from .function import FunctionVar, ToFunctionOperation from .function import FunctionVar, ToFunctionOperation
from .number import ( from .number import (
BooleanVar, BooleanVar,
NumberVar, NumberVar,
ToBooleanVarOperation, ToBooleanVarOperation,
ToNumberVarOperation, ToNumberVarOperation,
EqualOperation,
GreaterThanOperation,
GreaterThanOrEqualOperation,
LessThanOperation,
LessThanOrEqualOperation,
) )
from .object import ObjectVar, ToObjectOperation from .object import ObjectVar, ToObjectOperation
from .sequence import ArrayVar, StringVar, ToArrayOperation, ToStringOperation from .sequence import ArrayVar, StringVar, ToArrayOperation, ToStringOperation
from reflex.state import BaseState
VAR_TYPE = TypeVar("VAR_TYPE") VAR_TYPE = TypeVar("VAR_TYPE")
@ -520,8 +515,7 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
return setter return setter
def __eq__(self, other: Var | Any) -> BooleanVar: def __eq__(self, other: Var | Any) -> BooleanVar:
""" """Check if the current variable is equal to the given variable.
Check if the current variable is equal to the given variable.
Args: Args:
other (Var | Any): The variable to compare with. other (Var | Any): The variable to compare with.
@ -534,8 +528,7 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
return EqualOperation(self, other) return EqualOperation(self, other)
def __ne__(self, other: Var | Any) -> BooleanVar: def __ne__(self, other: Var | Any) -> BooleanVar:
""" """Check if the current object is not equal to the given object.
Check if the current object is not equal to the given object.
Parameters: Parameters:
other (Var | Any): The object to compare with. other (Var | Any): The object to compare with.
@ -548,8 +541,7 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
return ~EqualOperation(self, other) return ~EqualOperation(self, other)
def __gt__(self, other: Var | Any) -> BooleanVar: def __gt__(self, other: Var | Any) -> BooleanVar:
""" """Compare the current instance with another variable and return a BooleanVar representing the result of the greater than operation.
Compare the current instance with another variable and return a BooleanVar representing the result of the greater than operation.
Args: Args:
other (Var | Any): The variable to compare with. other (Var | Any): The variable to compare with.
@ -562,8 +554,7 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
return GreaterThanOperation(self, other) return GreaterThanOperation(self, other)
def __ge__(self, other: Var | Any) -> BooleanVar: def __ge__(self, other: Var | Any) -> BooleanVar:
""" """Check if the value of this variable is greater than or equal to the value of another variable or object.
Check if the value of this variable is greater than or equal to the value of another variable or object.
Args: Args:
other (Var | Any): The variable or object to compare with. other (Var | Any): The variable or object to compare with.
@ -576,8 +567,7 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
return GreaterThanOrEqualOperation(self, other) return GreaterThanOrEqualOperation(self, other)
def __lt__(self, other: Var | Any) -> BooleanVar: def __lt__(self, other: Var | Any) -> BooleanVar:
""" """Compare the current instance with another variable using the less than (<) operator.
Compare the current instance with another variable using the less than (<) operator.
Args: Args:
other: The variable to compare with. other: The variable to compare with.
@ -590,8 +580,7 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
return LessThanOperation(self, other) return LessThanOperation(self, other)
def __le__(self, other: Var | Any) -> BooleanVar: def __le__(self, other: Var | Any) -> BooleanVar:
""" """Compare if the current instance is less than or equal to the given value.
Compare if the current instance is less than or equal to the given value.
Args: Args:
other: The value to compare with. other: The value to compare with.
@ -622,7 +611,6 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
Returns: Returns:
A `BooleanVar` object representing the result of the logical AND operation. A `BooleanVar` object representing the result of the logical AND operation.
""" """
return AndOperation(self, other) return AndOperation(self, other)
def __rand__(self, other: Var | Any) -> ImmutableVar: def __rand__(self, other: Var | Any) -> ImmutableVar:
@ -634,7 +622,6 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
Returns: Returns:
A `BooleanVar` object representing the result of the logical AND operation. A `BooleanVar` object representing the result of the logical AND operation.
""" """
return AndOperation(other, self) return AndOperation(other, self)
def __or__(self, other: Var | Any) -> ImmutableVar: def __or__(self, other: Var | Any) -> ImmutableVar:
@ -646,7 +633,6 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
Returns: Returns:
A `BooleanVar` object representing the result of the logical OR operation. A `BooleanVar` object representing the result of the logical OR operation.
""" """
return OrOperation(self, other) return OrOperation(self, other)
def __ror__(self, other: Var | Any) -> ImmutableVar: def __ror__(self, other: Var | Any) -> ImmutableVar:
@ -658,7 +644,6 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
Returns: Returns:
A `BooleanVar` object representing the result of the logical OR operation. A `BooleanVar` object representing the result of the logical OR operation.
""" """
return OrOperation(other, self) return OrOperation(other, self)
def __invert__(self) -> BooleanVar: def __invert__(self) -> BooleanVar:
@ -687,7 +672,6 @@ class ImmutableVar(Var, Generic[VAR_TYPE]):
Returns: Returns:
The reference to the var. The reference to the var.
""" """
from .object import ObjectVar from .object import ObjectVar
refs = ImmutableVar( refs = ImmutableVar(

View File

@ -7,9 +7,10 @@ import sys
from functools import cached_property from functools import cached_property
from typing import Any, Callable, Optional, Tuple, Type, Union from typing import Any, Callable, Optional, Tuple, Type, Union
from .base import ImmutableVar, LiteralVar
from reflex.vars import ImmutableVarData, Var, VarData from reflex.vars import ImmutableVarData, Var, VarData
from .base import ImmutableVar, LiteralVar
class FunctionVar(ImmutableVar[Callable]): class FunctionVar(ImmutableVar[Callable]):
"""Base class for immutable function vars.""" """Base class for immutable function vars."""

View File

@ -9,12 +9,12 @@ from functools import cached_property
from typing import Any, Union from typing import Any, Union
from reflex.utils.types import GenericType from reflex.utils.types import GenericType
from reflex.vars import ImmutableVarData, Var, VarData
from .base import ( from .base import (
ImmutableVar, ImmutableVar,
LiteralVar, LiteralVar,
) )
from reflex.vars import ImmutableVarData, Var, VarData
class NumberVar(ImmutableVar[Union[int, float]]): class NumberVar(ImmutableVar[Union[int, float]]):

View File

@ -22,7 +22,9 @@ from typing import (
from typing_extensions import get_origin from typing_extensions import get_origin
from reflex.utils import console from reflex.utils.exceptions import VarAttributeError
from reflex.utils.types import GenericType, get_attribute_access_type
from reflex.vars import ImmutableVarData, Var, VarData
from .base import ( from .base import (
ImmutableVar, ImmutableVar,
@ -31,9 +33,6 @@ from .base import (
) )
from .number import BooleanVar, NumberVar from .number import BooleanVar, NumberVar
from .sequence import ArrayVar, StringVar from .sequence import ArrayVar, StringVar
from reflex.utils.exceptions import VarAttributeError
from reflex.utils.types import GenericType, get_attribute_access_type
from reflex.vars import ImmutableVarData, Var, VarData
OBJECT_TYPE = TypeVar("OBJECT_TYPE") OBJECT_TYPE = TypeVar("OBJECT_TYPE")
@ -371,7 +370,7 @@ class LiteralObjectVar(LiteralVar, ObjectVar[OBJECT_TYPE]):
], ],
*[ *[
key._get_all_var_data() key._get_all_var_data()
for key in self._var_value.keys() for key in self._var_value
if isinstance(key, Var) if isinstance(key, Var)
], ],
self._var_data, self._var_data,

View File

@ -27,6 +27,9 @@ from typing_extensions import get_origin
from reflex import constants from reflex import constants
from reflex.constants.base import REFLEX_VAR_OPENING_TAG from reflex.constants.base import REFLEX_VAR_OPENING_TAG
from reflex.utils.types import GenericType
from reflex.vars import ImmutableVarData, Var, VarData, _global_vars
from .base import ( from .base import (
ImmutableVar, ImmutableVar,
LiteralVar, LiteralVar,
@ -39,8 +42,6 @@ from .number import (
NotEqualOperation, NotEqualOperation,
NumberVar, NumberVar,
) )
from reflex.utils.types import GenericType
from reflex.vars import ImmutableVarData, Var, VarData, _global_vars
if TYPE_CHECKING: if TYPE_CHECKING:
from .object import ObjectVar from .object import ObjectVar
@ -72,8 +73,7 @@ class StringVar(ImmutableVar[str]):
return ConcatVarOperation(other, self) return ConcatVarOperation(other, self)
def __mul__(self, other: NumberVar | int) -> StringVar: def __mul__(self, other: NumberVar | int) -> StringVar:
""" """Multiply the sequence by a number or an integer.
Multiply the sequence by a number or an integer.
Args: Args:
other (NumberVar | int): The number or integer to multiply the sequence by. other (NumberVar | int): The number or integer to multiply the sequence by.
@ -84,8 +84,7 @@ class StringVar(ImmutableVar[str]):
return (self.split() * other).join() return (self.split() * other).join()
def __rmul__(self, other: NumberVar | int) -> StringVar: def __rmul__(self, other: NumberVar | int) -> StringVar:
""" """Multiply the sequence by a number or an integer.
Multiply the sequence by a number or an integer.
Args: Args:
other (NumberVar | int): The number or integer to multiply the sequence by. other (NumberVar | int): The number or integer to multiply the sequence by.
@ -746,7 +745,6 @@ class ArrayVar(ImmutableVar[ARRAY_VAR_TYPE]):
Returns: Returns:
The joined elements. The joined elements.
""" """
return ArrayJoinOperation(self, sep) return ArrayJoinOperation(self, sep)
def reverse(self) -> ArrayVar[ARRAY_VAR_TYPE]: def reverse(self) -> ArrayVar[ARRAY_VAR_TYPE]:
@ -758,8 +756,7 @@ class ArrayVar(ImmutableVar[ARRAY_VAR_TYPE]):
return ArrayReverseOperation(self) return ArrayReverseOperation(self)
def __add__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> ArrayConcatOperation: def __add__(self, other: ArrayVar[ARRAY_VAR_TYPE]) -> ArrayConcatOperation:
""" """Concatenate two arrays.
Concatenate two arrays.
Parameters: Parameters:
other (ArrayVar[ARRAY_VAR_TYPE]): The other array to concatenate. other (ArrayVar[ARRAY_VAR_TYPE]): The other array to concatenate.
@ -934,8 +931,7 @@ class ArrayVar(ImmutableVar[ARRAY_VAR_TYPE]):
return ArrayContainsOperation(self, other) return ArrayContainsOperation(self, other)
def __mul__(self, other: NumberVar | int) -> ArrayVar[ARRAY_VAR_TYPE]: def __mul__(self, other: NumberVar | int) -> ArrayVar[ARRAY_VAR_TYPE]:
""" """Multiply the sequence by a number or integer.
Multiply the sequence by a number or integer.
Parameters: Parameters:
other (NumberVar | int): The number or integer to multiply the sequence by. other (NumberVar | int): The number or integer to multiply the sequence by.
@ -946,8 +942,7 @@ class ArrayVar(ImmutableVar[ARRAY_VAR_TYPE]):
return ArrayRepeatOperation(self, other) return ArrayRepeatOperation(self, other)
def __rmul__(self, other: NumberVar | int) -> ArrayVar[ARRAY_VAR_TYPE]: def __rmul__(self, other: NumberVar | int) -> ArrayVar[ARRAY_VAR_TYPE]:
""" """Multiply the sequence by a number or integer.
Multiply the sequence by a number or integer.
Parameters: Parameters:
other (NumberVar | int): The number or integer to multiply the sequence by. other (NumberVar | int): The number or integer to multiply the sequence by.