[Python-Dev] Pre-PEP: Attribute Access Handlers v2

Finn Bock bckfnn@worldonline.dk
Fri, 21 Jul 2000 21:59:53 GMT


[Paul Prescod on computed attributes]

I'm not sure how well this is connected, but I would like to describe an
existing feature of JPython that allow for computed attributes.

The implementation of every python object have three methods (a little
simplified):

    public PyObject _doget(PyObject container) {
        return this;
    }

    public boolean _doset(PyObject container, PyObject value) {
        return false;
    }

    public boolean _dodel(PyObject container) {
        return false;
    }

As part of the implementation of __getattr__, the _doget method is
always called:

    public PyObject __findattr__(String name) {
        ...
        PyObject ret = __class__.lookup(name, false);
        if (ret != null)
            return ret._doget(this);
        return null;
    }

This way each computed attribute get controll when accessed, modified
and deleted. The hooks primary purpose is to support JPythons use of
java bean properties, fields and methods. It is currently not available
from within python, so it is not possible to define "def _doget(..)" in
a python class.

All this is just a datapoint.

regards,
finn