[Python-Dev] iscoroutinefunction vs. coroutines
Matthias Urlichs
smurf at noris.de
Thu Mar 9 06:04:40 EST 2017
Hi,
Is this pattern
def foo():
return bar()
async def bar():
await <whatever>
async def async_main():
await foo()
considered to be valid?
The reason I'm asking is that some code out there likes to accept a
might-be-a-coroutine-function argument, using
def run_callback(fn):
if iscoroutinefunction(fn):
res = await fn()
else:
res = fn()
instead of
def run_callback(fn):
res = fn()
if iscoroutine(res):
res = await res()
The former obviously breaks when somebody combines these idioms and calls
run_callback(foo)
but I can't help but wonder whether the latter use might be deprecated, or
even warned about, in the future and/or with non-CPython implementations.
--
-- Matthias Urlichs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170309/fc10ec40/attachment.sig>
More information about the Python-Dev
mailing list