Merge pull request #2685 from alex/type-error
Use a TypeError, rather than a ValueError, when refusing to treat a str as a Vec
This commit is contained in:
commit
4b7e0ee5b4
|
@ -0,0 +1 @@
|
||||||
|
Use a TypeError, rather than a ValueError, when refusing to treat a str as a Vec
|
|
@ -17,7 +17,7 @@ def test_vec_from_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_vec_from_str():
|
def test_vec_from_str():
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(TypeError):
|
||||||
sequence.vec_to_vec_pystring("123")
|
sequence.vec_to_vec_pystring("123")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||||
use crate::err::{self, PyDowncastError, PyErr, PyResult};
|
use crate::err::{self, PyDowncastError, PyErr, PyResult};
|
||||||
use crate::exceptions::PyValueError;
|
use crate::exceptions::PyTypeError;
|
||||||
use crate::inspect::types::TypeInfo;
|
use crate::inspect::types::TypeInfo;
|
||||||
use crate::internal_tricks::get_ssize_index;
|
use crate::internal_tricks::get_ssize_index;
|
||||||
use crate::once_cell::GILOnceCell;
|
use crate::once_cell::GILOnceCell;
|
||||||
|
@ -285,7 +285,7 @@ where
|
||||||
{
|
{
|
||||||
fn extract(obj: &'a PyAny) -> PyResult<Self> {
|
fn extract(obj: &'a PyAny) -> PyResult<Self> {
|
||||||
if let Ok(true) = obj.is_instance_of::<PyString>() {
|
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)
|
extract_sequence(obj)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue