event.remove fails when used for method in 0.9

Issue #2832 resolved
Denis Otkidach created an issue

_EventKey._key uses id() of listener function. This causes problem when method is used since in python new method object (with different id, but equal when compared with ==) is created each time it's accessed. As a result event.remove fails for it with exception "InvalidRequestError: No listeners found for event …".

Comments (3)

  1. Mike Bayer repo owner

    I think I might have known that. will have to see if the id() logic can be more intelligent

    diff --git a/test/base/test_events.py b/test/base/test_events.py
    index d2bfb09..57da149 100644
    --- a/test/base/test_events.py
    +++ b/test/base/test_events.py
    @@ -966,6 +966,27 @@ class RemovalTest(fixtures.TestBase):
    
             eq_(m1.mock_calls, [call("x")](call("x")))
    
    +    def test_instance(self):
    +        Target = self._fixture()
    +
    +        m1 = Mock()
    +        class Foo(object):
    +            def evt(self, arg):
    +                m1(arg)
    +
    +        f1 = Foo()
    +
    +        event.listen(Target, "event_one", f1.evt)
    +
    +        t1 = Target()
    +        t1.dispatch.event_one("x")
    +
    +        event.remove(Target, "event_one", f1.evt)
    +
    +        t1.dispatch.event_one("y")
    +
    +        eq_(m1.mock_calls, [call("x")](call("x")))
    +
         def test_propagate(self):
             Target = self._fixture()
    
  2. Log in to comment