[Python-Dev] Issues with PEP 482 (1)

Mark Shannon mark at hotpy.org
Tue Apr 28 22:00:17 CEST 2015



On 28/04/15 20:39, Paul Sokolovsky wrote:
> Hello,
>
> On Tue, 28 Apr 2015 19:44:53 +0100
> Mark Shannon <mark at hotpy.org> wrote:
>
> []
>
>> A coroutine without a yield statement can be defined simply and
>> concisely, thus:
>>
>> @coroutine
>> def f():
>>       return 1
>
> []
>
>> A pure-python definition of the "coroutine" decorator is
>> given below.
>>
>
> []
>
>> from types import FunctionType, CodeType
>>
>> CO_COROUTINE = 0x0080
>> CO_GENERATOR = 0x0020
>>
>> def coroutine(f):
>>       'Converts a function to a generator function'
>>       old_code = f.__code__
>>       new_code = CodeType(
>>           old_code.co_argcount,
>>           old_code.co_kwonlyargcount,
>
>
> This is joke right?
Well it was partly for entertainment value, although it works on PyPy.

The point is that something that can be done with a decorator, whether 
in pure Python or as builtin, does not require new syntax.

Cheers,
Mark.



More information about the Python-Dev mailing list