get it right pyright
This commit is contained in:
parent
42a7fb2f39
commit
e8380383a9
@ -577,7 +577,7 @@ class Component(BaseComponent, ABC):
|
||||
if isinstance(result, Var):
|
||||
# Recursively call this function if the lambda returned an EventChain Var.
|
||||
return self._create_event_chain(args_spec, result)
|
||||
events = result
|
||||
events = [*result]
|
||||
|
||||
# Otherwise, raise an error.
|
||||
else:
|
||||
|
@ -488,7 +488,7 @@ class FileUpload:
|
||||
if isinstance(events, Var):
|
||||
raise ValueError(f"{on_upload_progress} cannot return a var {events}.")
|
||||
on_upload_progress_chain = EventChain(
|
||||
events=events,
|
||||
events=[*events],
|
||||
args_spec=self.on_upload_progress_args_spec,
|
||||
)
|
||||
formatted_chain = str(format.format_prop(on_upload_progress_chain))
|
||||
|
@ -359,19 +359,7 @@ def format_prop(
|
||||
|
||||
# Handle event props.
|
||||
if isinstance(prop, EventChain):
|
||||
sig = inspect.signature(prop.args_spec) # type: ignore
|
||||
if sig.parameters:
|
||||
arg_def = ",".join(f"_{p}" for p in sig.parameters)
|
||||
arg_def_expr = f"[{arg_def}]"
|
||||
else:
|
||||
# add a default argument for addEvents if none were specified in prop.args_spec
|
||||
# used to trigger the preventDefault() on the event.
|
||||
arg_def = "...args"
|
||||
arg_def_expr = "args"
|
||||
|
||||
chain = ",".join([format_event(event) for event in prop.events])
|
||||
event = f"addEvents([{chain}], {arg_def_expr}, {json_dumps(prop.event_actions)})"
|
||||
prop = f"({arg_def}) => {event}"
|
||||
return str(Var.create(prop))
|
||||
|
||||
# Handle other types.
|
||||
elif isinstance(prop, str):
|
||||
|
@ -1178,7 +1178,7 @@ TEST_VAR = LiteralVar.create("test")._replace(
|
||||
)
|
||||
FORMATTED_TEST_VAR = LiteralVar.create(f"foo{TEST_VAR}bar")
|
||||
STYLE_VAR = TEST_VAR._replace(_js_expr="style")
|
||||
EVENT_CHAIN_VAR = TEST_VAR._replace(_var_type=EventChain)
|
||||
EVENT_CHAIN_VAR = TEST_VAR.to(EventChain)
|
||||
ARG_VAR = Var(_js_expr="arg")
|
||||
|
||||
TEST_VAR_DICT_OF_DICT = LiteralVar.create({"a": {"b": "test"}})._replace(
|
||||
@ -2159,7 +2159,7 @@ class TriggerState(rx.State):
|
||||
rx.text("random text", on_click=TriggerState.do_something),
|
||||
rx.text(
|
||||
"random text",
|
||||
on_click=Var(_js_expr="toggleColorMode", _var_type=EventChain),
|
||||
on_click=Var(_js_expr="toggleColorMode").to(EventChain),
|
||||
),
|
||||
),
|
||||
True,
|
||||
@ -2169,7 +2169,7 @@ class TriggerState(rx.State):
|
||||
rx.text("random text", on_click=rx.console_log("log")),
|
||||
rx.text(
|
||||
"random text",
|
||||
on_click=Var(_js_expr="toggleColorMode", _var_type=EventChain),
|
||||
on_click=Var(_js_expr="toggleColorMode").to(EventChain),
|
||||
),
|
||||
),
|
||||
False,
|
||||
|
Loading…
Reference in New Issue
Block a user