amol- commented on a change in pull request #10581:
URL: https://github.com/apache/arrow/pull/10581#discussion_r662228994



##########
File path: python/pyarrow/compute.py
##########
@@ -197,16 +215,13 @@ def _wrap_function(name, func):
     args_sig = ', '.join(arg_names)
     kwonly = '' if arg_names[-1].startswith('*') else ', *'
 
-    # Generate templated wrapper, so that the signature matches
-    # the documented argument names.
-    ns = {}
-    if option_class is not None:
-        template = _wrapper_options_template
-    else:
-        template = _wrapper_template
-    exec(template.format(func_name=name, args_sig=args_sig, kwonly=kwonly),
-         globals(), ns)
-    wrapper = ns['make_wrapper'](func, option_class)
+    # We make a generic wrapper with a simple argument-handling
+    # machinery, but we also add a __wrapped__ attribute pointing
+    # to a dummy callable with the desired signature for introspection
+    # and documentation.
+    wrapper = _make_generic_wrapper(name, func, option_class)
+    wrapper.__wrapped__ = _make_dummy_equivalent(args_sig, kwonly,
+                                                 option_class)

Review comment:
       Uhm, if our only goal is to fake the signature, why not just use 
``__signature__`` or ``__text_signature__`` which are available to expose 
signatures of C functions?
   
   Like
   
   ```
   def create_function(f_name, args):
       real_func = getattr(__builtins__, f_name)
       def f_impl(*args, **kwargs):
           return real_func(*args)
       f_impl.__name__ = f_name
       f_impl.__text_signature__ = "(a, b)"
       return f_impl
   
   import inspect
   f = create_function("min", ("a", "b"))
   print(f.__name__, inspect.signature(f), f(1, 2))
   ```
   
   That seem to achieve the same goal without any compile or ``__wrapped__`` 
magic




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to