@@ -168,40 +168,36 @@ def isfunction(object):
168168 __kwdefaults__ dict of keyword only parameters with defaults"""
169169 return isinstance (object , types .FunctionType )
170170
171- def isgeneratorfunction (object ):
171+ def isgeneratorfunction (obj ):
172172 """Return true if the object is a user-defined generator function.
173173
174174 Generator function objects provide the same attributes as functions.
175175 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 )
181180
182- def iscoroutinefunction (object ):
181+ def iscoroutinefunction (obj ):
183182 """Return true if the object is a coroutine function.
184183
185184 Coroutine functions are defined with "async def" syntax.
186185 """
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 ))
192190
193- def isasyncgenfunction (object ):
191+ def isasyncgenfunction (obj ):
194192 """Return true if the object is an asynchronous generator function.
195193
196194 Asynchronous generator functions are defined with "async def"
197195 syntax and have "yield" expressions in their body.
198196 """
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 )
205201
206202def isasyncgen (object ):
207203 """Return true if the object is an asynchronous generator."""
0 commit comments