11. Special Methods

Viper implements the following special methods, other than __getattr__ which is described above. It is important to note that some of these methods are search for using the fully generalised getattr function, and thus hook both the type object lookup, and also any __getattr__ method (provided by a class instance or the type object).

Other methods only work for instances. The reason for this disparity is efficiency.

Some special methods provided by Python are not available in Viper. These are '__cmp__', '__hash__', and all the numerical operators except __add__ and __mul__. Hash is a bad idea in Viper, Viper hashes things well enough, and much faster than any Python code. Not supporting __hash__ will have no effect on well written Python executed by Viper.

Emulation of numbers is not provided in Viper either. The reason is that a lot of complex machinery is required, and I consider it useless because object oriented systems cannot support binary operators correctly. Support may be added later for compatibility with python.

__add__ and __mul__ are provided only to support emulation of sequences.

The __str__, __repr__ and __erepr__ method use generalised searching, and therefore can be provided for any kind of object.

All the other methods apply only to instances, even if these methods are provided in the type objects of the object, they will not be called.