Search in sources :

Example 11 with DefinePyFunction

use of org.cafebabepy.runtime.module.DefinePyFunction in project cafebabepy by cafebabepy.

the class PyListType method __getitem__.

@DefinePyFunction(name = __getitem__)
public PyObject __getitem__(PyObject self, PyObject key) {
    if (!(self instanceof PyListObject)) {
        throw this.runtime.newRaiseTypeError("descriptor '__getitem__' requires a 'list' object but received a '" + self.getType().getFullName() + "'");
    }
    if (!(key instanceof PyIntObject)) {
        throw this.runtime.newRaiseTypeError("list indices must be integers or slices, not " + key.getType().getFullName());
    }
    PyListObject list = (PyListObject) self;
    PyIntObject index = (PyIntObject) key;
    return list.get(index);
}
Also used : PyListObject(org.cafebabepy.runtime.object.java.PyListObject) PyIntObject(org.cafebabepy.runtime.object.java.PyIntObject) DefinePyFunction(org.cafebabepy.runtime.module.DefinePyFunction)

Aggregations

DefinePyFunction (org.cafebabepy.runtime.module.DefinePyFunction)11 PyObject (org.cafebabepy.runtime.PyObject)9 PyIntObject (org.cafebabepy.runtime.object.java.PyIntObject)4 ArrayList (java.util.ArrayList)1 PyRangeIteratorObject (org.cafebabepy.runtime.object.iterator.PyRangeIteratorObject)1 PyListObject (org.cafebabepy.runtime.object.java.PyListObject)1 PyTupleObject (org.cafebabepy.runtime.object.java.PyTupleObject)1 PyMethodTypeObject (org.cafebabepy.runtime.object.proxy.PyMethodTypeObject)1