Message3703

Author certik
Recipients certik
Date 2008-10-26.22:14:10
SpamBayes Score 1.9984014e-15
Marked as misclassified No
Message-id <1225059251.1.0.806443893468.issue1159@psf.upfronthosting.co.za>
In-reply-to
Content
Run this file:

-----------------

class DummyNumber(object):
    """
    Minimal implementation of a number that works with SymPy.

    If one has a Number class (e.g. Sage Integer, or some other custom
class)
    that one wants to work well with SymPy, one has to implement at
least the
    methods of this class DummyNumber, resp. it's subclasses I5 and F1_1.

    Basically, one just needs to implement either __int__() or
__float__() and
    then one needs to make sure that the class works with Python
integers and
    with itself.
    """

    def __radd__(self, a):
        if isinstance(a, (int, float)):
            return a + self.number
        return NotImplemented

    def __add__(self, a):
        if isinstance(a, (int, float, DummyNumber)):
            return self.number + a
        return NotImplemented

    def __rsub__(self, a):
        if isinstance(a, (int, float)):
            return a - self.number
        return NotImplemented

    def __sub__(self, a):
        if isinstance(a, (int, float, DummyNumber)):
            return self.number - a
        return NotImplemented

    def __rmul__(self, a):
        if isinstance(a, (int, float)):
            return a * self.number
        return NotImplemented

    def __mul__(self, a):
        if isinstance(a, (int, float, DummyNumber)):
            return self.number * a
        return NotImplemented

    def __rdiv__(self, a):
        if isinstance(a, (int, float)):
            return a / self.number
        return NotImplemented

    def __div__(self, a):
        if isinstance(a, (int, float, DummyNumber)):
            return self.number / a
        return NotImplemented

    def __rpow__(self, a):
        if isinstance(a, (int, float)):
            return a ** self.number
        return NotImplemented

    def __pow__(self, a):
        if isinstance(a, (int, float, DummyNumber)):
            return self.number ** a
        return NotImplemented

    def __pos__(self):
        return self.number

    def __neg__(self):
        return - self.number

class I5(DummyNumber):
    number = 5
    def __int__(self):
        return self.number

class F1_1(DummyNumber):
    number = 1.1
    def __float__(self):
        return self.number

i5 = I5()
f1_1 = F1_1()

print f1_1**i5
print f1_1**f1_1

-----------------

$ jython w.py 
Traceback (most recent call last):
  File "w.py", line 83, in <module>
    print f1_1**i5
java.lang.NullPointerException
	at org.python.core.StdoutWrapper.print(StdoutWrapper.java:108)
	at org.python.core.StdoutWrapper.println(StdoutWrapper.java:167)
	at org.python.core.Py.println(Py.java:1316)
	at org.python.pycode._pyx0.f$0(w.py)
	at org.python.pycode._pyx0.call_function(w.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:199)
	at org.python.core.PyCode.call(PyCode.java:14)
	at org.python.core.Py.runCode(Py.java:1201)
	at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:155)
	at org.python.util.jython.run(jython.java:226)
	at org.python.util.jython.main(jython.java:113)

java.lang.NullPointerException: java.lang.NullPointerException


----------

if you comment out the "print f1_1**i5", it fails here:

------------

$ jython w.py 
Traceback (most recent call last):
  File "w.py", line 84, in <module>
    print f1_1**f1_1
TypeError: unsupported operand type(s) for **: 'F1_1' and 'F1_1'
History
Date User Action Args
2008-10-26 22:14:11certiksetrecipients: + certik
2008-10-26 22:14:11certiksetmessageid: <1225059251.1.0.806443893468.issue1159@psf.upfronthosting.co.za>
2008-10-26 22:14:11certiklinkissue1159 messages
2008-10-26 22:14:10certikcreate