Fix bug in JSONParser.parse() which causes it to return None
authorDavid Laban <david.laban@conversocial.com>
Tue, 26 Jul 2016 14:17:06 +0000 (15:17 +0100)
committerDavid Laban <david.laban@conversocial.com>
Tue, 26 Jul 2016 14:17:06 +0000 (15:17 +0100)
Re-combine tower-of-ifs into a single if/else.

Fixes #765

tweepy/parsers.py

index 6381912ecab6c1ee8b7e45a2a9d1aea3d0aec98f..046cf50994e10ac7695a8585d6059706b03109f0 100644 (file)
@@ -54,11 +54,11 @@ class JSONParser(Parser):
             raise TweepError('Failed to parse JSON payload: %s' % e)
 
         needs_cursors = 'cursor' in method.session.params
-        if needs_cursors and isinstance(json, dict):
-            if 'previous_cursor' in json:
-                if 'next_cursor' in json:
-                    cursors = json['previous_cursor'], json['next_cursor']
-                    return json, cursors
+        if needs_cursors and isinstance(json, dict) \
+                and 'previous_cursor' in json \
+                and 'next_cursor' in json:
+            cursors = json['previous_cursor'], json['next_cursor']
+            return json, cursors
         else:
             return json