
## Review A dedicated reviewer checked the rule description successfully for: - [ ] logical errors and incorrect information - [ ] information gaps and missing content - [ ] text style and tone - [ ] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
87 lines
1.7 KiB
Plaintext
87 lines
1.7 KiB
Plaintext
== Why is this an issue?
|
|
|
|
:operationName: method
|
|
|
|
include::../description.adoc[]
|
|
|
|
=== Exceptions
|
|
|
|
No issue will be raised when the empty method is abstract and meant to be overridden in a subclass, i.e. it is decorated with `abc.abstractmethod`,
|
|
`abc.abstractstaticmethod`, `abc.abstractclassmethod` or `abc.abstractproperty`.
|
|
Note however that these methods should normally have a docstring explaining how subclasses should implement these methods.
|
|
|
|
[source,python]
|
|
----
|
|
import abc
|
|
|
|
class MyAbstractClass(abc.ABC):
|
|
@abc.abstractproperty
|
|
def myproperty(self):
|
|
pass
|
|
|
|
@abc.abstractclassmethod
|
|
def myclassmethod(cls):
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def mymethod(self):
|
|
pass
|
|
|
|
@abc.abstractstaticmethod
|
|
def mystaticmethod():
|
|
pass
|
|
----
|
|
|
|
== How to fix it
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,python,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
def shouldNotBeEmpty(): # Noncompliant - method is empty
|
|
pass
|
|
|
|
def notImplemented(): # Noncompliant - method is empty
|
|
pass
|
|
|
|
def emptyOnPurpose(): # Noncompliant - method is empty
|
|
pass
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,python,diff-id=1,diff-type=compliant]
|
|
----
|
|
def shouldNotBeEmpty():
|
|
doSomething()
|
|
|
|
def notImplemented():
|
|
raise NotImplementedError("notImplemented() cannot be performed because ...")
|
|
|
|
def emptyOnPurpose():
|
|
pass # comment explaining why the method is empty
|
|
|
|
def emptyOnPurposeBis():
|
|
"""
|
|
Docstring explaining why this function is empty.
|
|
"""
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|