[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-11 Thread Andrew Barnert via Python-ideas
> On Feb 11, 2020, at 14:02, Eric V. Smith wrote: > > One of the goals of the async/await syntax is to make it clear where control > can yield, and therefor where you need to be concerned about mutating state. > You don't have this explicitness with threads or with a hypothetical syntax >

[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-11 Thread Eric V. Smith
On 2/11/2020 2:33 AM, Ben Rudiak-Gould wrote: On Mon, Feb 10, 2020 at 9:50 AM Andrew Barnert via Python-ideas wrote: It’s a well-known problem that async is “contagious”: [...] But C# and every other language that’s borrowed the idea has the same problem, and as far as I know, nobody’s

[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-11 Thread Joao S. O. Bueno
The idea on the OP can be fully implemented with ~10 lines of code in a decorator - which could be further factored out into a decorator-for-decorators: ``` import asyncio, inspect def hybrid_decorator(func): coro = inspect.iscoroutinefunction(func) if coro: async def

[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-11 Thread Soni L.
On 2020-02-11 4:33 a.m., Ben Rudiak-Gould wrote: On Mon, Feb 10, 2020 at 9:50 AM Andrew Barnert via Python-ideas wrote: > It’s a well-known problem that async is “contagious”: [...] > > But C# and every other language that’s borrowed the idea has the same problem, and as far as I know,

[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-10 Thread Ben Rudiak-Gould
On Mon, Feb 10, 2020 at 9:50 AM Andrew Barnert via Python-ideas wrote: > It’s a well-known problem that async is “contagious”: [...] > > But C# and every other language that’s borrowed the idea has the same > problem, and as far as I know, nobody’s thought of a good answer yet. Threads don't

[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-10 Thread Soni L.
I wonder why async needed to be like it is. await foo(...) could have turned into something like foo.__await__(...) and had foo.__call__ just run the function anyway until actual yielding is necessary (at which point, raise RuntimeError). oh well, can't change that now I guess. :/ On

[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-10 Thread Andrew Barnert via Python-ideas
> On Feb 10, 2020, at 02:34, Bar Harel wrote: > > While I'm not this idea can totally work, I do think we need a method of > closing the gap between asyc coroutines and normal functions. > > As of today, async applications need to create an entirely different > codebase, sometimes just by

[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-10 Thread Bar Harel
While I'm not sure this idea can totally work, I do think we need a method of closing the gap between asyc coroutines and normal functions. As of today, async applications need to create an entirely different codebase, sometimes just by copy and paste, while changing function definitions to async

[Python-ideas] Re: New syntax for decorators that are compatible with both normal and async functions

2020-02-09 Thread Andrew Barnert via Python-ideas
On Feb 9, 2020, at 13:39, hason.a...@gmail.com wrote: > > As of today, in order to make a decorator compatible with both normal and > async functions, you have to write something like this: > > def decor(func): >if asyncio.iscoroutinefunction(func): >async def wrapper(*args,