3 ms·
It means you can have generator functions that contain no yield statements, which is not as crazy as it sounds. I've had to do `if False: yield` before in Pytho
by bnjmn 13y ago
It means you can have generator functions that contain no yield statements, which is not as crazy as it sounds. I've had to do `if False: yield` before in Python to trick the language into treating a function as a generator. An unyielding generator behaves so differently from a similar-looking non-generator function that the extra syntax seems more than appropriate to me.
The asterisk also makes it trivial (using regular expressions) to tell whether a string of code contains any generator functions.
"Explicit is better than implicit" is a rule of thumb that Python supposedly values, but neglects to follow here!