next up previous contents
Next: 11.2 Unix Signal Handling Up: 11 New in Release Previous: 11 New in Release

11.1 New Class Features

The semantics of __coerce__ have been changed to be more reasonable. As an example, the new standard module Complex implements fairly complete complex numbers using this. Additional examples of classes with and without __coerce__ methods can be found in the Demo/classes subdirectory, modules Rat and Dates.

If a class defines no __coerce__ method, this is equivalent to the following definition:

def __coerce__(self, other): return self, other

If __coerce__ coerces itself to an object of a different type, the operation is carried out using that type -- in release 1.1, this would cause an error.

Comparisons involving class instances now invoke __coerce__ exactly as if cmp(x, y) were a binary operator like + (except if x and y are the same object).



guido@cnri.reston.va.us