Skip to content
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

Allow Registering and unregistering instance methods as listeners #102

Merged
merged 4 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changes
4.4.4 (unreleased)
------------------

- Nothing changed yet.
- Allow registering and unregistering instance methods as listeners.
See `issue 12 <https://github.com/zopefoundation/zope.interface/issues/12>`_
and `PR 102 <https://github.com/zopefoundation/zope.interface/pull/102>`_.


4.4.3 (2017-09-22)
Expand Down
2 changes: 1 addition & 1 deletion src/zope/interface/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def unsubscribe(self, required, provided, value=None):
if value is None:
new = ()
else:
new = tuple([v for v in old if v is not value])
new = tuple([v for v in old if v != value])

if new == old:
return
Expand Down
11 changes: 11 additions & 0 deletions src/zope/interface/tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ def test_unsubscribe_with_value_not_None_miss(self):
registry.subscribe([IB1], None, orig)
registry.unsubscribe([IB1], None, nomatch) #doesn't raise
self.assertEqual(len(registry._subscribers), 2)

def _instance_method_notify_target(self):
self.fail("Example method, not intended to be called.")

def test_unsubscribe_instance_method(self):
IB0, IB1, IB2, IB3, IB4, IF0, IF1, IR0, IR1 = _makeInterfaces()
registry = self._makeOne()
self.assertEqual(len(registry._subscribers), 0)
registry.subscribe([IB1], None, self._instance_method_notify_target)
registry.unsubscribe([IB1], None, self._instance_method_notify_target)
self.assertEqual(len(registry._subscribers), 0)


class LookupBaseFallbackTests(unittest.TestCase):
Expand Down