Skip to content

Commit cf4b435

Browse files
committed
Merge pull request faif#85 from JDegner0129/fix-pubsub-conditional
DRY up the subscribe conditional a bit
2 parents 1799a8f + bbc1749 commit cf4b435

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

publish_subscribe.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ def notify(self, msg):
1717
self.msg_queue.append(msg)
1818

1919
def subscribe(self, msg, subscriber):
20-
if msg not in self.subscribers:
21-
self.subscribers[msg] = []
22-
self.subscribers[msg].append(subscriber) # unfair
23-
else:
24-
self.subscribers[msg].append(subscriber)
20+
self.subscribers.setdefault(msg, []).append(subscriber)
2521

2622
def unsubscribe(self, msg, subscriber):
2723
self.subscribers[msg].remove(subscriber)

0 commit comments

Comments
 (0)