[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] 2D vector class



On 8/12/06, Alex Holkner <aholkner@xxxxxxxxxxxxxx> wrote:
You won't be able to meaningfully overload operators if you subclass
tuple (vector + tuple will not equal tuple + vector).

In the code I emailed, there is a unit test for exactly that problem
with a tuple inherited vector class, it works just fine.

The issue of right side or left side operators has nothing to do with
whether you overload tuple or not. You could overload object, and
still need to support both vector + tuple and tuple + vector.

In addition, Python can handle that just fine. There are seperate
operators to overload for when the object is on each side (they just
add r in front of the name for the right side one, so __add__ and
__radd__)

Finally, python seems to know to let your user classes operators win
over all built in operators on either side of the operator (I don't
know how it would decide what to do when two user classes overload,
maybe that's where left side wins... anybody?)