title: I can "pickle local objects" if I use a derived class?
body: <p>The <code>pickle</code> reference <a href="https://docs.python.org/3/library/pickle.html#what-can-be-pickled-and-unpickled" rel="noreferrer">states that</a> the set of objects which can be pickled is rather limited. Indeed, I have a function which returns a dinamically-generated class, and I found I can't pickle instances of that class:</p>
  
  <pre><code>&gt;&gt;&gt; import pickle
  &gt;&gt;&gt; def f():
  ...     class A: pass
  ...     return A
  ... 
  &gt;&gt;&gt; LocalA = f()
  &gt;&gt;&gt; la = LocalA()
  &gt;&gt;&gt; with open('testing.pickle', 'wb') as f:
  ...     pickle.dump(la, f, pickle.HIGHEST_PROTOCOL)
  ... 
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 2, in &lt;module&gt;
  AttributeError: Can't pickle local object 'f.&lt;locals&gt;.A'
  </code></pre>
  
  <p>Such objects are too complicated for <code>pickle</code>. Ok. Now, what's magic is that, if I try to pickle a similar object, but of a derived class, it works!</p>
  
  <pre><code>&gt;&gt;&gt; class DerivedA(LocalA): pass
  ... 
  &gt;&gt;&gt; da = DerivedA()
  &gt;&gt;&gt; with open('testing.pickle', 'wb') as f:
  ...     pickle.dump(da, f, pickle.HIGHEST_PROTOCOL)
  ...
  &gt;&gt;&gt;
  </code></pre>
  
  <p>What's happening here? If this is so easy, why doesn't <code>pickle</code> use this workaround to implement a <code>dump</code> method that allows "local objects" to be pickled?</p>