clarete/forbiddenfruit

Monkey-patching `__init__` returns KeyError

davips opened this issue · 3 comments

However, somehow @alendit managed to fix it in an older version at
https://github.com/alendit/forbiddenfruit

Is there any pypi package I could import that allows __init__ patching?

Oh, we haven't released in a while. Would you mind checking if the code on master has your issue fixed? Thanks for opening the issue!

Same as before:

In [10]: curse(list, "__init__", lambda x:x*x)                                                           
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-10-ac8633fa62a8> in <module>
----> 1 curse(list, "__init__", lambda x:x*x)

/tmp/forbiddenfruit/forbiddenfruit/__init__.py in curse(klass, attr, value, hide_from_dir)
    435             raise NotImplementedError(
    436                 "Dunder overloading is only supported on Python >= 3.3")
--> 437         _curse_special(klass, attr, value)
    438         return
    439 

/tmp/forbiddenfruit/forbiddenfruit/__init__.py in _curse_special(klass, attr, func)
    342             return NotImplementedRet
    343 
--> 344     tp_as_name, impl_method = override_dict[attr]
    345 
    346     # get the pointer to the correct tp_as_* structure

KeyError: '__init__'

I'm also seeing this issue for __setattr__. Is there a known fix?