Permalink
Browse files

send_event: Remove useless return value and annotate.

Detected by mypy.

[tweaked by tabbott to pass mypy check and remove annotations]
  • Loading branch information...
cpdean authored and timabbott committed Jun 5, 2016
1 parent a4704ba commit d77c70220c91a47b06695409e178bb006fe996e8
Showing with 12 additions and 7 deletions.
  1. +10 −5 zerver/lib/event_queue.py
  2. +2 −2 zerver/lib/queue.py
View
@@ -1,5 +1,5 @@
from __future__ import absolute_import
-from typing import Any
+from typing import Any, Dict, Iterable, Union
from django.utils.translation import ugettext as _
from django.conf import settings
@@ -760,9 +760,14 @@ def send_notification_http(data):
process_notification(data)
def send_notification(data):
- return queue_json_publish("notify_tornado", data, send_notification_http)
+ # type: (Dict[str, Any]) -> None
+ queue_json_publish("notify_tornado", data, send_notification_http)
def send_event(event, users):
- return queue_json_publish("notify_tornado",
- dict(event=event, users=users),
- send_notification_http)
+ # type: (Dict[str, Any], Union[Iterable[int], Iterable[Dict[str, Any]]]) -> None
+ """`users` is a list of user IDs, or in the case of `message` type
+ events, a list of dicts describing the users and metadata about
+ the user/message pair."""

This comment has been minimized.

Show comment
Hide comment
@cpdean

cpdean Jun 7, 2016

Contributor

It was cool how when I applied the restrictive annotation, mypy was quick to tell me I was doing it wrong due to another part of the codebase passing in dicts instead of ints.

@cpdean

cpdean Jun 7, 2016

Contributor

It was cool how when I applied the restrictive annotation, mypy was quick to tell me I was doing it wrong due to another part of the codebase passing in dicts instead of ints.

This comment has been minimized.

Show comment
Hide comment
@timabbott

timabbott Jun 7, 2016

Member

Yeah, this is actually a great case for how mypy can really help with refactoring! I'd certainly forgotten that detail. Will put in my list of examples for the mypy+Zulip blog post :)

@timabbott

timabbott Jun 7, 2016

Member

Yeah, this is actually a great case for how mypy can really help with refactoring! I'd certainly forgotten that detail. Will put in my list of examples for the mypy+Zulip blog post :)

+ queue_json_publish("notify_tornado",
+ dict(event=event, users=users),
+ send_notification_http)
View
@@ -94,12 +94,12 @@ def do_publish():
def json_publish(self, queue_name, body):
try:
- return self.publish(queue_name, ujson.dumps(body))
+ self.publish(queue_name, ujson.dumps(body))
except (AttributeError, pika.exceptions.AMQPConnectionError):
self.log.warning("Failed to send to rabbitmq, trying to reconnect and send again")
self._reconnect()
- return self.publish(queue_name, ujson.dumps(body))
+ self.publish(queue_name, ujson.dumps(body))
def register_consumer(self, queue_name, consumer):
def wrapped_consumer(ch, method, properties, body):

0 comments on commit d77c702

Please sign in to comment.