[pylucene-dev] InvalidArgsError nit with class methods
Aaron Lav
asl2 at pobox.com
Sun Nov 2 16:23:34 PST 2008
A coworker of mine noted that the first argument reported by
InvalidArgsError for class methods was always 'type'.
It looks like the PyErr_SetArgsError overload which takes a
PyTypeObject * wasn't being called: I've attached a test
case and a patch.
Thanks,
Aaron Lav (asl2 at pobox.com)
-------------- next part --------------
Index: jcc/python.py
===================================================================
--- jcc/python.py (revision 483)
+++ jcc/python.py (working copy)
@@ -932,8 +932,9 @@
line(out, indent + 1, 'return callSuper(&%sType, (PyObject *) self, "%s"%s, %d);',
names[-1], name, args, cardinality)
else:
- line(out, indent + 1, 'PyErr_SetArgsError((PyObject *) %s, "%s"%s);',
- static and 'type' or 'self', name, args)
+ line(out, indent + 1, 'PyErr_SetArgsError(%s, "%s"%s);',
+ static and '(PyTypeObject *) type' or '(PyObject *) self',
+ name, args)
line(out, indent + 1, 'return NULL;')
line(out, indent, '}')
-------------- next part --------------
from unittest import TestCase, main
from lucene import *
class InvalidArgsTestCase(TestCase):
def testInstance(self):
# can't use assertRaises since we need to test args of the
# returned exception
exception = None
try:
Integer(2.0)
except InvalidArgsError, e:
exception = e
self.assert_(exception)
self.assertEqual(exception.args[0],Integer)
self.assertEqual(exception.args[1], '__init__')
self.assertEqual(exception.args[2], (2.0,))
def testClass(self):
exception = None
try:
NumberTools.stringToLong(2.0)
except InvalidArgsError, e:
exception = e
self.assert_(exception)
self.assertEqual(exception.args[0],NumberTools)
self.assertEqual(exception.args[1], 'stringToLong')
self.assertEqual(exception.args[2], 2.0)
if __name__ == "__main__":
import sys, lucene
env = lucene.initVM(lucene.CLASSPATH)
if '-loop' in sys.argv:
sys.argv.remove('-loop')
while True:
try:
main()
except:
pass
else:
main()
More information about the pylucene-dev
mailing list