Tag Archives: method-hidden

[Solved] Pylint Warning: An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)

code:

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

Pylint tip:

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

The code check may not pass. In addition, obsessive-compulsive disorder is completely unacceptable.

Solution: add # pylint: disable = e0202. As follows:

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