ea5eba5916
As noted in #600, Python 3 allows a return inside a generator method, that raises a StopIteration and passes the return value inside the 'value' attr of the exception. To allow this behaviour we simple set 'contains_yield' while compiling 'yield', thus allowing a return statement, but only for Python 3. Then when compiling the try-except, we check for contains_yield to decide whether there will be a return. This allows code like: (defn gen [] (yield 3) "goodbye") to compile in both Py2 and Py3. The return value is simply ignored in Python 2. hy2py in Python 2 gives: def g(): yield 3L u'goodbye' while hy2py in Python 3 gives: def g(): yield 3 return 'goodbye' Turns out return in yield started in Python 3.3 |
||
---|---|---|
.. | ||
contrib | ||
__init__.hy | ||
cons.hy | ||
core.hy | ||
defclass.hy | ||
language.hy | ||
math.hy | ||
native_macros.hy | ||
quote.hy | ||
reader_macros.hy | ||
unless.hy | ||
when.hy | ||
with_decorator.hy | ||
with_test.hy |