MCPcopy Create free account
hub / github.com/dot-agent/nextpy / __call__

Method __call__

nextpy/backend/event.py:157–194  ·  view source on GitHub ↗

Pass arguments to the handler to get an event spec. This method configures event handlers that take in arguments. Args: *args: The arguments to pass to the handler. Returns: The event spec, containing both the function and args. Raises:

(self, *args: Var)

Source from the content-addressed store, hash-verified

155 return getattr(self.fn, BACKGROUND_TASK_MARKER, False)
156
157 def __call__(self, *args: Var) -> EventSpec:
158 """Pass arguments to the handler to get an event spec.
159
160 This method configures event handlers that take in arguments.
161
162 Args:
163 *args: The arguments to pass to the handler.
164
165 Returns:
166 The event spec, containing both the function and args.
167
168 Raises:
169 TypeError: If the arguments are invalid.
170 """
171 # Get the function args.
172 fn_args = inspect.getfullargspec(self.fn).args[1:]
173 fn_args = (Var.create_safe(arg) for arg in fn_args)
174
175 # Construct the payload.
176 values = []
177 for arg in args:
178 # Special case for file uploads.
179 if isinstance(arg, FileUpload):
180 return arg.as_event_spec(handler=self)
181
182 # Otherwise, convert to JSON.
183 try:
184 values.append(Var.create(arg, _var_is_string=type(arg) is str))
185 except TypeError as e:
186 raise TypeError(
187 f"Arguments to event handlers must be Vars or JSON-serializable. Got {arg} of type {type(arg)}."
188 ) from e
189 payload = tuple(zip(fn_args, values))
190
191 # Return the event spec.
192 return EventSpec(
193 handler=self, args=payload, event_actions=self.event_actions.copy()
194 )
195
196
197class EventSpec(EventActionsMixin):

Callers

nothing calls this directly

Calls 6

EventSpecClass · 0.90
create_safeMethod · 0.80
as_event_specMethod · 0.80
appendMethod · 0.45
createMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected