我想为我的PyMODM类提供一个自定义的初始化程序。直接做到
class MyModel(MongoModel):
fields = ...
def __init__(self, other_args...):
super().__init__(other_args)
do_something_else()
首先产生警告:
DeprecationWarning: __class__ not set defining 'MyModel' as <class '__main__.MyModel'>. Was __classcell__ propagated to type.__new__?
,然后出现错误:
TypeError: __init__() missing required positional arguments
我想念什么?
答案 0 :(得分:0)
我这样做:
class MyModel(MongoModel):
fields = ...
def __init__(self, other_args...):
super(MyModel, self).__init__(other_args)
do_something_else()
有效,但我得到DeprecationWarning: __class__ not set defining...
Provide __classcell__ example for Python 3.6 metaclass在这里他们解释得更多,但我一点也不理解