0

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

我错过了什么?

4

1 回答 1

0

我这样做了:

class MyModel(MongoModel):
fields = ...
def __init__(self, other_args...):
    super(MyModel, self).__init__(other_args)
    do_something_else()

工作,但我得到DeprecationWarning: __class__ not set defining...

Here Provide __classcell__ example for Python 3.6 metaclass他们解释得更多,但我根本不明白

于 2019-05-09T16:48:26.790 回答