From 73f3454b43262edd0f3b6701637729b8c6c3288e Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Mon, 23 Sep 2024 16:36:58 -0700 Subject: [PATCH] use is true for bool var (#3973) --- reflex/vars/sequence.py | 8 -------- tests/test_var.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/reflex/vars/sequence.py b/reflex/vars/sequence.py index ca8967d338..6145c980c2 100644 --- a/reflex/vars/sequence.py +++ b/reflex/vars/sequence.py @@ -194,14 +194,6 @@ def strip(self) -> StringVar: """ return string_strip_operation(self) - def bool(self): - """Boolean conversion. - - Returns: - The boolean value of the string. - """ - return self.length() != 0 - def reversed(self) -> StringVar: """Reverse the string. diff --git a/tests/test_var.py b/tests/test_var.py index 50bc799fa2..01cd8e1589 100644 --- a/tests/test_var.py +++ b/tests/test_var.py @@ -962,6 +962,21 @@ def test_all_number_operations(): ) +@pytest.mark.parametrize( + ("var", "expected"), + [ + (Var.create(False), "false"), + (Var.create(True), "true"), + (Var.create("false"), 'isTrue("false")'), + (Var.create([1, 2, 3]), "isTrue([1, 2, 3])"), + (Var.create({"a": 1, "b": 2}), 'isTrue(({ ["a"] : 1, ["b"] : 2 }))'), + (Var("mysterious_var"), "isTrue(mysterious_var)"), + ], +) +def test_boolify_operations(var, expected): + assert str(var.bool()) == expected + + def test_index_operation(): array_var = LiteralArrayVar.create([1, 2, 3, 4, 5]) assert str(array_var[0]) == "[1, 2, 3, 4, 5].at(0)"