<div dir="ltr"><div dir="ltr"><div>Hi again,</div><div><br></div><div>Another thought about __array_function__, this time about the implementation for ndarray. In it, we currently check whether any of the types define a (different) __array_function__, and, if so, give up. This seems too strict: I think that, at least in principle, subclasses should be allowed through even if they override __array_function__.</div><div><br></div><div>This thought was triggered by Travis pointing to the Liskov substitution principle [1], that code written for a given type should just work on a (properly written) subclass. This suggests `ndarray` should not exclude subclasses even if they override __array_function__, since if the subclass does not work that way, it can already ensure an error is raised since it knows it is called first.<br></div><div><br></div><div> Indeed, this is also how python itself works: if, eg., I subclass list as follows:</div><div>```</div><div>class MyList(list):</div><div>    def __radd__(self, other):</div><div>        return NotImplemented</div><div>```</div><div>then any `list + mylist` will just concatenate the lists, even though `MyList.__radd__` explicitly tells it cannot do it (it returning `NotImplemented` means that  `list.__add__` gets a change).<br></div><div><br></div><div></div><div>The reason that we do not already follow this logic may be that currently `ndarray.__array_function__` ends by calling the public function, which will lead to infinite recursion if there is a subclass that overrides __array_function__ and returns NotImplemented. However, inside ndarray.__array_function__, there is no real reason to call the public function - one might as well just call the implementation, in which case this is not a problem.</div><div><br></div><div>Does the above make sense? I realize that the same would be true for `__array_ufunc__`, though there the situation is slightly trickier since it is not as easy to bypass any further override checks. Nevertheless, it does seem like it would be correct to do the same there. (And if we agree this is the case, I'd quite happily implement it -- with the merger of multiarray and umath it has become much easier to do.)<br></div><div><br></div><div>All the best,</div><div><br></div><div>Marten<br></div><div><br></div><div>[1] <a href="https://en.wikipedia.org/wiki/Liskov_substitution_principle">https://en.wikipedia.org/wiki/Liskov_substitution_principle</a><br></div></div></div>