This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Thomas Antony, martin.panter, terry.reedy
Date 2017-04-07.20:23:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1491596593.94.0.521127199211.issue29987@psf.upfronthosting.co.za>
In-reply-to
Content
A generator function *gf* is a function that contain *yield* in its body.  When it is compiled, flag CO_GENERATOR is set in gf.__code__.co_flags.  When the function is called, the flag is queried and if set, a special path is taken that attaches the live but suspended code instance to a generator instance.

*isgeneratorfunction* tests that an object is a function and that the flag is set.

    return bool((isfunction(object) or ismethod(object)) and
                object.__code__.co_flags & CO_GENERATOR)

This is exactly what it should do.

Any function could potentially call a generator function and return its result.  Martin's *test2*, with or without the wrapper, is an example.

Note that *iscoroutinefunction* and *isaynchgenfunction* follow the same pattern, but with different flags.  A 4th flag is queried by *isawaitable*. The return object of any of these could also by returned by other functions.
History
Date User Action Args
2017-04-07 20:23:13terry.reedysetrecipients: + terry.reedy, martin.panter, Thomas Antony
2017-04-07 20:23:13terry.reedysetmessageid: <1491596593.94.0.521127199211.issue29987@psf.upfronthosting.co.za>
2017-04-07 20:23:13terry.reedylinkissue29987 messages
2017-04-07 20:23:13terry.reedycreate