> I did a little more digging, and turned up the __self__ and __func__
> attributes of bound methods:
> https://stackoverflow.com/questions/4679592/how-to-find-
> instance-of-a-bound-method-in-python
>
> So we might need another decorator function, but it seems that the current
> interface would actually suffice just fine for overriding methods. I'll
> update the NEP with some examples. It will look something like:
>
> def __array_function__(self, func, types, args, kwargs):
>   ...
>   if isinstance(func, types.MethodType):
>     object = func.__self__
>     unbound_func = func.__func__
>     ...
>
>
For C classes like the ufuncs, it seems `__self__` is defined for methods
as well (at least, `np.add.reduce.__self__` gives `np.add`), but not a
`__func__`. There is a `__name__` (="reduce"), though, which means that I
think one can still retrieve what is needed (obviously, this also means
`__array_ufunc__` could have been simpler...)

-- Marten
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to