diff --git a/pytests/tests/test_sequence.py b/pytests/tests/test_sequence.py index d0328146922..dc44a50defc 100644 --- a/pytests/tests/test_sequence.py +++ b/pytests/tests/test_sequence.py @@ -17,8 +17,7 @@ def test_vec_from_bytes(): def test_vec_from_str(): - with pytest.raises(ValueError): - sequence.vec_to_vec_pystring("123") + assert sequence.vec_to_vec_pystring("123") == ["1", "2", "3"] @pytest.mark.skipif( diff --git a/src/types/sequence.rs b/src/types/sequence.rs index 6d6421569a4..a7ed74b246c 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -1,11 +1,10 @@ // Copyright (c) 2017-present PyO3 Project and Contributors use crate::err::{self, PyDowncastError, PyErr, PyResult}; -use crate::exceptions::PyValueError; use crate::inspect::types::TypeInfo; use crate::internal_tricks::get_ssize_index; use crate::once_cell::GILOnceCell; use crate::type_object::PyTypeInfo; -use crate::types::{PyAny, PyList, PyString, PyTuple, PyType}; +use crate::types::{PyAny, PyList, PyTuple, PyType}; use crate::{ffi, PyNativeType, ToPyObject}; use crate::{AsPyPointer, IntoPy, IntoPyPointer, Py, Python}; use crate::{FromPyObject, PyTryFrom}; @@ -284,9 +283,6 @@ where T: FromPyObject<'a>, { fn extract(obj: &'a PyAny) -> PyResult { - if let Ok(true) = obj.is_instance_of::() { - return Err(PyValueError::new_err("Can't extract `str` to `Vec`")); - } extract_sequence(obj) } @@ -405,14 +401,23 @@ mod tests { } #[test] - fn test_strings_cannot_be_extracted_to_vec() { + fn test_strings_can_be_extracted_to_vec() { Python::with_gil(|py| { let v = "London Calling"; let ob = v.to_object(py); - assert!(ob.extract::>(py).is_err()); - assert!(ob.extract::>(py).is_err()); - assert!(ob.extract::>(py).is_err()); + assert_eq!( + ob.extract::>(py).unwrap(), + ["L", "o", "n", "d", "o", "n", " ", "C", "a", "l", "l", "i", "n", "g"] + ); + assert_eq!( + ob.extract::>(py).unwrap(), + ["L", "o", "n", "d", "o", "n", " ", "C", "a", "l", "l", "i", "n", "g"] + ); + assert_eq!( + ob.extract::>(py).unwrap(), + ['L', 'o', 'n', 'd', 'o', 'n', ' ', 'C', 'a', 'l', 'l', 'i', 'n', 'g'] + ); }); }