def PyObject_GenericSetAttr(space, w_obj, w_name, w_value): """Generic attribute setter function that is meant to be put into a type object's tp_setattro slot. It looks for a data descriptor in the dictionary of classes in the object's MRO, and if found it takes preference over setting the attribute in the instance dictionary. Otherwise, the attribute is set in the object's __dict__ (if present). Otherwise, an AttributeError is raised and -1 is returned.""" from pypy.objspace.descroperation import object_setattr, object_delattr if w_value is not None: w_descr = object_setattr(space) space.get_and_call_function(w_descr, w_obj, w_name, w_value) else: w_descr = object_delattr(space) space.get_and_call_function(w_descr, w_obj, w_name) return 0