Two functions having the same implementation are suspicious. It might be that something else was intended. Or the duplication is intentional, which
becomes a maintenance burden.
class MyClass:
code = "secret"
def calculate_code(self):
self.do_the_thing()
return self.__class__.code
def get_name(self): # Noncompliant: duplicates calculate_code
self.do_the_thing()
return self.__class__.code
def do_the_thing(self):
pass # on purpose
If the identical logic is intentional, the code should be refactored to avoid duplication. For example, by having both functions call the same
function or by having one implementation invoke the other.
class MyClass:
code = "secret"
def calculate_code(self):
self.do_the_thing()
return self.__class__.code
def get_name(self): # Intent is clear
return self.calculate_code()
def do_the_thing(self):
pass # on purpose
Exceptions
No issue will be raised on empty methods/functions and methods/functions with only one line of code.