-
Notifications
You must be signed in to change notification settings - Fork 231
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
Best way to associate some data with ObjectProxy
?
#255
Comments
Can you give a high level explanation with usage examples of what you are trying to do rather than ask about what you think is the solution. I need to understand what your goal is to be able to suggest the best way, or even if you should be using wrapt at all, since it isn't a magic solution for everything and often not even needed. Anyway, what you are asking for sort of mirrors what some people have asked for before but never had a good solution. That is, maintain an attribute on the wrapper which isn't propagated through to the wrapped object, but not require a Now for whatever reason an idea of how to solve it just popped into my head for some reason. Rather funny that it has taken me so long to realise this could work.
Which yields:
|
Thanks. It's kinda embarrassing tho since I'm implementing some monkey patching for data hijack through a python system. The entire system have some sort of data passing around, each data can be handled with some sort of callback. The thing is the callbacks are kind of limited for my need but I found this way to workaround with it, which is to to associate some data with since modifying the system itself is basically a game of data chasing. I guess the linked issue is a dupe of this then? |
Can't say whether the other issue which I pointed at this one is a dupe or not since ultimately don't fully understand what your or other posters goals really are. Anyway, here is another way of tricking the Python attribute lookup mechanism.
IOW. Instead of defining a dummy class attribute, add |
Current my implementation works like this:
But the moment when
Wrapper
isWrapper(123)
or some other primitive values, this becomes unusable. I have also attempted to do the following:But unsure if it's reliable for the case when
self
itself havedata
or_self_dict
attribute when looking atProxy Object Attributes
section in the docs.The text was updated successfully, but these errors were encountered: