An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)
Posted ifengqi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
完美解决
以上是关于An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)的主要内容,如果未能解决你的问题,请参考以下文章