rspec/rules/S2325/python/rule.adoc
Alban Auzeill 2c306d110e Fix code block ambiguity with old header style
Ensure blank line before list and clean the one leading space
2020-06-30 17:16:12 +02:00

33 lines
861 B
Plaintext

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 <code>@classmethod</code> or <code>@staticmethod</code>. 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 <code>NotImplementedError</code> are ignored.