[Cython] On cdef and cpdef discrepencies

Robert Bradshaw robertwb at gmail.com
Fri Jun 23 02:18:18 EDT 2017


On Thu, Jun 22, 2017 at 1:25 AM, Jeroen Demeyer <jdemeyer at cage.ugent.be> wrote:
> On 2017-06-21 21:51, Robert Bradshaw wrote:
>>
>> I'll see if I can put together a patch.
>
>
> For what? For Sage? For Cython?

I was thinking for Sage. I was assuming there was just an oddball
collection of oversights accumulated over the yeras.

> Anyway, I think that coping with this new error message is not particularly
> hard, just a lot of work. That's why I would prefer a warning instead of an
> error. That way, we can easily see how bad the problem is and what needs to
> be fixed and we fix it gradually (say, before Cython 0.27 which could make
> this a hard error).

I was digging into this a bit more, and the issue seems to be entirely
the arithmetic methods like _add_, and was introduced one year and one
day ago: https://github.com/sagemath/sage/commit/e1d2ba46574273ec4d358e654ed195a82b81a654
. It'd be cleaner if these were in fact cpdef methods, but our
category method injection framework requires that the class not have
an _add_ defined at the Python level. But any overrides must be cpdef
methods lest a (Python) call to x._add_(y) succeed but not find the
override.

Perhaps it'd be more clear to define cpdef Element._add_ whose
implementation directly calls getattr_from_category rather than
(<object>self)._add_.

- Robert


More information about the cython-devel mailing list