99
1010from pydantic import BaseModel , RootModel
1111
12- from ..constants import JSON
13- from ..param .parameterized import ParameterizedFunction
14- from ..schema_validators .validators import JSONSchemaValidator , PydanticSchemaValidator
15- from ..utils import (
12+ from hololinked import SchemaValidatorClasses
13+ from hololinked .constants import JSON
14+ from hololinked .core .exceptions import StateMachineError
15+ from hololinked .param .parameterized import ParameterizedFunction
16+ from hololinked .utils import (
1617 get_input_model_from_signature ,
1718 get_return_type_from_signature ,
1819 has_async_def ,
1920 isclassmethod ,
2021 issubklass ,
2122)
23+
2224from .dataklasses import ActionInfoValidator
23- from .exceptions import StateMachineError
2425
2526
2627class Action :
2728 """
2829 Object that models an action.
30+
2931 These actions are unbound and return a bound action when accessed using the owning object.
3032 """
3133
3234 __slots__ = ["obj" , "owner" , "_execution_info" ]
3335
3436 def __init__ (self , obj : MethodType ) -> None :
3537 """
38+ Initialize an Action.
39+
3640 Parameters
3741 ----------
3842 obj: MethodType
@@ -69,13 +73,13 @@ def __call__(self, *args, **kwargs):
6973
7074 @property
7175 def name (self ) -> str :
72- """name of the action"""
76+ """Name of the action. """
7377 return self .obj .__name__
7478
7579 @property
7680 def execution_info (self ) -> ActionInfoValidator :
7781 """
78- internal dataclass that holds all information about the action
82+ Internal dataclass that holds all information about the action.
7983
8084 TODO: this can be refactored
8185 """
@@ -107,9 +111,7 @@ def to_affordance(self, owner_inst=None):
107111
108112
109113class BoundAction :
110- """
111- A bound action - base class for both sync and async methods.
112- """
114+ """A bound action, base class for both sync and async methods."""
113115
114116 __slots__ = [
115117 "obj" ,
@@ -173,14 +175,14 @@ def validate_call(self, args, kwargs: dict[str, Any]) -> None:
173175
174176 @property
175177 def name (self ) -> str :
176- """name of the action"""
178+ """Name of the action. """
177179 return self .obj .__name__
178180
179181 def __call__ (self , * args , ** kwargs ):
180182 raise NotImplementedError ("call must be implemented by subclass" )
181183
182184 def external_call (self , * args , ** kwargs ):
183- """validated call to the action with state machine and payload checks"""
185+ """Validated call to the action with state machine and payload checks. """
184186 raise NotImplementedError ("external_call must be implemented by subclass" )
185187
186188 def __str__ (self ):
@@ -224,7 +226,7 @@ class BoundSyncAction(BoundAction):
224226 """
225227
226228 def external_call (self , * args , ** kwargs ):
227- """validated call to the action with state machine and payload checks"""
229+ """Validated call to the action with state machine and payload checks"""
228230 self .validate_call (args , kwargs )
229231 return self .__call__ (* args , ** kwargs )
230232
@@ -241,7 +243,7 @@ class BoundAsyncAction(BoundAction):
241243 """
242244
243245 async def external_call (self , * args , ** kwargs ):
244- """validated call to the action with state machine and payload checks"""
246+ """Validated call to the action with state machine and payload checks"""
245247 self .validate_call (args , kwargs )
246248 return await self .__call__ (* args , ** kwargs )
247249
@@ -358,9 +360,9 @@ def inner(obj):
358360 )
359361 if input_schema :
360362 if isinstance (input_schema , dict ):
361- execution_info_validator .schema_validator = JSONSchemaValidator (input_schema )
363+ execution_info_validator .schema_validator = SchemaValidatorClasses . json_schema (input_schema )
362364 elif issubklass (input_schema , (BaseModel , RootModel )):
363- execution_info_validator .schema_validator = PydanticSchemaValidator (input_schema )
365+ execution_info_validator .schema_validator = SchemaValidatorClasses . pydantic (input_schema )
364366 else :
365367 raise TypeError (
366368 "input schema must be a JSON schema or a Pydantic model, got {}" .format (type (input_schema ))
0 commit comments