Closures in leu of pointers?

Chris Angelico rosuav at gmail.com
Sun Jun 30 01:59:21 EDT 2013


On Sun, Jun 30, 2013 at 3:46 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On a related note, I think that generator functions should in some way
> be explicitly marked as such in the declaration, rather than needing
> to scan the entire function body for a yield statement to determine
> whether it's a generator or not.

Most functions are:

def func(args):
    body
    return result

Generators are:

class func(args): # okay, you can't shortcut it like that, give it an
__init__ method
    def do_stuff(self):
        body
        yield results one by one

I don't know that anything would be gained by having a different
function declaration statement/attribute, but maybe this is something
that would benefit from a code comment (which, as far as I'm
concerned, is as much a part of the function signature as the coded
parts are).

ChrisA



More information about the Python-list mailing list