Skip to content

Commit

Permalink
Clarify docs: return in generator is new in 3.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Jan 10, 2015
1 parent 7b82e98 commit dca3f6b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/guide/async.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ the original synchronous version::
response = yield http_client.fetch(url)
raise gen.Return(response.body)

The statement ``raise gen.Return(response.body)`` is an artifact of Python 2, in which generators aren't allowed to return values. To overcome this, Tornado coroutines raise a special kind of exception called a ``Return``. The coroutine catches this exception and treats it like a returned value. In Python 3, a ``return response.body`` achieves the same result.
The statement ``raise gen.Return(response.body)`` is an artifact of
Python 2 (and 3.2), in which generators aren't allowed to return
values. To overcome this, Tornado coroutines raise a special kind of
exception called a `.Return`. The coroutine catches this exception and
treats it like a returned value. In Python 3.3 and later, a ``return
response.body`` achieves the same result.

0 comments on commit dca3f6b

Please sign in to comment.