On Wed, 26 Jul 2023 at 12:23, Dom Grigonis via Python-list <python-list@python.org> wrote: > print(a + 1) # TypeError: unsupported operand type(s) for +: 'A' > and 'int' > > Is there a way to achieve it without actually implementing operators? > I have looked at Proxy objects, but they do not seem suited to achieve this. > (e.g. wrapt)
These kinds of special methods are not looked up on the object, but on the type. It's more like type(a).__add__(a, 1). So you would need a metaclass for this. ChrisA -- https://mail.python.org/mailman/listinfo/python-list