Message291290
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. |
|
Date |
User |
Action |
Args |
2017-04-07 20:23:13 | terry.reedy | set | recipients:
+ terry.reedy, martin.panter, Thomas Antony |
2017-04-07 20:23:13 | terry.reedy | set | messageid: <1491596593.94.0.521127199211.issue29987@psf.upfronthosting.co.za> |
2017-04-07 20:23:13 | terry.reedy | link | issue29987 messages |
2017-04-07 20:23:13 | terry.reedy | create | |
|