clarete / forbiddenfruit

Patch built-in python objects
https://clarete.li/forbiddenfruit/
GNU General Public License v3.0
826 stars 52 forks source link

Redefined magic methods are not inherited #29

Open voidworker opened 5 years ago

voidworker commented 5 years ago

Cursing object type is not working as expected. It is ok for ordinary methods:

>>> from forbiddenfruit import curse
>>> curse(object, 'f', lambda x: print("boo"))
>>> [].f()
boo

But not for magic methods:

>>> from forbiddenfruit import curse
>>> curse(object, '__matmul__', (lambda x, y: y(x)))
>>> [1,2,3] @ len
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for @: 'list' and 'builtin_function_or_method'

Little testing shows that subclasses do not inherit redefined magic methods.

@alendit , please, could you pay some attention to this?