-
Notifications
You must be signed in to change notification settings - Fork 235
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
Dunder attributes added to wrapped function objects #282
Comments
Am aware of complications that can occur for this in certain cases. Can you explain how this is causing an issue in your specific case? The cases I am aware of tend to resolve around special methods like |
Sorry, I was trying to simplify as much as possible and used |
Yep, that is the exact one I mainly know about causing problems. The thought on that one, but haven't got around to trying it, is not to have the |
That's an interesting idea. I won't have a chance to try it out until next week, but it sounds promising. I'll let you know how it goes. |
The following update to the pure-python implementation seems to be working for my case, and the class ObjectProxy(with_metaclass(_ObjectProxyMetaType)):
# [...]
def __init__(self, wrapped):
# [...]
try:
object.__setattr__(self, '__iter__', wrapped.__iter__)
except AttributeError:
pass Not sure if this is the most correct or efficient way to do things though. Would you consider adding something like this? |
Something like that is indeed what I was thinking of. Although I was stupidly thinking that would need to have a |
Thanks for the guidance so far. Unfortunately I haven't yet been able to get something similar working in the C extension. Do you have any hints or ideas for what this might look like in extension code? If it helps, I've tried removing |
Can you show the actual code you used along with full description from the error. Want to double check no reference counting issues. Also, some of the dunder methods are a bit special and need to be on the class type when it is implemented in C and having them as attribute is a problem. Am not aware of iter being one of those though. |
Here's the diff: develop...lazorchakp:wrapt:conditionally-iterable-object-proxies The full error from
Tests pass with |
What happens if just do:
Does that even fail? |
This fails with the same error:
|
I've come across a case similar to #93 - I have wrapped a function using a
wrapt.function_wrapper
, but this adds attributes (dunder methods) to the resulting function that are not present on the unwrapped function.The original issue discusses several difficulties with implementing a fix on ObjectProxy. I'm wondering if limiting the scope of a fix to just FunctionWrapper would be more reasonable / acceptable.
A simplified demonstration of the issue:
I'm mostly curious about the feasibility of defining
__getattribute__
on FunctionWrapper (or possibly _FunctionWrapperBase). I understand that doing this directly on ObjectProxy would have too much of a negative performance impact, but I don't expect attribute access to occur often enough on function objects for this to be a concern for FunctionWrappers. I've tried out a few fixes, but so far haven't been able to come up with a correct implementation.The text was updated successfully, but these errors were encountered: