@@ -168,40 +168,36 @@ def isfunction(object):
168
168
__kwdefaults__ dict of keyword only parameters with defaults"""
169
169
return isinstance (object , types .FunctionType )
170
170
171
- def isgeneratorfunction (object ):
171
+ def isgeneratorfunction (obj ):
172
172
"""Return true if the object is a user-defined generator function.
173
173
174
174
Generator function objects provide the same attributes as functions.
175
175
See help(isfunction) for a list of attributes."""
176
- is_generator_function = bool ((isfunction (object ) or ismethod (object )) and
177
- object .__code__ .co_flags & CO_GENERATOR )
178
- is_partial_generator = bool ((isinstance (object , functools .partial ) and
179
- object .func .__code__ .co_flags & CO_GENERATOR ))
180
- return is_generator_function or is_partial_generator
176
+ while isinstance (obj , functools .partial ):
177
+ obj = obj .func
178
+ return bool ((isfunction (obj ) or ismethod (obj )) and
179
+ obj .__code__ .co_flags & CO_GENERATOR )
181
180
182
- def iscoroutinefunction (object ):
181
+ def iscoroutinefunction (obj ):
183
182
"""Return true if the object is a coroutine function.
184
183
185
184
Coroutine functions are defined with "async def" syntax.
186
185
"""
187
- is_coroutine_function = bool (((isfunction (object ) or ismethod (object )) and
188
- object .__code__ .co_flags & CO_COROUTINE ))
189
- is_partial_coroutine = bool ((isinstance (object , functools .partial ) and
190
- object .func .__code__ .co_flags & CO_COROUTINE ))
191
- return is_coroutine_function or is_partial_coroutine
186
+ while isinstance (obj , functools .partial ):
187
+ obj = obj .func
188
+ return bool (((isfunction (obj ) or ismethod (obj )) and
189
+ obj .__code__ .co_flags & CO_COROUTINE ))
192
190
193
- def isasyncgenfunction (object ):
191
+ def isasyncgenfunction (obj ):
194
192
"""Return true if the object is an asynchronous generator function.
195
193
196
194
Asynchronous generator functions are defined with "async def"
197
195
syntax and have "yield" expressions in their body.
198
196
"""
199
- is_async_gen_function = bool ((isfunction (object ) or ismethod (object )) and
200
- object .__code__ .co_flags & CO_ASYNC_GENERATOR )
201
- is_partial_async_gen = bool ((isinstance (object , functools .partial ) and
202
- object .func .__code__ .co_flags & CO_ASYNC_GENERATOR ))
203
- return is_async_gen_function or is_partial_async_gen
204
-
197
+ while isinstance (obj , functools .partial ):
198
+ obj = obj .func
199
+ return bool ((isfunction (obj ) or ismethod (obj )) and
200
+ obj .__code__ .co_flags & CO_ASYNC_GENERATOR )
205
201
206
202
def isasyncgen (object ):
207
203
"""Return true if the object is an asynchronous generator."""
0 commit comments