Skip to content

Commit d804372

Browse files
committed
update some more words
1 parent 5c7ca79 commit d804372

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

peps/pep-0798.rst

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ following (though without defining or referencing the looping variable
232232
for i in expr:
233233
yield i
234234

235-
236235
The specifics of these semantics should be revisited in the future,
237236
particularly if async generators receive support for ``yield from`` (in which
238237
case both forms may wish to be changed to make use of ``yield from`` instead of
@@ -391,6 +390,12 @@ in comprehensions would raise a ``SyntaxError``, or that relied on the
391390
particular phrasing of any of the old error messages being replaced, which we
392391
expect to be rare.
393392

393+
One related concern is that a hypotehtical future decision to change the
394+
semantics of generator expressions to make use of ``yield from`` during
395+
unpacking (delegating to generators that are being unpacked) would be not be
396+
backwards-compatible because it would affect the behavior of the resulting
397+
generators when used with ``.send()``, ``.throw()``, and ``.close()``. See
398+
:ref:`pep798-alternativegenexpsemantics` for more discussion.
394399

395400
.. _pep798-examples:
396401

@@ -721,9 +726,18 @@ Alternative Generator Expression Semantics
721726

722727
Another point of discussion centered around the semantics of unpacking in
723728
generator expressions, particularly the relationship between the semantics of
724-
synchronous and asynchronous generator expressions given that the latter do not
725-
support ``yield from`` (see the section of :pep:`525` on Asynchronous ``yield
726-
from``).
729+
synchronous and asynchronous generator expressions given that async generators
730+
do not support ``yield from`` (see the section of :pep:`525` on Asynchronous
731+
``yield from``).
732+
733+
The core question centered around whether sync and/or async generator
734+
expressions should use ``yield from`` (or an equivalent) when unpacking, as
735+
opposed to an explicit loop. The main difference between these options is
736+
whether the resulting generator delegates to the objects being unpacked (see
737+
:pep:`380`), which would affect the behavior of these generator expressions
738+
when used with ``.send()``, ``.throw()``, and ``.close()``, in the case where
739+
the objects being unpacked are themselves generators, which appears to be a
740+
rare situation.
727741

728742
Several reasonable options were considered, none of which was a clear winner in
729743
a `poll in the Discourse thread
@@ -749,13 +763,15 @@ a `poll in the Discourse thread
749763
compelling practical use case for delegating to subgenerators during
750764
unpacking.
751765

752-
3. Disallowing unpacking in asynchronous generator expressions until they
766+
3. Using ``yield from`` for unpacking in synchronous generator expressions, and
767+
disallowing unpacking in asynchronous generator expressions until they
753768
support ``yield from``.
754769

755770
This strategy could possibly reduce friction if asynchronous generator
756-
expressions do gain support for ``yield from`` in the future, but in the
757-
meantime, it would result in an even bigger discrepancy between synchronous
758-
and asynchronous generator expressions than option 1.
771+
expressions do gain support for ``yield from`` in the future by making sure
772+
that any decision made at that point would be fully backwards-compatible,
773+
but in the meantime, it would result in an even bigger discrepancy between
774+
synchronous and asynchronous generator expressions than option 1.
759775

760776
4. Disallowing unpacking in all generator expressions.
761777

@@ -765,7 +781,9 @@ a `poll in the Discourse thread
765781
Each of these options (including the one presented in this PEP) has its
766782
benefits and drawbacks, with no option being clearly superior on all fronts;
767783
but the semantics proposed in :ref:`pep798-genexpsemantics` represent a
768-
reasonable compromise.
784+
reasonable compromise by allowing exactly the same kind of unpacking in
785+
synchronous and asynchronous generator expressions and retaining an existing
786+
property of generator expressions (that they do not
769787

770788
As suggested above, this decision should be revisited in the event that
771789
asynchronous generators receive support for ``yield from`` in the future,

0 commit comments

Comments
 (0)