I am trying to wrap functions using a C object in NumPy (this speeds up things quite a lot due to avoiding **kwargs
back and forth. The reason is that we have a dispatching mechanism, and this seemed like a decent approach. (There is another approach but it would also subtly change behavior).
Now a small beauty (or maybe real) issue is that e.g. sphinx use inspect.isroutine()
to decides that this means its a :py:func:
(rather than :py:data:
and I cannot be certain that others don’t expect similar.
A possible fix would seem to be to just subclass MethodType
in C (or even FunctionType
), but that seems rather overstepping, so I am curious if there is prior art that does similarly evil things (or a clean way to do the same).
So this code:
@c_defined_object
def func(a, b, c=3):
# do things
should return a C callable, but look as much like the original function as possible (and e.g. have __wrapped__
, but hopefully more).