Search in sources :

Example 1 with PyTupleObject

use of org.cafebabepy.runtime.object.java.PyTupleObject in project cafebabepy by cafebabepy.

the class PyTupleType method __getitem__.

@DefinePyFunction(name = __getitem__)
public PyObject __getitem__(PyObject self, PyObject key) {
    if (!(self instanceof PyTupleObject)) {
        throw this.runtime.newRaiseTypeError("descriptor '__getitem__' requires a 'tuple' object but received a '" + self.getType().getFullName() + "'");
    }
    if (!(key instanceof PyIntObject)) {
        throw this.runtime.newRaiseTypeError("tuple indices must be integers or slices, not " + key.getType().getFullName());
    }
    PyTupleObject tuple = (PyTupleObject) self;
    PyIntObject index = (PyIntObject) key;
    return tuple.get(index);
}
Also used : PyTupleObject(org.cafebabepy.runtime.object.java.PyTupleObject) 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 PyTupleObject (org.cafebabepy.runtime.object.java.PyTupleObject)1