.. _return-arg-in-generator:
return-arg-in-generator / E0106
===============================
**Message emitted:**
``Return with argument inside generator``
**Description:**
*Used when a "return" statement with an argument is found in a generator function or method (e.g. with some "yield" statements).*
**Correct code:**
.. literalinclude:: /data/messages/r/return-arg-in-generator/good.py
:language: python
**Additional details:**
This is a message that isn't going to be raised for python > 3.3. It was raised
for code like::
def interrogate_until_you_find_jack(pirates):
for pirate in pirates:
if pirate == "Captain Jack Sparrow":
return "Arrr! We've found our captain!"
yield pirate
Which is now valid and equivalent to the previously expected::
def interrogate_until_you_find_jack(pirates):
for pirate in pirates:
if pirate == "Captain Jack Sparrow":
raise StopIteration("Arrr! We've found our captain!")
yield pirate
**Related links:**
- `PEP380 `_
- `Stackoverflow explanation `_
Created by the `basic `__ checker.