From: Harmon Date: Fri, 19 Nov 2021 15:16:57 +0000 (-0600) Subject: Improve and optimize Model.__getstate__ X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ebbb48dcdcb003ecc393c389e7d2bb1eac2a182b;p=tweepy.git Improve and optimize Model.__getstate__ Resolves #1707 --- 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