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)
| 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 | |
| 197 | class EventSpec(EventActionsMixin): |
nothing calls this directly
no test coverage detected