Skip to content

Commit

Permalink
fix: EventEmitter.listeners() should not throw on unknown listeners (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Jan 18, 2022
1 parent aee3da9 commit 794a201
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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():
"""`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

0 comments on commit 794a201

Please sign in to comment.