Valid to subclass `MethodType` from C (or: how to make a C object look and feel as much as function as possible)?

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 :slight_smile: (or a clean way to do the same).

So this code:

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).

Ah well, I think I will probably just monkey-patch sphinx. Although, if anyone has some similar pattern elsewhere, I would be curious to see it.