Message2549
This looks like a good start, but I do have a few comments.
We're not using Java 5 yet, so your complexFromObject can't use
autounboxing to get Double and Integer objects into PyComplex. That
doesn't actually matter though because there's an easier
implementation of complexFromObject. Java methods exposed to Jython
can just take PyObject and Jython will do the right thing in looking
them up and calling them. PyObject has a __complex__ method on it
just like the special method in Python that returns a complex version
of a given object. The only thing you have to do other than calling
__complex__ is check for an AttributeError being raised. That's what
PyObject does by default, so if a subclass hasn't implemented
__complex__, you need to handle that and throw a type error instead.
It'd look something like:
try {
return in.__complex__();
} catch(PyException pyEx) {
if(pyEx.type == Py.AttributeError) {
throw Py.TypeError("a float is required");
}
throw pyEx;
}
So you can just replace all of your Object in arguments with PyObject
in and you should be good to go.
I'm not actually looking at your implementation of complex math. I'm
assuming you can transcribe it from C pretty well and I don't actually
want to remember how to work with complex numbers. It would be nice
if you'd expand on test_cmath.py to actually exercise this. I'm sure
the CPython people wouldn't mind an expanded test suite. |
|
Date |
User |
Action |
Args |
2008-02-20 17:18:34 | admin | link | issue1600162 messages |
2008-02-20 17:18:34 | admin | create | |
|