Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monkey-patching __init__ returns KeyError #38

Open
davips opened this issue Feb 7, 2020 · 3 comments
Open

Monkey-patching __init__ returns KeyError #38

davips opened this issue Feb 7, 2020 · 3 comments

Comments

@davips
Copy link

davips commented Feb 7, 2020

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?

@clarete
Copy link
Owner

clarete commented Feb 22, 2020

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!

@davips
Copy link
Author

davips commented Feb 28, 2020

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__'

@BeBopping
Copy link

BeBopping commented Dec 5, 2020

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

pschanely added a commit to pschanely/forbiddenfruit that referenced this issue Feb 16, 2021
Somewhat related to clarete#38
I'm not sure how ugly it is to leave void pointer placeholders
in the structure declaration.
clarete pushed a commit that referenced this issue May 23, 2021
Somewhat related to #38
I'm not sure how ugly it is to leave void pointer placeholders
in the structure declaration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants