[Python-Dev] feature request: inspect.isgenerator
Michael Chermside
mcherm at mcherm.com
Thu Jun 1 19:18:49 CEST 2006
Phillip J. Eby writes:
> Yes, I think the whole concept of inspecting for this is broken.
> *Any* function can return a generator-iterator. A generator
> function is just a function that happens to always return one.
Just following up on Phillip's comments, consider the following functions:
def foo(x):
while still_going(x):
yield some_func(x)
def bar(x):
while still_going(x):
yield other_func(x)
def foo_or_bar(x):
if some_condition(x):
return foo(x)
else:
return bar(x)
I presume that Michele's proposal is that inspect.isgenerator() (or
perhaps "inspect.isgenfunc()") would return True for "foo" and "bar"
but false for "foo_or_bar". Can you give a single use case for which
that distinction is desirable?
-- Michael Chermside
More information about the Python-Dev
mailing list