rspec/rules/S2325/python/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

61 lines
1.4 KiB
Plaintext

== 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
[source,python]
----
class Utilities:
def do_the_thing(self, arg1, arg2, ...): # Noncompliant
#...
----
=== Compliant solution
[source,python]
----
class Utilities:
@classmethod
def do_the_thing(cls, arg1, arg2, ...):
#...
----
or
[source,python]
----
class Utilities:
@staticmethod
def do_the_thing(arg1, arg2, ...):
#...
----
=== Exceptions
Methods which raise or may raise a ``++NotImplementedError++`` are ignored.
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Make this method static.
'''
== Comments And Links
(visible only on this page)
=== on 20 Apr 2020, 13:20:45 Nicolas Harraudeau wrote:
This rule seems to raise many false positives. It should be reviewed during the next janitoring effort: \https://community.sonarsource.com/t/python-s2325-false-positive-on-functools-cached-property/23250
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]