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

Is (and/or Why) __str__, __repr__ are not patchable? #11

Open
guneysus opened this issue Dec 12, 2014 · 9 comments
Open

Is (and/or Why) __str__, __repr__ are not patchable? #11

guneysus opened this issue Dec 12, 2014 · 9 comments

Comments

@guneysus
Copy link

No description provided.

@guneysus guneysus changed the title Is (and/or Why) __str__, __repr__, etc are is not patchable? Is (and/or Why) __str__, __repr__ are not patchable? Dec 12, 2014
@clarete
Copy link
Owner

clarete commented Jan 15, 2016

Hello, sorry for the late response. forbiddenfruit is a really [lame] simple hack that exposes the __dict__ attribute of a python class. Magic methods and special protocols are resolved separately. forbiddenfruit would have to special case these methods and overwrite the right properties in the PyObject struct to allow patching these special guys.

It's possible but might take some digging to find out what to overwrite.

@alendit
Copy link
Contributor

alendit commented Feb 18, 2019

Hi, I assume it applies to all "dunders"? I.e. I tried to patch __matmul__ on FunctionType to implement function chaining. And although f.__matmul__(g) does the right think, f @ g doesn't seem to pick up the existence of the overwritten implementation.

Of course, f.chain(g) would do, too, but the ability to override the operator behaviour would add a wholly another level of the black magic and let me maniacally laugh at the code reviewer's tears, so it would be incredibly useful, as you might imagine.

@alexchandel
Copy link

This is resolved for methods defined in ff's PyTypeObject._fields_ or one of its method suites (e.g. PyNumberMethods) and added to override_dict. __repr__, __hash__, __call__, __iter__, and __next__ are still missing.

@pschanely
Copy link
Contributor

Just a quick +1 for getting __repr__ working; it would enable symbolic reasoning about repr strings in CrossHair.

@RadiantUwU
Copy link

__hash__ also doesnt work

@RadiantUwU
Copy link

Right now, im trying to patch hash on the forbiddenfruit module

@phy1729
Copy link

phy1729 commented Aug 11, 2021

I happen to be working in the same area. Looking to add __next__ which is proving troublesome because it can raise an exception. But I've added __repr__ and __hash__ on phy1729/complete-PyTypeObject

@MrFizzyBubbs
Copy link

+1 for __call__

@soamicharan
Copy link

please also add __getattr__ for patching

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

9 participants