All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S4144.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

Why is this an issue?

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.





© 2015 - 2024 Weber Informatics LLC | Privacy Policy