How can I detect duplicate method names in a Python class?

If you run Pylint over your code, it will inform you when you have overwritten another method:

For example, I ran this:

class A(object):
    def blah(self):
        print("Hello, World!")

    def blah(self):
        print("I give up!")

In this online Pylint checker. Besides all the missing docstrings and such, I get this:

E: 5:A.blah: method already defined line 2

Alternatively, via the command line:

python -m pyflakes .

Output:

.\blah.py:5:5 redefinition of unused 'blah' from line 2

Leave a Comment