Skip to content

Commit aac61c6

Browse files
authored
actually get rid of callable var fr fr (#4821)
1 parent 6fb4914 commit aac61c6

File tree

7 files changed

+6
-66
lines changed

7 files changed

+6
-66
lines changed

reflex/components/core/upload.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from reflex.utils import format
3030
from reflex.utils.imports import ImportVar
3131
from reflex.vars import VarData
32-
from reflex.vars.base import CallableVar, Var, get_unique_variable_name
32+
from reflex.vars.base import Var, get_unique_variable_name
3333
from reflex.vars.sequence import LiteralStringVar
3434

3535
DEFAULT_UPLOAD_ID: str = "default"
@@ -45,7 +45,6 @@
4545
)
4646

4747

48-
@CallableVar
4948
def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var:
5049
"""Get the file upload drop trigger.
5150
@@ -75,7 +74,6 @@ def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var:
7574
)
7675

7776

78-
@CallableVar
7977
def selected_files(id_: str = DEFAULT_UPLOAD_ID) -> Var:
8078
"""Get the list of selected files.
8179

reflex/components/core/upload.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ from reflex.event import CallableEventSpec, EventSpec, EventType
1313
from reflex.style import Style
1414
from reflex.utils.imports import ImportVar
1515
from reflex.vars import VarData
16-
from reflex.vars.base import CallableVar, Var
16+
from reflex.vars.base import Var
1717

1818
DEFAULT_UPLOAD_ID: str
1919
upload_files_context_var_data: VarData
2020

21-
@CallableVar
2221
def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var: ...
23-
@CallableVar
2422
def selected_files(id_: str = DEFAULT_UPLOAD_ID) -> Var: ...
2523
@CallableEventSpec
2624
def clear_selected_files(id_: str = DEFAULT_UPLOAD_ID) -> EventSpec: ...

reflex/components/radix/themes/color_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def create(
144144

145145
if allow_system:
146146

147-
def color_mode_item(_color_mode: str):
147+
def color_mode_item(_color_mode: Literal["light", "dark", "system"]):
148148
return dropdown_menu.item(
149149
_color_mode.title(), on_click=set_color_mode(_color_mode)
150150
)

reflex/style.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from reflex.utils.imports import ImportVar
1313
from reflex.utils.types import get_origin
1414
from reflex.vars import VarData
15-
from reflex.vars.base import CallableVar, LiteralVar, Var
15+
from reflex.vars.base import LiteralVar, Var
1616
from reflex.vars.function import FunctionVar
1717
from reflex.vars.object import ObjectVar
1818

@@ -48,7 +48,6 @@ def _color_mode_var(_js_expr: str, _var_type: Type = str) -> Var:
4848
).guess_type()
4949

5050

51-
@CallableVar
5251
def set_color_mode(
5352
new_color_mode: LiteralColorMode | Var[LiteralColorMode] | None = None,
5453
) -> Var[EventChain]:

reflex/vars/base.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,61 +1903,6 @@ def _or_operation(a: Var, b: Var):
19031903
)
19041904

19051905

1906-
@dataclasses.dataclass(
1907-
eq=False,
1908-
frozen=True,
1909-
slots=True,
1910-
)
1911-
class CallableVar(Var):
1912-
"""Decorate a Var-returning function to act as both a Var and a function.
1913-
1914-
This is used as a compatibility shim for replacing Var objects in the
1915-
API with functions that return a family of Var.
1916-
"""
1917-
1918-
fn: Callable[..., Var] = dataclasses.field(
1919-
default_factory=lambda: lambda: Var(_js_expr="undefined")
1920-
)
1921-
original_var: Var = dataclasses.field(
1922-
default_factory=lambda: Var(_js_expr="undefined")
1923-
)
1924-
1925-
def __init__(self, fn: Callable[..., Var]):
1926-
"""Initialize a CallableVar.
1927-
1928-
Args:
1929-
fn: The function to decorate (must return Var)
1930-
"""
1931-
original_var = fn()
1932-
super(CallableVar, self).__init__(
1933-
_js_expr=original_var._js_expr,
1934-
_var_type=original_var._var_type,
1935-
_var_data=VarData.merge(original_var._get_all_var_data()),
1936-
)
1937-
object.__setattr__(self, "fn", fn)
1938-
object.__setattr__(self, "original_var", original_var)
1939-
1940-
def __call__(self, *args: Any, **kwargs: Any) -> Var:
1941-
"""Call the decorated function.
1942-
1943-
Args:
1944-
*args: The args to pass to the function.
1945-
**kwargs: The kwargs to pass to the function.
1946-
1947-
Returns:
1948-
The Var returned from calling the function.
1949-
"""
1950-
return self.fn(*args, **kwargs)
1951-
1952-
def __hash__(self) -> int:
1953-
"""Calculate the hash of the object.
1954-
1955-
Returns:
1956-
The hash of the object.
1957-
"""
1958-
return hash((type(self).__name__, self.original_var))
1959-
1960-
19611906
RETURN_TYPE = TypeVar("RETURN_TYPE")
19621907

19631908
DICT_KEY = TypeVar("DICT_KEY")

tests/integration/test_upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def index():
8787
),
8888
rx.box(
8989
rx.foreach(
90-
rx.selected_files,
90+
rx.selected_files(),
9191
lambda f: rx.text(f, as_="p"),
9292
),
9393
id="selected_files",

tests/integration/tests_playwright/test_appearance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def index():
6161
rx.icon(tag="moon", size=20),
6262
value="dark",
6363
),
64-
on_change=set_color_mode,
64+
on_change=set_color_mode(),
6565
variant="classic",
6666
radius="large",
6767
value=color_mode,

0 commit comments

Comments
 (0)