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

Cursing dunder methods fails with: KeyError: '<method_to_curse>' #61

Open
sgerodes opened this issue Jul 30, 2021 · 5 comments
Open

Cursing dunder methods fails with: KeyError: '<method_to_curse>' #61

sgerodes opened this issue Jul 30, 2021 · 5 comments

Comments

@sgerodes
Copy link

sgerodes commented Jul 30, 2021

curse(str, '__eq__', str.__ne__)

fails with:
...

  File ".../python3.6/site-packages/forbiddenfruit/__init__.py", line 425, in curse
    _curse_special(klass, attr, value)
  File ".../python3.6/site-packages/forbiddenfruit/__init__.py", line 332, in _curse_special
    tp_as_name, impl_method = override_dict[attr]
KeyError: '__eq__'

Also other dunder methods fails. e.g.:

curse(int, '__new__', <some other method>)
curse(float, '__dict__', <some other method>)
@sgerodes sgerodes changed the title Cursing dunder methods fails Cursing dunder methods fails with "KeyError: '<method_to_curse>'" Jul 30, 2021
@sgerodes sgerodes changed the title Cursing dunder methods fails with "KeyError: '<method_to_curse>'" Cursing dunder methods fails with: KeyError: '<method_to_curse>' Jul 30, 2021
@Objectivitix
Copy link

Objectivitix commented Aug 4, 2021

I've had the same problems as well. I was messing around with dunders, and some raise KeyError where the attr definitely exists (I checked with __dict__ and similar things). However, this is peculiar:

image

It didn't raise an error.
Do only some dunders not work?

@Objectivitix
Copy link

Also, other issues with the same format (cursing __something__ fails) seem to be the same problem, but just more specific (cursing __init__ fails, __iter__ fails, etc)

@RadiantUwU
Copy link

__str__ and __new__ have been registered

@RadiantUwU
Copy link

and my pull request will register a lot more
You know what? Ill try to register them all.

@Keyacom
Copy link

Keyacom commented Nov 8, 2022

Another proof that cursing dunder methods fails.

I was trying to make numeric types callable, to implement implicit multiplication as it's known in some programming languages such as Julia.

from forbiddenfruit import curse, reverse

def __call__(self, other, /):
  return self * other

for cls in (int, float, complex):
  curse(cls, "__call__", __call__)

print(2(6))

This of course gave a SyntaxWarning that int objects are not callable, but also threw a KeyError: '__call__'.

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

4 participants