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

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

There is a newer version: 4.26.0.19456
Show newest version

Why is this an issue?

Class methods that don’t access instance data can and should be static because they yield more performant code.

To implement a static method in Python one should use either @classmethod or @staticmethod. A class method receives the class as implicit first argument, just like an instance method receives the instance. A static method does not receive an implicit first argument.

Noncompliant code example

class Utilities:
    def do_the_thing(self, arg1, arg2, ...):  # Noncompliant
        #...

Compliant solution

class Utilities:
    @classmethod
    def do_the_thing(cls, arg1, arg2, ...):
        #...

or

class Utilities:
    @staticmethod
    def do_the_thing(arg1, arg2, ...):
        #...

Exceptions

Methods which raise or may raise a NotImplementedError are ignored.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy