Yield after the return in Python function.

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Apr 5 20:02:11 EDT 2021


On 6/04/21 4:02 am, Terry Reedy wrote:
> *Any* use of 'yield' in a function makes the function a generator 
> function.  ...  If there were a 'dead 
> (unreachable) code' exception, a reader or compiler would have to 
> analyze each use of 'yield' and decide whether it is reachable or not. 

It would also break existing code. An unreachable "yield" is
sometimes used as a way to get a generator that doesn't yield
anything.

-- 
Greg


More information about the Python-list mailing list