2020-06-30 12:48:07 +02:00
Class methods that don't access instance data can and should be static because they yield more performant code.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
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.
2020-06-30 12:48:07 +02:00
== 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
2020-06-30 14:49:38 +02:00
2020-06-30 12:48:07 +02:00
----
class Utilities:
@staticmethod
def do_the_thing(arg1, arg2, ...):
#...
----
== Exceptions
2021-01-27 13:42:22 +01:00
Methods which raise or may raise a ``++NotImplementedError++`` are ignored.
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]