|
Re: How to specify __contains__ method?: msg#00013python.pyrex
Am So, den 11.04.2004 schrieb Gary Bishop um 20:43: Known bug ;) [I'm just not sure if I mailed it away or if I forgot to mail the bugfix in ;) ] Ok, in Pyrex/Compiler/TypeSlots.py look for a line like that: MethodSlot(objargproc, "sq_contains", "__contains__"), change it then to: MethodSlot(cmpfunc, "sq_contains", "__contains__"), Sorry, for this "manual, from memory" patch, but I've got the fixed stuff in the office, so I cannot check before Tuesday. Andreas > When I compile the following simple example: > > cdef class foo: > def __contains__(self, key): > return 1 > > I get the error message: > > d:\msl\gb\python\my\Matrix\bug2.pyx:3:11: Return with value in void function > > If I change "def" to "cdef int", it gets past Pyrex but the C compiler > complains: > > bug2.c(147) : warning C4028: formal parameter 1 different from declaration > > But it appears to work. > > Now in a more complicated case, I can't get it to work properly. > > cdef class foo: > cdef int val > def __init__(self): > val = 0 > > cdef int __contains__(self, key): > print 'foo contains', self.val > return 1 > > cdef class fee(foo): > cdef int __contains__(self, key): > print 'fee contains', self.val > return 0 > > cdef class faa(fee): > def bof(self): > print 'bof', self.val > cdef int __contains__(self, key): > print 'faa contains', self.val > return 0 > > If I leave off that last cdef int __contains__, I get C compiler errors like: > > bug2.c(275) : warning C4028: formal parameter 1 different from declaration > bug2.c(421) : warning C4028: formal parameter 1 different from declaration > bug2.c(568) : error C2065: 'None' : undeclared identifier > bug2.c(568) : error C2099: initializer is not a constant > > With it included, it will compile but when I try to do > import bug2 > faa = bug2.faa() > 1 in faa > > I get: > faa contains > Exception exceptions.AttributeError: "'bug2.faa' object has no > attribute 'val'" in 'bug2.faa.__contains__' ignored > > I seem to have lost my connection (via inheritance) to the original foo class. > > I poked around in the Pyrex0.9 source a little but couldn't find my way > to where this might happen. > > Any ideas for a work around? > > Thanks for Pyrex, it is GREAT STUFF. > gb > > _______________________________________________ > Pyrex mailing list > Pyrex@xxxxxxxxxxxxxxxxx > http://lists.copyleft.no/mailman/listinfo/pyrex
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | How to specify __contains__ method?: 00013, Gary Bishop |
|---|---|
| Next by Date: | Team Pyrex Mission Statement: 00013, Paul Prescod |
| Previous by Thread: | How to specify __contains__ method?i: 00013, Gary Bishop |
| Next by Thread: | Re: How to specify __contains__ method?: 00013, Greg Ewing |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |