On Wed, Mar 6, 2019 at 4:37 PM pylang <pyla...@gmail.com> wrote: >> def maybe_async(fn): >> @functools.wraps(fn) >> def wrapper(*args, **kwargs): >> coro = fn(*args, **kwargs) >> if asyncio.get_running_loop() is not None: >> return coro >> else: >> return await coro > > I was unable to run his example as-is (in Python 3.6 at least) since the > `await` keyword is only permitted inside an `async def` function.
Oh yeah, that was a brain fart. I meant to write: def maybe_async(fn): @functools.wraps(fn) def wrapper(*args, **kwargs): coro = fn(*args, **kwargs) if asyncio.get_running_loop() is not None: return coro else: return asyncio.run(coro) -n -- Nathaniel J. Smith -- https://vorpus.org _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/