[Python-Dev] Pickling instances of nested classes

Walter Dörwald walter at livinglogic.de
Fri Apr 1 21:29:44 CEST 2005


Samuele Pedroni wrote:

> [...]
> 
> this should approximate that behavior better: [not tested]
> 
>   import sys
> 
>  ....
>  def __new__(cls, name, bases, dic):
>      sub = [x for x in dic.values() if isinstance(x,HierarchMeta)]
>      newtype = type.__new__(cls, name, bases, dic)
>      for x in sub:
>          if not hasattr(x, '_outer_') and 
> getattr(sys.modules.get(x.__module__), x.__name__, None) is not x:
>               x._outer_ = newtype
>      return newtype
> 
>  .....
> 
> we don't set _outer_ if a way to pickle the class is already there

This doesn't fix

class Foo:
    class Bar:
       pass

class Baz:
    Bar = Foo.Bar

both this should be a simple fix.

Bye,
    Walter Dörwald


More information about the Python-Dev mailing list