[Xapian-discuss] Using a subclass of MatchSpy in Python bindings
Doctor Munchkin
doctormunchkin at gmail.com
Thu Dec 2 10:05:50 GMT 2010
On 1 December 2010 21:52, Olly Betts <olly at survex.com> wrote:
> On Wed, Dec 01, 2010 at 01:18:40PM +0000, Doctor Munchkin wrote:
>> >>> class MyMatchSpy(xapian.MatchSpy):
>> ... def __init__(self):
>> ... pass
>> ... def __call__(self, *args, **kw):
>> ... print "called with", args, kw
>> ...
>> >>> ms = MyMatchSpy()
>> >>> enquire = xapian.Enquire(database)
>> >>> enquire.add_matchspy(ms)
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> File "/usr/lib/python2.6/dist-packages/xapian/__init__.py", line
>> 6920, in _enquire_match_spy_add
>> _enquire_add_matchspy_orig(self, decider)
>> TypeError: in method 'Enquire_add_matchspy', argument 2 of type
>> 'Xapian::MatchSpy *'
>>
>> Am I missing something obvious here, or is swig misbehaving? The above
>> works if ms is an instance of xapian.ValueCountMatchSpy, but I need to
>> implement something different to this.
>
> I think you need to call the base class constructor in your constructor:
>
> def __init__(self):
> xapian.MatchSpy.__init__(self)
>
Hi Olly, thanks for the quick response.
When I try that, I get an error from MatchSpy's __init__:
>>> database = xapian.Database(dbpath)
>>>
>>> class MyMatchSpy(xapian.MatchSpy):
... def __init__(self):
... xapian.MatchSpy.__init__(self)
... def __call__(self, *args, **kw):
... print "called with", args, kw
...
>>> ms = MyMatchSpy()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
File "/usr/lib/python2.6/dist-packages/xapian/__init__.py", line
3201, in __init__
def __init__(self, *args, **kwargs): raise AttributeError("No
constructor defined")
AttributeError: No constructor defined
It looks like swig deliberately forbids subclassing of MatchSpy. Is
there a way around this?
Thanks,
Munchkin
More information about the Xapian-discuss
mailing list