Skip to content

Commit

Permalink
[Python] Restore compatibility with Cython 0.29.31
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Oct 21, 2024
1 parent 1dd756a commit 3d1ea26
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/func1.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ cdef class Func1:
cdef object exception
cpdef void _set_callback(self, object) except *
@staticmethod
cdef shared_ptr[CxxFunc1] _make_cxx_func1(string, tuple)
cdef shared_ptr[CxxFunc1] _make_cxx_func1(string, tuple) except *
@staticmethod
cdef Func1 _make_func1(shared_ptr[CxxFunc1])
40 changes: 35 additions & 5 deletions interfaces/cython/cantera/func1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ cdef class Func1:
return pystr(self.func.type())

@staticmethod
cdef shared_ptr[CxxFunc1] _make_cxx_func1(string cxx_string, tuple args):
cdef shared_ptr[CxxFunc1] _make_cxx_func1(string cxx_string, tuple args) except *:
"""Create C++ functor from type specifier and arguments."""
cdef shared_ptr[CxxFunc1] func
cdef Func1 f0
Expand Down Expand Up @@ -244,7 +244,15 @@ cdef class Func1:
if not isinstance(other, Func1):
other = Func1(other)
cdef Func1 f1 = other
return Func1._make_func1(CxxNewSumFunction(self._func, f1._func))

# @todo: When dropping support for Cython < 3.0.0, 'f0' can be removed and
# 'self._func' can be used directly in the C++ call
cdef Func1 f0
if isinstance(self, Func1):
f0 = self
else:
f0 = Func1(self)
return Func1._make_func1(CxxNewSumFunction(f0._func, f1._func))

def __radd__(self, other):
if not isinstance(other, Func1):
Expand All @@ -256,7 +264,15 @@ cdef class Func1:
if not isinstance(other, Func1):
other = Func1(other)
cdef Func1 f1 = other
return Func1._make_func1(CxxNewDiffFunction(self._func, f1._func))

# @todo: When dropping support for Cython < 3.0.0, 'f0' can be removed and
# 'self._func' can be used directly in the C++ call
cdef Func1 f0
if isinstance(self, Func1):
f0 = self
else:
f0 = Func1(self)
return Func1._make_func1(CxxNewDiffFunction(f0._func, f1._func))

def __rsub__(self, other):
if not isinstance(other, Func1):
Expand All @@ -268,7 +284,14 @@ cdef class Func1:
if not isinstance(other, Func1):
other = Func1(other)
cdef Func1 f1 = other
return Func1._make_func1(CxxNewProdFunction(self._func, f1._func))
# @todo: When dropping support for Cython < 3.0.0, 'f0' can be removed and
# 'self._func' can be used directly in the C++ call
cdef Func1 f0
if isinstance(self, Func1):
f0 = self
else:
f0 = Func1(self)
return Func1._make_func1(CxxNewProdFunction(f0._func, f1._func))

def __rmul__(self, other):
if not isinstance(other, Func1):
Expand All @@ -280,7 +303,14 @@ cdef class Func1:
if not isinstance(other, Func1):
other = Func1(other)
cdef Func1 f1 = other
return Func1._make_func1(CxxNewRatioFunction(self._func, f1._func))
# @todo: When dropping support for Cython < 3.0.0, 'f0' can be removed and
# 'self._func' can be used directly in the C++ call
cdef Func1 f0
if isinstance(self, Func1):
f0 = self
else:
f0 = Func1(self)
return Func1._make_func1(CxxNewRatioFunction(f0._func, f1._func))

def __rtruediv__(self, other):
if not isinstance(other, Func1):
Expand Down

0 comments on commit 3d1ea26

Please sign in to comment.