如何在PyMODM模型类中定义初始值设定项

2024-09-20 22:54:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想为我的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

我错过了什么?你知道吗


Tags: self警告fieldsinitdefargsdoelse
1条回答
网友
1楼 · 发布于 2024-09-20 22:54:31

我做到了:

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他们解释得更多,但我一点也不明白

相关问题 更多 >

    热门问题