From 3dea0df2b8ee797264de67afc9f2d670e68aa634 Mon Sep 17 00:00:00 2001 From: Harmon Date: Sat, 29 Oct 2022 21:28:24 -0500 Subject: [PATCH] Warn when Tweet data is missing default edit_history_tweet_ids field --- tweepy/tweet.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tweepy/tweet.py b/tweepy/tweet.py index 42a189d..0e896c4 100644 --- a/tweepy/tweet.py +++ b/tweepy/tweet.py @@ -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") -- 2.25.1