[Python-Dev] iscoroutinefunction vs. coroutines (original) (raw)
Matthias Urlichs smurf at noris.de
Thu Mar 9 06:04:40 EST 2017
- Previous message (by thread): [Python-Dev] Python Design issue with print() function
- Next message (by thread): [Python-Dev] iscoroutinefunction vs. coroutines
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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>
- Previous message (by thread): [Python-Dev] Python Design issue with print() function
- Next message (by thread): [Python-Dev] iscoroutinefunction vs. coroutines
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]