Terry J. Reedy added the comment:
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.
----------
nosy: +terry.reedy
resolution: -> rejected
stage: -> resolved
status: open -> closed
type: -> enhancement
versions: +Python 3.7 -Python 3.5, Python 3.6
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29987>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com