diff --git a/newsfragments/2685.changed.md b/newsfragments/2685.changed.md new file mode 100644 index 00000000000..8e498fe167b --- /dev/null +++ b/newsfragments/2685.changed.md @@ -0,0 +1 @@ +Use a TypeError, rather than a ValueError, when refusing to treat a str as a Vec diff --git a/src/types/sequence.rs b/src/types/sequence.rs index 422a2db2e10..9fa4010c732 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -1,6 +1,6 @@ // Copyright (c) 2017-present PyO3 Project and Contributors use crate::err::{self, PyDowncastError, PyErr, PyResult}; -use crate::exceptions::PyValueError; +use crate::exceptions::PyTypeError; use crate::inspect::types::TypeInfo; use crate::internal_tricks::get_ssize_index; use crate::once_cell::GILOnceCell; @@ -285,7 +285,7 @@ where { 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`")); + return Err(PyTypeError::new_err("Can't extract `str` to `Vec`")); } extract_sequence(obj) }