Improve clarity of AsyncStream.on_data
authorHarmon <Harmon758@gmail.com>
Tue, 26 Jan 2021 15:42:47 +0000 (09:42 -0600)
committerHarmon <Harmon758@gmail.com>
Tue, 26 Jan 2021 15:42:47 +0000 (09:42 -0600)
tweepy/asynchronous/streaming.py

index 150c617a3f3de079654b6bcc64d26569f079a6b2..c5a1a376cb60d0ac94c633e7d1966a547f60b2e8 100644 (file)
@@ -295,11 +295,14 @@ class AsyncStream:
             return await self.on_disconnect_message(data["disconnect"])
         if "limit" in data:
             return await self.on_limit(data["limit"]["track"])
-        for message_type in ("scrub_geo","status_withheld", "user_withheld",
-                             "warning"):
-            if message_type in data:
-                method = getattr(self, "on_" + message_type)
-                return await method(data[message_type])
+        if "scrub_geo" in data:
+            return await self.on_scrub_geo(data["scrub_geo"])
+        if "status_withheld" in data:
+            return await self.on_status_withheld(data["status_withheld"])
+        if "user_withheld" in data:
+            return await self.on_user_withheld(data["user_withheld"])
+        if "warning" in data:
+            return await self.on_warning(data["warning"])
 
         log.warning("Received unknown message type: %s", raw_data)