From ebbb48dcdcb003ecc393c389e7d2bb1eac2a182b Mon Sep 17 00:00:00 2001 From: Harmon Date: Fri, 19 Nov 2021 09:16:57 -0600 Subject: [PATCH] Improve and optimize Model.__getstate__ Resolves #1707 --- tweepy/models.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tweepy/models.py b/tweepy/models.py index c77000d..245aa7a 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -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 -- 2.25.1