An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)

VS code 里写下如下代码:

class Encoder(JSONEncoder):
    def default(self, o): 
        if isinstance(o, ObjectId):
            o = str(o)
            return o

pylint 提示:

An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)

看来pylint 不怎么喜欢使用default命名我们的方法。

虽然不影响代码的运行,但对于强迫症来说,真的很烦。

修改:

class Encoder(JSONEncoder):
    def default(self, o):                     # pylint: disable=E0202
        if isinstance(o, ObjectId):
            o = str(o)
            return o

完美解决

posted @ 2019-07-09 13:00  小莽  阅读(1682)  评论(0编辑  收藏  举报