How can I pickle a dynamically created nested class in python?

前端 未结 6 1623
醉酒成梦
醉酒成梦 2020-11-28 05:25

I have a nested class:

class WidgetType(object):
    
    class FloatType(object):
        pass
    
    class TextType(object):
        pass

.. and

6条回答
  •  情书的邮戳
    2020-11-28 05:48

    In Sage (www.sagemath.org), we have many instances of this pickling issue. The way we decided to systematically solve it is to put the outer class inside a specific metaclass whose goal is to implement and hide the hack. Note that this automatically propagate through nested classes if there are several level of nesting.

提交回复
热议问题