Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-06 Thread Michele Simionato
Phillip J. Eby pje at telecommunity.com writes: 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. In other words, the confusion is in the idea of

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-06 Thread Michele Simionato
Terry Reedy tjreedy at udel.edu writes: tout court?? is not English or commonly used at least in America It is French: http://encarta.msn.com/dictionary_561508877/tout_court.html I thought it was common in English too, but clearly I was mistaken. Ok, you mean generator function, which

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Michele Simionato
Neal Norwitz nnorwitz at gmail.com writes: I wonder whether a check shouldn't just return (co_flags 0x20), which is CO_GENERATOR. Makes more sense. Okay, but my point is that the final user should not be expected to know about those implementation details. The one obvious way to me is

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Georg Brandl
Michele Simionato wrote: Neal Norwitz nnorwitz at gmail.com writes: I wonder whether a check shouldn't just return (co_flags 0x20), which is CO_GENERATOR. Makes more sense. Okay, but my point is that the final user should not be expected to know about those implementation details.

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Terry Reedy
Michele Simionato [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Neal Norwitz nnorwitz at gmail.com writes: I wonder whether a check shouldn't just return (co_flags 0x20), which is CO_GENERATOR. Makes more sense. Okay, but my point is that the final user should not be

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Michele Simionato
Terry Reedy tjreedy at udel.edu writes: To me, another obvious way is isinstance(object, gentype) where gentype = type(i for i in []) # for instance which should also be in types module. No, that check would match generator objects, not generators tout court. On a related notes,

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Michele Simionato
Georg Brandl g.brandl at gmx.net writes: I'd say, go ahead and write a patch including docs, and I think there's no problem with accepting it (as long as it comes before beta1). I was having a look at http://docs.python.org/dev/lib/inspect-types.html and it would seem that adding isgenerator

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Georg Brandl
Michele Simionato wrote: Georg Brandl g.brandl at gmx.net writes: I'd say, go ahead and write a patch including docs, and I think there's no problem with accepting it (as long as it comes before beta1). I was having a look at http://docs.python.org/dev/lib/inspect-types.html and it would

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Georg Brandl
Michele Simionato wrote: Georg Brandl g.brandl at gmx.net writes: Also, should one add a GeneratorType, perhaps as a subclass of FunctionType? Add GeneratorType where? There is already one in the types module. Yep, this is the crux. types.GeneratorType refers to generator objects,

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Terry Reedy
Michele Simionato [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] No, that check would match generator objects, not generators tout court. tout court?? is not English or commonly used at least in America On a related notes, inspect.isfunction gives True on a generator, such as

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Terry Reedy
Michele Simionato [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Yep, this is the crux. types.GeneratorType refers to generator objects, which in an improper sense are instances of a generator function. I.e. def g(): yield 1 # this is a generator go = g() # this is a generator

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Phillip J. Eby
At 09:26 AM 6/1/2006 +, Michele Simionato wrote: Terry Reedy tjreedy at udel.edu writes: To me, another obvious way is isinstance(object, gentype) where gentype = type(i for i in []) # for instance which should also be in types module. No, that check would match generator objects, not

Re: [Python-Dev] feature request: inspect.isgenerator

2006-06-01 Thread Michael Chermside
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:

Re: [Python-Dev] feature request: inspect.isgenerator

2006-05-29 Thread Terry Reedy
Michele Simionato [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Is there still time for new feature requests in Python 2.5? I am missing a isgenerator function in the inspect module. Right now I am using def isgenerator(func): return func.func_code.co_flags == 99 but it is

Re: [Python-Dev] feature request: inspect.isgenerator

2006-05-29 Thread Fredrik Lundh
Terry Reedy wrote: def isgenerator(func): return func.func_code.co_flags == 99 but it is rather ugly (horrible indeed). To me, part of the beauty of Python is that is so easy to write such things so compactly, so that we do not need megaAPIs with hundreds of functions and methods.

Re: [Python-Dev] feature request: inspect.isgenerator

2006-05-29 Thread Georg Brandl
Fredrik Lundh wrote: Terry Reedy wrote: def isgenerator(func): return func.func_code.co_flags == 99 but it is rather ugly (horrible indeed). To me, part of the beauty of Python is that is so easy to write such things so compactly, so that we do not need megaAPIs with hundreds of

Re: [Python-Dev] feature request: inspect.isgenerator

2006-05-29 Thread Neal Norwitz
On 5/29/06, Georg Brandl [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: is there some natural and obvious connection between generators and that number that I'm missing, or is that constant perhaps best hidden inside some introspection support module? It seems to be a combination of