Improve and optimize Model.__getstate__
authorHarmon <Harmon758@gmail.com>
Fri, 19 Nov 2021 15:16:57 +0000 (09:16 -0600)
committerHarmon <Harmon758@gmail.com>
Fri, 19 Nov 2021 15:16:57 +0000 (09:16 -0600)
Resolves #1707

tweepy/models.py

index c77000dc6d7981b9ba129268b8981c04ec5d0949..245aa7a71ff77147b2521ac6d65651fac319dc04 100644 (file)
@@ -13,12 +13,8 @@ class Model:
         self._api = api
 
     def __getstate__(self):
-        # pickle
-        pickle = dict(self.__dict__)
-        try:
-            del pickle['_api']  # do not pickle the API reference
-        except KeyError:
-            pass
+        pickle = self.__dict__.copy()
+        pickle.pop('_api', None)
         return pickle
 
     @classmethod