Re: Fallback for operator and other dunder methods

2023-07-25 Thread Dom Grigonis via Python-list
Could you give an example? Something isn’t working for me. > On 26 Jul 2023, at 09:40, Chris Angelico via Python-list > wrote: > > On Wed, 26 Jul 2023 at 12:23, Dom Grigonis via Python-list > wrote: >> print(a + 1)# TypeError: unsupported operand type(s) for +: 'A' >> and 'int' >>

Re: Fallback for operator and other dunder methods

2023-07-25 Thread Chris Angelico via Python-list
On Wed, 26 Jul 2023 at 12:23, Dom Grigonis via Python-list 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 ac

Fallback for operator and other dunder methods

2023-07-25 Thread Dom Grigonis via Python-list
To illustrate what I was trying to achieve: class A: def __init__(self, arr): self.arr = arr def __getattr__(self, name): arr_method = getattr(self.arr, name) def wrapper(*args, **kwargs): new_arr = arr_method(*args, **kwargs) return type(se