2023-08-04 12:58:46 +02:00

51 lines
1.2 KiB
Plaintext

This rule raises an issue when a function call result is used, even though the function does not return anything.
== Why is this an issue?
If a function does not return anything, it makes no sense to use its output. Specifically, passing it to another function, or assigning its "result" to a variable is probably a bug because such functions return nothing, which is probably not what was intended.
=== Code examples
==== Noncompliant code example
[source,python,diff-id=1,diff-type=noncompliant]
----
def foo():
l = [1, 2, 3]
result = l.append(42) # Noncompliant, `append` mutates list l
return result
----
==== Compliant solution
[source,python,diff-id=1,diff-type=compliant]
----
def foo():
l = [1, 2, 3]
l.append(42)
return l
----
== Resources
=== Documentation
* Python documentation - https://docs.python.org/3/tutorial/controlflow.html#defining-functions[Defining Functions]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]