This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Bryan Koch
Recipients Bryan Koch, greg.ewing, steven.daprano
Date 2019-01-18.00:31:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1547771505.97.0.32419395184.issue35756@roundup.psfhosted.org>
In-reply-to
Content
Thank you both for the clarifications.  I agree these's no bug in `yield from` however is there a way to reference the return value when a generator with a return is invoked using `for val in gen` i.e. when the generator is invoked without delegation?

I could write my own wrapper around using `next` to work around this but it might be an oversight of the new grammar (new being relative) that the return value is only available when invoked from the `yield from` syntax.

Essentially I have code that looks like
`
for value in generator:
  do thing with value
  yield value
`
where I need to do something before yielding the value.  It would be awesome if invoking a generator above would throw a SyntaxError iff it contained a return and it wasn't invoked through `yield from`.

The below isn't valid Python and I'm not sure that it should be but it's what I need to do.

`
return_value = for value in generator:
  do thing with value
  yield value

if return_value:
  do something with return_value
`
History
Date User Action Args
2019-01-18 00:31:47Bryan Kochsetrecipients: + Bryan Koch, steven.daprano, greg.ewing
2019-01-18 00:31:45Bryan Kochsetmessageid: <1547771505.97.0.32419395184.issue35756@roundup.psfhosted.org>
2019-01-18 00:31:45Bryan Kochlinkissue35756 messages
2019-01-18 00:31:45Bryan Kochcreate