You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "tvalentyn (via GitHub)" <gi...@apache.org> on 2023/03/09 20:27:08 UTC

[GitHub] [beam] tvalentyn commented on issue #22969: Discrepancy in behavior of `DoFn.process()` when `yield` is combined with `return` statement, or vice versa

tvalentyn commented on issue #22969:
URL: https://github.com/apache/beam/issues/22969#issuecomment-1462730124

   Taking a closer look, the unexpected behavior is not caused by Beam but rather how Python interprets a function with `yield` and `return` statements mixed together. See: https://stackoverflow.com/questions/16780002/return-in-generator-together-with-yield which summarizes it.
   
   For example:
   
   ```
   def foo(c):
     if (c):
       yield "foo"
     else:
       return "bar
   ```
   
   ```
   list(foo(True))
   Out: ['foo']
   ```
   
   ```
   list(foo(False))
   Out: []
   ```
   
   ```next(foo(False))``` raises StopIteration: bar
   
   Seems that such mix-and-match was an error in Python 2.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org