diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | psycopg/typecast.c | 22 |
2 files changed, 22 insertions, 5 deletions
@@ -1,5 +1,10 @@ 2005-10-18 Federico Di Gregorio <fog@initd.org> + * psycopg/typecast.c: temporary fix to typecasting objects to return + False for any comparaison except an integer in self.values (i.e., we + don't raise an exception anymore on a coerce error.) Epydoc is now + happy. + * psycopg/config.h: ZETA config.h patch from Charlie Clark. * examples/threads.py: fixed small typo: psycopg -> psycopg2. diff --git a/psycopg/typecast.c b/psycopg/typecast.c index 19bcf1f..7ab8bc5 100644 --- a/psycopg/typecast.c +++ b/psycopg/typecast.c @@ -221,8 +221,12 @@ typecast_coerce(PyObject **pv, PyObject **pw) return 0; } } - PyErr_SetString(PyExc_TypeError, "type coercion failed"); - return -1; + + /* PyErr_SetString(PyExc_TypeError, "type coercion failed"); */ + /* let's try to return None instead of raising an exception */ + Py_INCREF(*pv); + Py_INCREF(*pw); + return 0; } static PyNumberMethods typecastObject_as_number = { @@ -255,13 +259,21 @@ static PyNumberMethods typecastObject_as_number = { /* object methods */ static int -typecast_cmp(typecastObject *self, typecastObject *v) +typecast_cmp(typecastObject *self, PyObject* obj) { + typecastObject *v = NULL; int res; - + + if (PyObject_TypeCheck(obj, &typecastType)) { + v = (typecastObject*)obj; + } + else { + return 1; + } + if (PyObject_Length(v->values) > 1 && PyObject_Length(self->values) == 1) { /* calls itself exchanging the args */ - return typecast_cmp(v, self); + return typecast_cmp(v, (PyObject*)self); } res = PySequence_Contains(self->values, PyTuple_GET_ITEM(v->values, 0)); |