Skip to content

Fix remove_all_listeners leaving stale empty event key - #209

Merged
jfhbrook merged 2 commits into
jfhbrook:mainfrom
vincent178:fix/remove-all-listeners-cleans-event-key
Aug 13, 2026
Merged

Fix remove_all_listeners leaving stale empty event key#209
jfhbrook merged 2 commits into
jfhbrook:mainfrom
vincent178:fix/remove-all-listeners-cleans-event-key

Conversation

@vincent178

@vincent178 vincent178 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

EventEmitter.remove_all_listeners("event") replaced the event's OrderedDict with an empty one rather than deleting the key:

# before
if event is not None:
    self._events[event] = OrderedDict()

As a result the event key remained present in _events, and event_names() kept reporting the event as registered even though it had no listeners. This was inconsistent with _remove_listener, which correctly dels the key when a mapping drains.

The fix is deleting the key, the same as _remove_listener

vincent178 and others added 2 commits July 22, 2026 06:08
remove_all_listeners("event") replaced the event's OrderedDict with an
empty one instead of deleting the key, so the event remained present in
_events and event_names() still reported it as registered. Delete the
key outright (guarded so removing a never-registered event is a no-op
rather than a KeyError) and add regression tests covering both the
single-event and clear-all paths.

Co-Authored-By: Claude <noreply@anthropic.com>
The single-event path is already covered by the fixed assertion at the
end of test_listener_removal. Drop the dedicated
test_remove_all_listeners_single_event_cleans_key to avoid duplication;
keep the clear-all regression test.

Co-Authored-By: Claude <noreply@anthropic.com>
@jfhbrook
jfhbrook merged commit 426cd82 into jfhbrook:main Aug 13, 2026
5 checks passed
@jfhbrook

Copy link
Copy Markdown
Owner

Released in v14.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants