These are chat archives for symengine/symengine

Aug 2014
Nikolaus Sonnenschein
Aug 13 2014 08:13 UTC

I am using sympy for a project where I am extending Symbol with a few extras. I was trying to see if I could switch over to csympy but I am having troubles with inheritance. For example (works fine with sympy)

from csympy import Symbol
class ChildSymbol(Symbol):
    def __init__(self, name, lb=None, ub=None):
        Symbol.__init__(name) = lb
        self.ub = None
child = ChildSymbol('a', lb=-10, ub=10)

will raise

TypeError                                 Traceback (most recent call last)
<ipython-input-26-bcfa3d993935> in <module>()
      5 = lb
      6         self.ub = None
----> 7 child = ChildSymbol('a', lb=-10, ub=10)

/Users/niko/Arbejder/Dev/csympy/build/csympy/lib/ in csympy.lib.csympy_wrapper.Symbol.__cinit__ (/Users/niko/Arbejder/Dev/csympy/build/csympy/lib/csympy_wrapper.cpp:4975)()

TypeError: __cinit__() got an unexpected keyword argument 'lb'

I am aware that inheritance is tricky in Cython (see for example and others). Does anyone maybe have a suggestion for how to circumvent that arguments are passed on to cinit? I am sorry if this is not an appropriate place to ask.

Ondřej Čertík
Aug 13 2014 19:54 UTC
Hi @phantomas1234 yes, it's an appropriate place to ask. I think @asmeurer mentioned on the list that you might want to do things differently. As to this particular issue, there might be some workaround in Cython, though I don't know myself. You could of course extend csympy in C++, and then wrap that.
What exactly is your application?
Aaron Meurer
Aug 13 2014 19:56 UTC
so do you just need to override __cinit__?