Fallback for operator and other dunder methods

Chris Angelico rosuav at gmail.com
Wed Jul 26 03:01:38 EDT 2023


On Wed, 26 Jul 2023 at 16:52, Dom Grigonis <dom.grigonis at 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


More information about the Python-list mailing list