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

前端 未结 4 1288
温柔的废话
温柔的废话 2020-12-11 00:41

When writing unit tests, I sometimes cut and paste a test and don\'t remember to change the method name. This results in overwriting the previous test, effectively hiding i

4条回答
  •  [愿得一人]
    2020-12-11 01:05

    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 
    

提交回复
热议问题