title: Pickling weakref in Python
body: <p>I am still pretty new to Python and even newer to pickling. I have a class <code>Vertex(ScatterLayout)</code> with a <a href="https://docs.python.org/2/library/pickle.html#object.__getnewargs__" rel="noreferrer"><code>__getnewargs__()</code></a>:</p>
  
  <pre><code>def __getnewargs__(self):
      return (self.pos, self.size, self.idea.text)
  </code></pre>
  
  <p>My understanding is that this will cause the pickle to pickle the object from <code>__getnewargs__()</code> rather than the object's dictionary.</p>
  
  <p>The pickle is called in the following method (in a different class <code>MindMapApp(App)</code>):</p>
  
  <pre><code>def save(self):
      vertices = self.mindmap.get_vertices()
      edges = self.mindmap.get_edges()
  
      output = open('mindmap.pkl', 'wb')
  
      #pickle.dump(edges, output, pickle.HIGHEST_PROTOCOL)
      pickle.dump(vertices, output, pickle.HIGHEST_PROTOCOL)
  
      output.close()
  </code></pre>
  
  <p>When I call the <code>save()</code> method I get the following error:</p>
  
  <pre><code>pickle.PicklingError: Can't pickle &lt;type 'weakref'&gt;: it's not found as __builtin__.weakref
  </code></pre>
  
  <p>What am I missing or not understanding? I have also tried implementing the <code>__getstate__()</code> / <code>__setstate__(state)</code> combination, with the same result.</p>