rspec/rules/S2712/python/rule.adoc
2022-02-04 16:28:24 +00:00

34 lines
771 B
Plaintext

Functions that use ``++yield++`` are known as "generators". Before Python 3.3, generators cannot ``++return++`` values. Similarly, functions that use ``++return++`` cannot use ``++yield++``. Doing so will cause a ``++SyntaxError++``.
Either upgrade your version of Python to a version >= 3.3, or don't use both return and yield in a function.
== Noncompliant Code Example
[source,python]
----
def adder(n):
num = 0
while num < n:
yield num
num += 1
return num #Noncompliant
----
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[]