Python - IndexableString accepts tuples directly

This commit is contained in:
Anthony MOI
2020-01-10 00:32:30 -05:00
parent 1f16fcbe77
commit d46ea842c2

View File

@ -56,8 +56,18 @@ impl PyMappingProtocol for IndexableString {
} }
} else if let Ok(slice) = item.cast_as::<PySlice>(py) { } else if let Ok(slice) = item.cast_as::<PySlice>(py) {
Ok(slice) Ok(slice)
} else if let Ok(offset) = item.cast_as::<PyTuple>(py) {
if offset.len() == 2 {
let start = offset.get_item(0).extract::<isize>()?;
let end = offset.get_item(1).extract::<isize>()?;
Ok(PySlice::new(py, start, end, 1))
} else { } else {
Err(exceptions::TypeError::py_err("Expected number or slice")) Err(exceptions::TypeError::py_err("Expected Tuple[int, int]"))
}
} else {
Err(exceptions::TypeError::py_err(
"Expected number or slice or Tuple[int, int]",
))
}?; }?;
// Find out range from the slice // Find out range from the slice