Optimize Tweet.referenced_tweets initialization
authorHarmon <Harmon758@gmail.com>
Sun, 27 Feb 2022 20:35:20 +0000 (14:35 -0600)
committerHarmon <Harmon758@gmail.com>
Sun, 27 Feb 2022 20:35:20 +0000 (14:35 -0600)
tweepy/tweet.py

index 0437a720004e1bcbf3f49b5ccd3f5287ac47f46d..7d877fde6edf7a09702d9304a972d1b407fd9f8c 100644 (file)
@@ -52,11 +52,11 @@ class Tweet(HashableID, DataMapping):
         self.promoted_metrics = data.get("promoted_metrics")
         self.public_metrics = data.get("public_metrics")
 
-        self.referenced_tweets = None
-        if "referenced_tweets" in data:
+        self.referenced_tweets = data.get("referenced_tweets")
+        if self.referenced_tweets is not None:
             self.referenced_tweets = [
                 ReferencedTweet(referenced_tweet)
-                for referenced_tweet in data["referenced_tweets"]
+                for referenced_tweet in self.referenced_tweets
             ]
 
         self.reply_settings = data.get("reply_settings")