-
-
Notifications
You must be signed in to change notification settings - Fork 0
Object Watchdog uses existing instance instead of creating new instances #1
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
Comments
Is there a fix for this? I have the same issue which makes the package pretty much useless... |
Not yet. I have the issue in the queue, but other projects with sponsorship have preference |
I've been doing a bit of debugging and think I found the issue. I've created my own version which doesn't use metaclass but regular inheritence. This works great. class DataObserver:
__observableAttrs__ = []
__observers = []
def __setattr__(self, key, value):
self.__dict__[key] = value
if key in self.__observableAttrs__:
for observer in self.__observers:
observer(self, key, value)
def addObserver(self, fn):
self.__observers.append(fn) |
This package seems to do exactly what I need, but this is indeed a major issue. |
@idotzang I made a tiny package encapsulating this functionality, it may help - https://github.com/saurabh0719/object-tracker |
Sorry, but currently, I not have so much time to maintain this package, sorry. A PR sounds great :) |
Imagine having the following snippet:
What do we expect? We expect
a.number == 1
andb.number == 2
. However, when printing thea.number
we see2
(!). Adding a print statement before setting the number at initialization level (print(hasattr(self, "number"))
) reveals thatself.number
is already set on instanceb
.The text was updated successfully, but these errors were encountered: