change form and improve type checking
This commit is contained in:
parent
437848f5b9
commit
eecc94f866
@ -102,7 +102,7 @@ class Fieldset(Element):
|
|||||||
name: Var[Union[str, int, bool]]
|
name: Var[Union[str, int, bool]]
|
||||||
|
|
||||||
|
|
||||||
def on_submit_event_spec() -> Tuple[Var[Dict[str, Any]]]:
|
def on_submit_event_spec() -> Tuple[Var[Dict[str, str]]]:
|
||||||
"""Event handler spec for the on_submit event.
|
"""Event handler spec for the on_submit event.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -270,7 +270,7 @@ class Fieldset(Element):
|
|||||||
"""
|
"""
|
||||||
...
|
...
|
||||||
|
|
||||||
def on_submit_event_spec() -> Tuple[Var[Dict[str, Any]]]: ...
|
def on_submit_event_spec() -> Tuple[Var[Dict[str, str]]]: ...
|
||||||
|
|
||||||
class Form(BaseHTML):
|
class Form(BaseHTML):
|
||||||
@overload
|
@overload
|
||||||
@ -337,7 +337,7 @@ class Form(BaseHTML):
|
|||||||
on_mouse_over: Optional[EventType[[]]] = None,
|
on_mouse_over: Optional[EventType[[]]] = None,
|
||||||
on_mouse_up: Optional[EventType[[]]] = None,
|
on_mouse_up: Optional[EventType[[]]] = None,
|
||||||
on_scroll: Optional[EventType[[]]] = None,
|
on_scroll: Optional[EventType[[]]] = None,
|
||||||
on_submit: Optional[EventType[Dict[str, Any]]] = None,
|
on_submit: Optional[EventType[Dict[str, str]]] = None,
|
||||||
on_unmount: Optional[EventType[[]]] = None,
|
on_unmount: Optional[EventType[[]]] = None,
|
||||||
**props,
|
**props,
|
||||||
) -> "Form":
|
) -> "Form":
|
||||||
|
@ -129,7 +129,7 @@ class FormRoot(FormComponent, HTMLForm):
|
|||||||
on_mouse_over: Optional[EventType[[]]] = None,
|
on_mouse_over: Optional[EventType[[]]] = None,
|
||||||
on_mouse_up: Optional[EventType[[]]] = None,
|
on_mouse_up: Optional[EventType[[]]] = None,
|
||||||
on_scroll: Optional[EventType[[]]] = None,
|
on_scroll: Optional[EventType[[]]] = None,
|
||||||
on_submit: Optional[EventType[Dict[str, Any]]] = None,
|
on_submit: Optional[EventType[Dict[str, str]]] = None,
|
||||||
on_unmount: Optional[EventType[[]]] = None,
|
on_unmount: Optional[EventType[[]]] = None,
|
||||||
**props,
|
**props,
|
||||||
) -> "FormRoot":
|
) -> "FormRoot":
|
||||||
@ -594,7 +594,7 @@ class Form(FormRoot):
|
|||||||
on_mouse_over: Optional[EventType[[]]] = None,
|
on_mouse_over: Optional[EventType[[]]] = None,
|
||||||
on_mouse_up: Optional[EventType[[]]] = None,
|
on_mouse_up: Optional[EventType[[]]] = None,
|
||||||
on_scroll: Optional[EventType[[]]] = None,
|
on_scroll: Optional[EventType[[]]] = None,
|
||||||
on_submit: Optional[EventType[Dict[str, Any]]] = None,
|
on_submit: Optional[EventType[Dict[str, str]]] = None,
|
||||||
on_unmount: Optional[EventType[[]]] = None,
|
on_unmount: Optional[EventType[[]]] = None,
|
||||||
**props,
|
**props,
|
||||||
) -> "Form":
|
) -> "Form":
|
||||||
@ -716,7 +716,7 @@ class FormNamespace(ComponentNamespace):
|
|||||||
on_mouse_over: Optional[EventType[[]]] = None,
|
on_mouse_over: Optional[EventType[[]]] = None,
|
||||||
on_mouse_up: Optional[EventType[[]]] = None,
|
on_mouse_up: Optional[EventType[[]]] = None,
|
||||||
on_scroll: Optional[EventType[[]]] = None,
|
on_scroll: Optional[EventType[[]]] = None,
|
||||||
on_submit: Optional[EventType[Dict[str, Any]]] = None,
|
on_submit: Optional[EventType[Dict[str, str]]] = None,
|
||||||
on_unmount: Optional[EventType[[]]] = None,
|
on_unmount: Optional[EventType[[]]] = None,
|
||||||
**props,
|
**props,
|
||||||
) -> "Form":
|
) -> "Form":
|
||||||
|
@ -1015,17 +1015,23 @@ def call_event_handler(
|
|||||||
"See https://reflex.dev/docs/events/event-arguments/"
|
"See https://reflex.dev/docs/events/event-arguments/"
|
||||||
)
|
)
|
||||||
|
|
||||||
def compare_types(specific_type, accepted_type):
|
def compare_types(provided_type, accepted_type):
|
||||||
# Check if both are generic types (e.g., List)
|
# Check if both are generic types (e.g., List)
|
||||||
if get_origin(specific_type) != get_origin(accepted_type):
|
if (get_origin(provided_type) or provided_type) != (
|
||||||
|
get_origin(accepted_type) or accepted_type
|
||||||
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Get type arguments (e.g., int vs. Union[float, int])
|
# Get type arguments (e.g., int vs. Union[float, int])
|
||||||
specific_args = get_args(specific_type)
|
provided_args = get_args(provided_type)
|
||||||
accepted_args = get_args(accepted_type)
|
accepted_args = get_args(accepted_type)
|
||||||
|
|
||||||
# Ensure all specific types are compatible with accepted types
|
# Ensure all specific types are compatible with accepted types
|
||||||
return all(issubclass(s, a) for s, a in zip(specific_args, accepted_args))
|
return all(
|
||||||
|
issubclass(provided_arg, accepted_arg)
|
||||||
|
for provided_arg, accepted_arg in zip(provided_args, accepted_args)
|
||||||
|
if accepted_arg is not Any
|
||||||
|
)
|
||||||
|
|
||||||
event_spec_return_type = get_type_hints(arg_spec).get("return", None)
|
event_spec_return_type = get_type_hints(arg_spec).get("return", None)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user