From b66d417be046c8b49a683649351834170bd9a734 Mon Sep 17 00:00:00 2001 From: Nils Diefenbach <23okrs20+github@mykolab.com> Date: Tue, 24 Oct 2017 15:12:13 +0200 Subject: [PATCH] Remove redundant key creation in dict using python's built-in `collections.defaultdict()` makes this more readable. --- pusherclient/channel.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pusherclient/channel.py b/pusherclient/channel.py index a09fe22..e1852cd 100755 --- a/pusherclient/channel.py +++ b/pusherclient/channel.py @@ -1,10 +1,12 @@ +from collections import defaultdict + class Channel(object): def __init__(self, channel_name, connection): self.name = channel_name self.connection = connection - self.event_callbacks = {} + self.event_callbacks = defaultdict(list) def bind(self, event_name, callback): """Bind an event to a callback @@ -14,9 +16,6 @@ def bind(self, event_name, callback): :param callback: The callback to notify of this event. """ - if event_name not in self.event_callbacks.keys(): - self.event_callbacks[event_name] = [] - self.event_callbacks[event_name].append(callback) def trigger(self, event_name, data):