Skip to content

Commit 38982e8

Browse files
committed
remove Input for PyAny
1 parent 1308fa0 commit 38982e8

23 files changed

+174
-806
lines changed

src/errors/location.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,17 @@ impl Serialize for Location {
193193
}
194194
}
195195

196-
impl TryFrom<Option<&PyAny>> for Location {
196+
impl TryFrom<Option<&Py2<'_, PyAny>>> for Location {
197197
type Error = PyErr;
198198

199199
/// Only ever called by ValidationError -> PyLineError to convert user input to our internal Location
200200
/// Thus this expects the location to *not* be reversed and reverses it before storing it.
201-
fn try_from(location: Option<&PyAny>) -> PyResult<Self> {
201+
fn try_from(location: Option<&Py2<'_, PyAny>>) -> PyResult<Self> {
202202
if let Some(location) = location {
203203
let mut loc_vec: Vec<LocItem> = if let Ok(tuple) = location.downcast::<PyTuple>() {
204-
tuple.iter().map(AsLocItem::as_loc_item).collect()
204+
tuple.iter().map(|any| any.as_loc_item()).collect()
205205
} else if let Ok(list) = location.downcast::<PyList>() {
206-
list.iter().map(AsLocItem::as_loc_item).collect()
206+
list.iter().map(|any| any.as_loc_item()).collect()
207207
} else {
208208
return Err(PyTypeError::new_err(
209209
"Location must be a list or tuple of strings and ints",

src/errors/validation_exception.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,17 @@ impl ValidationError {
237237
fn from_exception_data(
238238
py: Python,
239239
title: PyObject,
240-
line_errors: &PyList,
240+
line_errors: Py2<'_, PyList>,
241241
input_type: &str,
242242
hide_input: bool,
243243
) -> PyResult<Py<Self>> {
244244
Py::new(
245245
py,
246246
Self {
247-
line_errors: line_errors.iter().map(PyLineError::try_from).collect::<PyResult<_>>()?,
247+
line_errors: line_errors
248+
.iter()
249+
.map(|error| PyLineError::try_from(&error))
250+
.collect::<PyResult<_>>()?,
248251
title,
249252
input_type: InputType::try_from(input_type)?,
250253
hide_input,
@@ -433,11 +436,11 @@ impl From<PyLineError> for ValLineError {
433436
}
434437
}
435438

436-
impl TryFrom<&PyAny> for PyLineError {
439+
impl TryFrom<&Py2<'_, PyAny>> for PyLineError {
437440
type Error = PyErr;
438441

439-
fn try_from(value: &PyAny) -> PyResult<Self> {
440-
let dict: &PyDict = value.downcast()?;
442+
fn try_from(value: &Py2<'_, PyAny>) -> PyResult<Self> {
443+
let dict = value.downcast::<PyDict>()?;
441444
let py = value.py();
442445

443446
let type_raw = dict
@@ -455,7 +458,7 @@ impl TryFrom<&PyAny> for PyLineError {
455458
));
456459
};
457460

458-
let location = Location::try_from(dict.get_item("loc")?)?;
461+
let location = Location::try_from(dict.get_item("loc")?.as_ref())?;
459462

460463
let input_value = match dict.get_item("input")? {
461464
Some(i) => i.into_py(py),

0 commit comments

Comments
 (0)