source icon indicating copy to clipboard operation
source copied to clipboard

Cython 3.0 incompatible issue

Open munechika-koyo opened this issue 2 years ago • 4 comments

Hello,

I found that runtime error about vector multiplication calculation like:

>>> from raysect.core.math import Vector3D
>>> Vector(1, 2, 3) * 2.0
Vector3D(2.0, 4.0, 6.0)

>>> 2.0 * Vector3D(1, 2, 3)
TypeError: unsupported operand type(s) for *: 'int' and 'raysect.core.math.vector.Vector3D'

This error cannot be seen if I compile raysect by cython < 3.0.0. So, I suppose the issue is caused by cython 3.0 incompatibility.

munechika-koyo avatar Jul 27 '23 07:07 munechika-koyo

when checking the docs (https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html), I noticed that parameters of __mul__ method had been changed. (__mul__(x, y) -> __mul__(self, other)) This seems to cause the issue.

And we should implement __rmul__() reverse method.

munechika-koyo avatar Jul 27 '23 08:07 munechika-koyo

Hi, Yes, this applies to all binary arithmetic methods. As pointed out by @jacklovell in #373, there is a directive c_api_binop_methods=True that allows the old implementation to continue working. I was going to fix Raysect incompatibility with Cython 3.0, but haven't found the time yet. I will try to look in the near future, because this also affects Cherab.

vsnever avatar Jul 27 '23 13:07 vsnever

Thank you for your prompt reply. I could not noticed that issue. I am also trying to fix all binary arithmetic methods at least and going to push the PR, so please consider it if you are welcome.

munechika-koyo avatar Jul 27 '23 14:07 munechika-koyo

I am also trying to fix all binary arithmetic methods at least and going to push the PR, so please consider it if you are welcome.

Thank you very much! The fix you proposed is fine with me. Let's wait for a response from @CnlPepper.

vsnever avatar Aug 01 '23 16:08 vsnever