best-practiceseasyQuestion 16 of 70
Event Notification Dispatcher
Review the following Python code and flag the issue.
Python
1class NotificationService:
2 def __init__(self):
3 self.sent_count = 0
4
5 def send_notifications(self, users, channels=['email']):
6 for user in users:
7 for channel in channels:
8 self._dispatch(user, channel)
9 self.sent_count += 1
10 return self.sent_count
11
12 def send_with_attachments(self, user, message, attachments=[]):
13 attachments.append({'type': 'footer', 'content': 'Sent via NotifyService'})
14 payload = {
15 'to': user,
16 'body': message,
17 'attachments': attachments
18 }
19 return self._dispatch_payload(payload)
20
21 def _dispatch(self, user, channel):
22 print(f'Sending to {user} via {channel}')
23
24 def _dispatch_payload(self, payload):
25 print(f'Dispatching: {payload}')
26 return True