<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Jun 27, 2018 at 12:50 PM Stephan Hoyer <<a href="mailto:shoyer@gmail.com" target="_blank">shoyer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">One concern this does raise is how to handle methods like those on RandomState, even though methods like random_like() don't currently exist. Distribution objects from scipy.stats could have similar use cases.<br></div></div></div><div dir="ltr"><div class="gmail_quote"><div><br></div><div>So perhaps it's worth "future proofing" the interface by passing `obj` and `method` to __array_function__ rather than only `func`. It is slower to call a func via func.__call__ than func, but only very marginally (~100 ns in my tests).</div></div></div></blockquote><div><br></div></div><div dir="ltr"><div class="gmail_quote"><div>I did a little more digging, and turned up the __self__ and __func__ attributes of bound methods:</div><div><a href="https://stackoverflow.com/questions/4679592/how-to-find-instance-of-a-bound-method-in-python" target="_blank">https://stackoverflow.com/questions/4679592/how-to-find-instance-of-a-bound-method-in-python</a><br></div><div><br></div><div>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:</div><div><br></div><div>def __array_function__(self, func, types, args, kwargs):</div><div>  ...</div><div>  if isinstance(func, types.MethodType):</div><div>    object = func.__self__</div><div>    unbound_func = func.__func__</div><div>    ...</div><div><br></div><div>Given that functions are the most common case, I think it's best to keep with `func` as the main interface, but it's good to know that this does not preclude overriding methods.</div><div><br></div></div></div></div>