[PyQt] SIP: rich compare with a tuple bug?

Phil Thompson phil at riverbankcomputing.com
Thu Apr 24 12:36:56 BST 2008


On Wednesday 23 April 2008, Kevin Watters wrote:
> I think I found a bug with rich comparison operators. I have a simple class
> like this:
>
> class point
> {
> public:
> 	point();
> 	point(int x, int y);
>
> 	int x;
> 	int y;
> %ConvertToTypeCode
> 	/* (convert sequences with 2 ints to points) */
> %End
>
> 	bool operator==(const point&);
> };
>
> The ConvertToTypeCode successfully makes it so that any function expecting
> a point object will take a 2-tuple (or 2 integer sequence of any type) just
> fine.
>
> But I'm having problems with the operator== -- it doesn't work for tuples.
>
> >From Python:
>
> p = point(42, 5)
> p == (42, 5) # False
>
> If I step into my ConvertToTypeCode, I see that sipPy is only getting the
> first integer in the tuple. So this actually works:
>
> p = point(42, 5)
> p == ((42, 5), ) # True
>
> But strangely, if I use any other sequence than a tuple, it appears to work
> fine:
>
> p = point(42, 5)
> p == [42, 5] # True
>
> So that leads me to believe that somewhere we're missing a PyTuple_New in
> SIP. I can't quite figure out where in the SIP source this should be
> happening, though.
>
> All of the relevant code is in this pastebin: http://pastebin.org/31587
>
> Thanks for any help!

It should be fixed in tonight's snapshot.

Thanks,
Phil


More information about the PyQt mailing list