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

fix: EventEmitter.listeners() should not throw on unknown listeners #104

Merged
merged 1 commit into from Jan 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyee/base.py
Expand Up @@ -226,4 +226,4 @@ def remove_all_listeners(self, event: Optional[str] = None) -> None:

def listeners(self, event: str) -> List[Callable]:
"""Returns a list of all listeners registered to the ``event``."""
return list(self._events[event].keys())
return list(self._events.get(event, OrderedDict()).keys())
7 changes: 7 additions & 0 deletions tests/test_sync.py
Expand Up @@ -240,6 +240,13 @@ def once_handler():
call_me.assert_not_called()


def test_listeners_does_work_with_unknown_listeners():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even have to ask for a test. Beautiful!

"""`listeners()` should not throw."""
ee = EventEmitter()
listeners = ee.listeners("event")
assert listeners == []


def test_properties_preserved():
"""Test that the properties of decorated functions are preserved."""

Expand Down