@ExposedMethod(doc = BuiltinDocs.list_extend_doc) final synchronized void list_extend(PyObject o) { if (o instanceof PyList) { list.addAll(((PyList) o).list); } else { for (PyObject item : o.asIterable()) { list.add(item); } } gListAllocatedStatus = __len__(); }
@Override protected void setslice(int start, int stop, int step, PyObject value) { if (stop < start) { stop = start; } if (value instanceof PyList) { if (value == this) { // copy value = new PyList((PySequence) value); } setslicePyList(start, stop, step, (PyList) value); } else if (value instanceof PySequence) { setsliceIterator(start, stop, step, value.asIterable().iterator()); } else if (value != null && !(value instanceof List)) { value = new PyList(value); setsliceIterator(start, stop, step, value.asIterable().iterator()); } else { List valueList = (List) value.__tojava__(List.class); if (valueList != null && valueList != Py.NoConversion) { setsliceList(start, stop, step, valueList); } } }
@ExposedNew @ExposedMethod(doc = BuiltinDocs.list___init___doc) final void list___init__(PyObject[] args, String[] kwds) { ArgParser ap = new ArgParser("list", args, kwds, new String[] {"sequence"}, 0); PyObject seq = ap.getPyObject(0, null); clear(); if (seq == null) { return; } if (seq instanceof PyList) { list.addAll(((PyList) seq).list); // don't convert } else if (seq instanceof PyTuple) { list.addAll(((PyTuple) seq).getList()); } else { for (PyObject item : seq.asIterable()) { append(item); } } }
public PyList(PyObject o) { this(TYPE); for (PyObject item : o.asIterable()) { list.add(item); } }