DanielSank / observed

Observer pattern in python
MIT License
33 stars 4 forks source link

event access doesn't keep object alive #4

Closed coldfix closed 10 years ago

coldfix commented 10 years ago

I noticed a bug, which went into early versions of obsub as well (by use of weak references, in fact). Access to bound methods is supposed to keep objects alive. You should always be able to do something like result = temporary_object.method().

Example:

from observed import event

class Foo(object):
    @event
    def bar(self):
        print(self)

Foo().bar()   # prints: None

Note, that this can occur in much more subtle places, for example when using the result of an expression (result of an operator or function call).

DanielSank commented 10 years ago

I believe this issue is corrected in the new dedicatedClasses branch. Thank you very much for you feedback. I am learning very much very quickly here.

DanielSank commented 10 years ago

The example given in the original post is now fixed, and I don't see any further issues related to this.