diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-12-01 04:54:17 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-12-01 04:54:17 (GMT) |
commit | 73a7e9b10b2ec9636e3c6396cf7b3695f8ed1856 (patch) | |
tree | 14101bd8c629aad1d3ae7cf77e1946516ddeba80 /Doc/whatsnew/3.7.rst | |
parent | 6a89481680b921e7b317c29877bdda9a6031e5ad (diff) | |
download | cpython-73a7e9b10b2ec9636e3c6396cf7b3695f8ed1856.zip cpython-73a7e9b10b2ec9636e3c6396cf7b3695f8ed1856.tar.gz cpython-73a7e9b10b2ec9636e3c6396cf7b3695f8ed1856.tar.bz2 |
bpo-10544: Deprecate "yield" in comprehensions and generator expressions. (GH-4579)
The current behaviour of yield expressions inside comprehensions and
generator expressions is essentially an accident of implementation - it
arises implicitly from the way the compiler handles yield expressions inside
nested functions and generators.
Since the current behaviour wasn't deliberately designed, and is inherently
confusing, we're deprecating it, with no current plans to reintroduce it.
Instead, our advice will be to use a named nested generator definition
for cases where this behaviour is desired.
Diffstat (limited to 'Doc/whatsnew/3.7.rst')
-rw-r--r-- | Doc/whatsnew/3.7.rst | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 6545a18..b6dad4e 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -570,6 +570,18 @@ Other CPython Implementation Changes Deprecated ========== +* Yield expressions (both ``yield`` and ``yield from`` clauses) are now deprecated + in comprehensions and generator expressions (aside from the iterable expression + in the leftmost :keyword:`for` clause). This ensures that comprehensions + always immediately return a container of the appropriate type (rather than + potentially returning a :term:`generator iterator` object), while generator + expressions won't attempt to interleave their implicit output with the output + from any explicit yield expressions. + + In Python 3.7, such expressions emit :exc:`DeprecationWarning` when compiled, + in Python 3.8+ they will emit :exc:`SyntaxError`. (Contributed by Serhiy + Storchaka in :issue:`10544`.) + - Function :c:func:`PySlice_GetIndicesEx` is deprecated and replaced with a macro if ``Py_LIMITED_API`` is not set or set to the value between ``0x03050400`` and ``0x03060000`` (not including) or ``0x03060100`` or |