From a7eae533099eca6b680b1c85b4c7402462b411d1 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Mon, 21 Oct 2024 12:36:41 -0700 Subject: [PATCH] add custom type --- reflex/state.py | 9 +++++---- reflex/utils/exceptions.py | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/reflex/state.py b/reflex/state.py index fb05d558f..8fb18e880 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -76,6 +76,7 @@ from reflex.utils import console, format, path_ops, prerequisites, types from reflex.utils.exceptions import ( ComputedVarShadowsBaseVars, ComputedVarShadowsStateVar, + DynamicComponentInvalidSignature, DynamicRouteArgShadowsStateVar, EventHandlerShadowsBuiltInStateMethod, ImmutableStateError, @@ -2105,8 +2106,8 @@ def dynamic(func: Callable[[T], Component]): The dynamically generated component. Raises: - ValueError: If the function does not have exactly one parameter. - ValueError: If the function does not have a type hint for the state class. + DynamicComponentInvalidSignature: If the function does not have exactly one parameter. + DynamicComponentInvalidSignature: If the function does not have a type hint for the state class. """ number_of_parameters = len(inspect.signature(func).parameters) @@ -2118,12 +2119,12 @@ def dynamic(func: Callable[[T], Component]): values = list(func_signature.values()) if number_of_parameters != 1: - raise ValueError( + raise DynamicComponentInvalidSignature( "The function must have exactly one parameter, which is the state class." ) if len(values) != 1: - raise ValueError( + raise DynamicComponentInvalidSignature( "You must provide a type hint for the state class in the function." ) diff --git a/reflex/utils/exceptions.py b/reflex/utils/exceptions.py index 35f59a0e1..f74c078fe 100644 --- a/reflex/utils/exceptions.py +++ b/reflex/utils/exceptions.py @@ -135,3 +135,7 @@ class SetUndefinedStateVarError(ReflexError, AttributeError): class StateSchemaMismatchError(ReflexError, TypeError): """Raised when the serialized schema of a state class does not match the current schema.""" + + +class DynamicComponentInvalidSignature(ReflexError, TypeError): + """Raised when a dynamic component has an invalid signature."""