isgenerator(...) - anywhere to be found?

Christian Heimes lists at cheimes.de
Tue Jan 22 10:06:47 EST 2008


Stefan Rank wrote:
> on 22.01.2008 14:20 Diez B. Roggisch said the following:
>> def isgenerator(v):
>>     def _g(): yield
>>     return type(v) == type(_g())
>>
>> But I wonder why there is no such method already available?
> 
> 
> This tests for generator objects, and you could also use::
> 
>    return type(v) is types.GeneratorType
> 
> I think that this is pretty direct already.
> 
> I also need to test for generator functions from time to time for which 
> I use::
> 
>    def _isaGeneratorFunction(func):
>        '''Check the bitmask of `func` for the magic generator flag.'''
>        return bool(func.func_code.co_flags & CO_GENERATOR)

Can you please write a function for the inspect module + docs + a small
unit tests and submit a patch? The inspect module is missing the
isgenerator function.

Christian




More information about the Python-list mailing list