rspec/rules/S2712/python/rule.adoc

18 lines
503 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
def adder(n):
num = 0
while num < n:
yield num
num += 1
return num #Noncompliant
----