down to 13 errors

This commit is contained in:
Khaleel Al-Adhami 2024-08-13 17:13:43 -07:00
parent 82a3498d02
commit 39bc0c0b57
8 changed files with 17 additions and 14 deletions

View File

@ -6,7 +6,7 @@ from typing import Any, Dict, List, Optional, Set, Tuple, Union
from reflex.base import Base
from reflex.event import EventChain
from reflex.ivars.base import ImmutableVar, LiteralVar
from reflex.ivars.base import LiteralVar
from reflex.utils import format, types
from reflex.vars import Var

View File

@ -676,6 +676,10 @@ class ObjectMergeOperation(ObjectVar):
"""
return hash((self.__class__.__name__, self._lhs, self._rhs))
def __post_init__(self):
"""Post initialization."""
object.__delattr__(self, "_var_name")
@classmethod
def create(
cls,

View File

@ -489,7 +489,6 @@ def format_props(*single_props, **key_value_props) -> list[str]:
# Format all the props.
from reflex.ivars.base import ImmutableVar, LiteralVar
return [
(
f"{name}={format_prop(prop)}"

View File

@ -5,6 +5,7 @@ from reflex.ivars.base import ImmutableVar
STATE_VAR = ImmutableVar.create_safe("default_state.name")
@pytest.mark.parametrize(
"contents,expected",
[

View File

@ -1433,16 +1433,16 @@ def test_add_page_component_returning_tuple():
assert isinstance((fragment_wrapper := app.pages["index"].children[0]), Fragment)
assert isinstance((first_text := fragment_wrapper.children[0]), Text)
assert str(first_text.children[0].contents) == "{`first`}" # type: ignore
assert str(first_text.children[0].contents) == '"first"' # type: ignore
assert isinstance((second_text := fragment_wrapper.children[1]), Text)
assert str(second_text.children[0].contents) == "{`second`}" # type: ignore
assert str(second_text.children[0].contents) == '"second"' # type: ignore
# Test page with trailing comma.
assert isinstance(
(page2_fragment_wrapper := app.pages["page2"].children[0]), Fragment
)
assert isinstance((third_text := page2_fragment_wrapper.children[0]), Text)
assert str(third_text.children[0].contents) == "{`third`}" # type: ignore
assert str(third_text.children[0].contents) == '"third"' # type: ignore
@pytest.mark.parametrize("export", (True, False))

View File

@ -1,4 +1,3 @@
import json
from typing import List
import pytest

View File

@ -415,7 +415,7 @@ def test_class_attributes():
assert str(prop) == f'{TestState.get_name()}.obj["prop1"]'
prop = TestState.complex[1].prop1
assert str(prop) == f"{TestState.get_name()}.complex[1][\"prop1\"]"
assert str(prop) == f'{TestState.get_name()}.complex[1]["prop1"]'
def test_get_parent_state():

View File

@ -920,7 +920,7 @@ def test_function_var():
last_name = LiteralStringVar.create("Universe")
assert (
str(create_hello_statement.call(f"{first_name} {last_name}"))
== '(((name) => (("Hello, "+name+"!")))(("Steven"+" "+"Universe")))'
== '(((name) => (("Hello, "+name+"!")))("Steven Universe"))'
)
@ -967,7 +967,7 @@ def test_all_number_operations():
assert (
str(even_more_complicated_number)
== "!(((Math.abs(Math.floor(((Math.floor(((-((-5.4 + 1)) * 2) / 3) / 2) % 3) ** 2))) != 0) || (true && (Math.round(((Math.floor(((-((-5.4 + 1)) * 2) / 3) / 2) % 3) ** 2)) != 0))))"
== "!(Boolean((Math.abs(Math.floor(((Math.floor(((-((-5.4 + 1)) * 2) / 3) / 2) % 3) ** 2))) || (2 && Math.round(((Math.floor(((-((-5.4 + 1)) * 2) / 3) / 2) % 3) ** 2))))))"
)
assert str(LiteralNumberVar.create(5) > False) == "(5 > 0)"
@ -988,9 +988,9 @@ def test_index_operation():
)
assert (
str(array_var[::-1])
== "[1, 2, 3, 4, 5].slice(0, [1, 2, 3, 4, 5].length).reverse().slice(undefined, undefined).filter((_, i) => i % 1 === 0)"
== "[1, 2, 3, 4, 5].slice(0, [1, 2, 3, 4, 5].length).slice().reverse().slice(undefined, undefined).filter((_, i) => i % 1 === 0)"
)
assert str(array_var.reverse()) == "[1, 2, 3, 4, 5].reverse()"
assert str(array_var.reverse()) == "[1, 2, 3, 4, 5].slice().reverse()"
assert str(array_var[0].to(NumberVar) + 9) == "([1, 2, 3, 4, 5].at(0) + 9)"
@ -999,7 +999,7 @@ def test_array_operations():
assert str(array_var.length()) == "[1, 2, 3, 4, 5].length"
assert str(array_var.contains(3)) == "[1, 2, 3, 4, 5].includes(3)"
assert str(array_var.reverse()) == "[1, 2, 3, 4, 5].reverse()"
assert str(array_var.reverse()) == "[1, 2, 3, 4, 5].slice().reverse()"
assert (
str(ArrayVar.range(10))
== "Array.from({ length: (10 - 0) / 1 }, (_, i) => 0 + i * 1)"
@ -1720,8 +1720,8 @@ def test_invalid_var_operations(operand1_var: Var, operand2_var, operators: List
f"{ATestState.get_full_name()}.value",
),
(
Var.create(f"{ATestState.value} string", _var_is_string=True),
f"`${{{ATestState.get_full_name()}.value}} string`",
LiteralVar.create(f"{ATestState.value} string"),
f'({ATestState.get_full_name()}.value+" string")',
),
(Var.create(ATestState.dict_val), f"{ATestState.get_full_name()}.dict_val"),
],