dahlia / wikidata

Wikidata client library for Python
https://pypi.org/project/Wikidata/
GNU General Public License v3.0
337 stars 31 forks source link

Entities cannot be pickled #31

Closed nelson-liu closed 4 years ago

nelson-liu commented 4 years ago

Seems like this would require moving away from WeakValueDictionary?

In [1]: from wikidata.client import Client

In [2]: import pickle

In [3]: c = Client()

In [4]: example = c.get("Q42")

In [5]: with open("test", "wb") as f:
   ...:     pickle.dump(example, f)
   ...:
   ...:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-966820a5735d> in <module>
      1 with open("test", "wb") as f:
----> 2     pickle.dump(example, f)
      3
      4

AttributeError: Can't pickle local object 'WeakValueDictionary.__init__.<locals>.remove'
dahlia commented 4 years ago

See also: https://docs.python.org/3/library/pickle.html#persistence-of-external-objects.