10. The __getattr__ method

If Viper is unable to fetch an attribute by normal means, it tries to find an callable attribute named '__getattr__'; if one is found, it is called with the attribute.

Note that this mechanism is special in Viper: the __getattr__ method is searched for even when the object is not a class instance. In particular, the __getattr__ method can be found in the type object of any object.

When the search for '__getattr__' is performed on a class instance, the search follows the standard sequence of examining the objects attribute dictionary, and then the class dictionary, and then the dictionaries of the base classes (binding the first argument to the object to create a bound method if the attribute is callable): this is the standard lookup mechanism: lookup in the type object will only proceed if it fails. Note that if a __getattr__ method is found by the standard lookup, it must be callable, and the result of calling it is final, so that if it fails, no further attempt is made to find the attribute. [Is this the most useful mechanism?]