Warn when Tweet data is missing default edit_history_tweet_ids field
authorHarmon <Harmon758@gmail.com>
Sun, 30 Oct 2022 02:28:24 +0000 (21:28 -0500)
committerHarmon <Harmon758@gmail.com>
Sun, 30 Oct 2022 02:28:24 +0000 (21:28 -0500)
tweepy/tweet.py

index 42a189dc327dbd0f53dc3e402b5489168916934e..0e896c432c833bdfc959061466a6862ff9a87e97 100644 (file)
@@ -2,6 +2,8 @@
 # Copyright 2009-2022 Joshua Roesslein
 # See LICENSE for details.
 
+import warnings
+
 from tweepy.mixins import DataMapping, HashableID
 from tweepy.utils import parse_datetime
 
@@ -124,9 +126,16 @@ class Tweet(HashableID, DataMapping):
         self.data = data
         self.id = int(data["id"])
         self.text = data["text"]
-        self.edit_history_tweet_ids = list(
-            map(int, data["edit_history_tweet_ids"])
-        )
+        try:
+            self.edit_history_tweet_ids = list(
+                map(int, data["edit_history_tweet_ids"])
+            )
+        except KeyError:
+            warnings.warn(
+                "Tweet data missing default edit_history_tweet_ids field",
+                RuntimeWarning,
+                stacklevel=2
+            )
 
         self.attachments = data.get("attachments")