Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions peps/pep-0798.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,35 @@ Title: Unpacking in Comprehensions
Author: Adam Hartz <hz@mit.edu>, Erik Demaine <edemaine@mit.edu>
Sponsor: Jelle Zijlstra <jelle.zijlstra at gmail.com>
Discussions-To: https://discuss.python.org/t/99435
Status: Draft
Status: Accepted
Type: Standards Track
Created: 19-Jul-2025
Python-Version: 3.15
Post-History: `16-Oct-2021 <https://mail.python.org/archives/list/python-ideas@python.org/thread/7G732VMDWCRMWM4PKRG6ZMUKH7SUC7SH/>`__, `22-Jun-2025 <https://discuss.python.org/t/pre-pep-unpacking-in-comprehensions/96362>`__, `19-Jul-2025 <https://discuss.python.org/t/pep-798-unpacking-in-comprehensions/99435>`__
Post-History:
`16-Oct-2021 <https://mail.python.org/archives/list/python-ideas@python.org/thread/7G732VMDWCRMWM4PKRG6ZMUKH7SUC7SH/>`__,
`22-Jun-2025 <https://discuss.python.org/t/pre-pep-unpacking-in-comprehensions/96362>`__,
`19-Jul-2025 <https://discuss.python.org/t/pep-798-unpacking-in-comprehensions/99435>`__,
Resolution: `03-Nov-2025 <https://discuss.python.org/t/pep-798-unpacking-in-comprehensions/99435/60>`__

.. note::
The Steering Council accepts this PEP with one modification: we require that
both synchronous and asynchronous generator expressions use explicit loops
rather than yield from for unpacking operations.

The Steering Council believes that simplicity and consistency are paramount
here. The delegation behaviour provided by ``yield from`` adds semantic
complexity for advanced use cases involving ``.send(),`` ``.throw()``, and
``.close()`` that are rarely relevant when writing comprehensions. We don’t
believe that developers writing comprehensions should have to think about
the differences between sync and async generator semantics or about generator
delegation protocols. We firmly believe that the mental model should be as
simple as possible and as symmetric as possible between all kinds of
comprehensions. The straightforward semantics of explicit loops provide a
uniform mental model that works the same way regardless of context, and also
provides better parity with the function-like versions, such as
``itertools.chain.from_iterable``. For the rare cases where someone actually
needs delegation behaviour, the Steering Council believes they should use an
explicit generator function with ``yield from`` rather than a comprehension.


Abstract
Expand Down