Debugging fail in : I had a generator function:

def them():
for thing in some_things():
yield thing

But I wanted to quickly try changing it to use a helper that returned a list, so I just added that code at the top:

def them():
return them_from_somewhere_else()
for thing in some_things():
yield thing

Took me a while to figure out why `list(them())` was always an empty list.

0

If you have a fediverse account, you can quote this note from your own instance. Search https://hachyderm.io/users/nedbat/statuses/116150179474021938 on your instance and quote it. (Note that quoting is not supported in Mastodon.)

RE: hachyderm.io/@nedbat/116150179

The answer to the mystery: because my function had a `yield` in it, it was compiled as a generator. But executing the function never ran `yield`, so iterating it produced an empty sequence. The value from the return statement is ignored.

TBH, I know there is a way to get the returned value, but I have never needed to, and I don't know how.

The solution was to delete the code after the return.

0