Skip to content

Commit

Permalink
Merge pull request #2685 from alex/type-error
Browse files Browse the repository at this point in the history
Use a TypeError, rather than a ValueError, when refusing to treat a str as a Vec
  • Loading branch information
davidhewitt committed Nov 9, 2022
2 parents 6746ff8 + f7a487b commit 4b7e0ee
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions newsfragments/2685.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use a TypeError, rather than a ValueError, when refusing to treat a str as a Vec
2 changes: 1 addition & 1 deletion pytests/tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_vec_from_bytes():


def test_vec_from_str():
with pytest.raises(ValueError):
with pytest.raises(TypeError):
sequence.vec_to_vec_pystring("123")


Expand Down
4 changes: 2 additions & 2 deletions src/types/sequence.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -285,7 +285,7 @@ where
{
fn extract(obj: &'a PyAny) -> PyResult<Self> {
if let Ok(true) = obj.is_instance_of::<PyString>() {
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)
}
Expand Down

0 comments on commit 4b7e0ee

Please sign in to comment.