Search in sources :

Example 1 with PyListObject

use of org.cafebabepy.runtime.object.java.PyListObject 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)1 PyIntObject (org.cafebabepy.runtime.object.java.PyIntObject)1 PyListObject (org.cafebabepy.runtime.object.java.PyListObject)1