Var
reflex_base.vars.base.Var
Base class for immutable vars.
Methods
equals
equals(other: Var) -> boolCheck if two vars are equal.
Parameters
other
The other var to compare.
Returns
Whether the vars are equal.
create
create(
value: OTHER_VAR_TYPE,
_var_data: Optional[VarData] = None,
) -> Var[OTHER_VAR_TYPE]Create a var from a value.
Parameters
value
The value to create the var from.
_var_data
Additional hooks and imports associated with the Var.
Returns
The var.
to
to(output: type[OUTPUT] | GenericType, var_type: Optional[GenericType] = None) -> VarConvert the var to a different type.
Parameters
output
The output type.
var_type
The type of the var.
Returns
The converted var.
guess_type
guess_type() -> VarGuesses the type of the variable based on its _var_type attribute.
Returns
The guessed type of the variable.
Raises
TypeError
If the type is not supported for guessing.
bool
bool() -> BooleanVarConvert the var to a boolean.
Returns
The boolean var.
is_none
is_none() -> BooleanVarCheck if the var is None.
Returns
A BooleanVar object representing the result of the check.
is_not_none
is_not_none() -> BooleanVarCheck if the var is not None.
Returns
A BooleanVar object representing the result of the check.
to_string
to_string(use_json: bool = True) -> StringVarConvert the var to a string.
Parameters
use_json
Whether to use JSON stringify. If False, uses Object.prototype.toString.
Returns
The string var.
js_type
js_type() -> StringVarReturns the javascript type of the object.
This method uses the typeof function from the FunctionStringVar class
to determine the type of the object.
Returns
A string variable representing the type of the object.
range
range(
first_endpoint: int | NumberVar,
second_endpoint: Optional[int | NumberVar] = None,
step: Optional[int | NumberVar] = None,
) -> ArrayVar[Sequence[int]]Create a range of numbers.
Parameters
first_endpoint
The end of the range if second_endpoint is not provided, otherwise the start of the range.
second_endpoint
The end of the range.
step
The step of the range.
Returns
The range of numbers.