Fallback for operator and other dunder methods
Dom Grigonis
dom.grigonis at gmail.com
Fri Aug 4 12:07:50 EDT 2023
The issue was more of a wrapping around numpy array. Found the solution already. Unfortunately, there is no equivalent to __getattr__, the only way is to dynamically define them from meta. It seems it’s pretty standard to just have a collection of special method names and using them for similar cases. Well, at least it’s what I got to. __getattr__ feels very hacky for such case, so maybe it’s for the best.
> On 2 Aug 2023, at 19:54, Edmondo Giovannozzi via Python-list <python-list at python.org> wrote:
>
> Il giorno mercoledì 26 luglio 2023 alle 20:35:53 UTC+2 Dom Grigonis ha scritto:
>> Tried exactly that and didn’t work. Neither __getattr__, nor __getattribute__ of meta is being invoked.
>>> On 26 Jul 2023, at 10:01, Chris Angelico via Python-list <pytho... at python.org <http://python.org/>> wrote:
>>>
>>> On Wed, 26 Jul 2023 at 16:52, Dom Grigonis <dom.gr <http://dom.gr/>... at gmail.com <http://gmail.com/>> wrote:
>>>>
>>>> Could you give an example? Something isn’t working for me.
>>>>
>>>
>>> This is a metaclass:
>>>
>>> class Meta(type):
>>> ...
>>> class Demo(metaclass=Meta):
>>> ...
>>>
>>> In order to catch those kinds of attribute lookups, you'll need the
>>> metaclass to hook them. And you might need to use __getattribute__
>>> rather than __getattr__. However, there may also be some checks that
>>> simply look for the presence of the attribute (see: slots), so you may
>>> find that it's even more complicated. It's usually easiest to just
>>> create the slots you want.
>>>
>>> ChrisA
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>
>
> For numpy arrays you can find some suggestion at:
> https://numpy.org/doc/stable/user/basics.dispatch.html <https://numpy.org/doc/stable/user/basics.dispatch.html>
> --
> https://mail.python.org/mailman/listinfo/python-list <https://mail.python.org/mailman/listinfo/python-list>
More information about the Python-list
mailing list