`remove_handler` does not remove a registered handler
Describe the bug
Calling remove_handler does not remove a previously registered handler.
To Reproduce Steps to reproduce the behavior, or sample code that shows the bug.
def test_remove_handler():
import esper
handler_called = False
def handler(_):
nonlocal handler_called
handler_called = True
esper.set_handler("foo", handler)
esper.remove_handler("foo", handler)
esper.dispatch_event("foo", None) # Dispatch the event to trigger the handler
esper.process()
assert not handler_called, "Handler was not removed correctly."
Expected behavior Handler is removed
Development environment:
- Python 3.10
- Esper 3.3
Additional context Add any other context about the problem here.
I think the comparison of the function passed to remove_handler with the weakref to the function stored in the registry fails.
Thanks for opening the ticket. I think your analysis is correct. I'll make a fix for this soon.
remove_handler has a guard check that compares the passed func to its weakref, however that comparison would always fail.
I could make a PR to make a weakref from the passed func, and use that in the guard check. If you agree with the change
HI @maxlebedev, this is what I was planning to do, but havn't had a chance to knock it out. If you are up to it, please go ahead.
Just made a PR https://github.com/benmoran56/esper/pull/107
Just realized we still had this open, even though it's merged and released. Thanks again!