[Cython] pure mode quirk

Stefan Behnel stefan_ml at behnel.de
Thu May 10 13:39:26 CEST 2012


mark florisson, 10.05.2012 11:41:
> On 10 May 2012 10:25, Stefan Behnel wrote:
>> when declaring a C function in pure mode, you eventually end up with this:
>>
>>    @cython.cfunc
>>    @cython.returns(cython.bint)
>>    @cython.locals(a=cython.int, b=cython.int, c=cython.int)
>>    def c_compare(a,b):
>>        c = 5
>>        return a == b + c
>>
>> That is very verbose, making it hard to find the name of the actual
>> function. It's also not very intuitive that @cython.locals() is the way to
>> declare arguments.
>>
>> I would find it more readable to support this:
>>
>>    @cython.cfunc(cython.bint, a=cython.int, b=cython.int)
>>    @cython.locals(c=cython.int)
>>    def c_compare(a,b):
>>        c = 5
>>        return a == b
>>
>> But the problem here is that it conflicts with
>>
>>    @cython.cfunc
>>    def c_compare(a,b):
>>        c = 5
>>        return a == b
>>
>> when executed from Shadow.py. How should the fake decorator know that it is
>> being called with a type as first argument and not with the function it
>> decorates? Legacy, legacy ...
> 
> I personally don't care much for pure mode, but it could just do an
> instance check for a function. You only accept real def functions
> anyway.

Hmm, maybe, yes. IIRC, non-Cython decorators are otherwise forbidden on
cdef functions (but also on cpdef functions?), so the case that another
decorator replaces the function with something else in between isn't very
likely to occur.

In any case, the fix would be to change the decorator order to move the
Cython decorators right at the function declaration. Not sure if that'd be
completely obvious to everyone, but, as I said, not very likely to be a
problem ...

Stefan


More information about the cython-devel mailing list