On Fri, May 11, 2018 at 7:40 AM, Chris Angelico <ros...@gmail.com> wrote: > So, yes, your function's name is outright lying. But there's nothing > about it that is *pretending* to be a normal function. It IS a normal > function.
The detail of whether it's a generator function affects the function's execution and may be relevant to the caller. Here are two hypothetical functions. They do some processing with side-effects over a bunch of items and return the processed items. However, one is a generator function and the other just returns a list. def process_items(items): ... def handle_items(items): ... Now, we can agree that these ought to be better documented, but say I want to call one of these for the side effects and ignore the return value. Just from reading the first line of the function, do I need to iterate over the result, or not? Scenario 2. I have two "while True" loops. One is potentially infinite and the other is not. while True: ... while True: ... Obviously, it's important to know whether a loop might be infinite before I run the code that includes it. Just from reading the first line of the loop, how do I know? You can argue that they should use strings instead to describe what they do, which would help, although I think that's potentially confusing. I don't see these two situations as being fundamentally different. Do you? -- https://mail.python.org/mailman/listinfo/python-list