@@ -388,53 +388,39 @@ def _inner(cls: type[Executor]) -> type:
388388 return _inner
389389
390390
391- class _EmptyFunctionSpec (FunctionSpec ):
391+ class EmptyFunctionSpec (FunctionSpec ):
392392 pass
393393
394394
395395class _SimpleFunctionExecutor :
396- spec : Any
396+ spec : Callable [..., Any ]
397397
398398 def prepare (self ) -> None :
399- self .__call__ = self .spec . __call__
399+ self .__call__ = staticmethod ( self .spec )
400400
401401
402- def function (** args : Any ) -> Callable [[Callable [..., Any ]], FunctionSpec ]:
402+ def function (** args : Any ) -> Callable [[Callable [..., Any ]], Callable [..., Any ] ]:
403403 """
404404 Decorate a function to provide a function for an op.
405405 """
406406 op_args = OpArgs (** args )
407407
408- def _inner (fn : Callable [..., Any ]) -> FunctionSpec :
408+ def _inner (fn : Callable [..., Any ]) -> Callable [..., Any ] :
409409 # Convert snake case to camel case.
410- op_name = "" .join (word .capitalize () for word in fn .__name__ .split ("_" ))
410+ op_kind = "" .join (word .capitalize () for word in fn .__name__ .split ("_" ))
411411 sig = inspect .signature (fn )
412- full_name = f"{ fn .__module__ } .{ fn .__qualname__ } "
413-
414- # An object that is both callable and can act as a FunctionSpec.
415- class _CallableSpec (_EmptyFunctionSpec ):
416- __call__ = staticmethod (fn )
417-
418- def __reduce__ (self ) -> str | tuple [Any , ...]:
419- return full_name
420-
421- _CallableSpec .__name__ = op_name
422- _CallableSpec .__doc__ = fn .__doc__
423- _CallableSpec .__qualname__ = fn .__qualname__
424- _CallableSpec .__module__ = fn .__module__
425- callable_spec = _CallableSpec ()
426-
412+ fn .__cocoindex_op_kind__ = op_kind # type: ignore
427413 _register_op_factory (
428414 category = OpCategory .FUNCTION ,
429415 expected_args = list (sig .parameters .items ()),
430416 expected_return = sig .return_annotation ,
431417 executor_factory = _SimpleFunctionExecutor ,
432- spec_loader = lambda : callable_spec ,
433- op_kind = op_name ,
418+ spec_loader = lambda : fn ,
419+ op_kind = op_kind ,
434420 op_args = op_args ,
435421 )
436422
437- return callable_spec
423+ return fn
438424
439425 return _inner
440426
0 commit comments