() {
Ok(PySequenceIterable::FrozenSet(iterable))
} else {
// Try to get this as a generable iterable thing, but exclude string and mapping types
@@ -930,7 +930,7 @@ fn extract_sequence_iterable<'a, 'py>(obj: &'a Bound<'py, PyAny>) -> ValResult()
|| obj.is_instance_of::()
|| obj.is_instance_of::()
- || obj.downcast::().is_ok())
+ || obj.cast::().is_ok())
{
if let Ok(iter) = obj.try_iter() {
return Ok(PySequenceIterable::Iterator(iter));
diff --git a/src/input/input_string.rs b/src/input/input_string.rs
index a635188a8..38878a256 100644
--- a/src/input/input_string.rs
+++ b/src/input/input_string.rs
@@ -30,7 +30,7 @@ pub enum StringMapping<'py> {
impl<'py> StringMapping<'py> {
pub fn new_key(py_key: Bound<'py, PyAny>) -> ValResult {
- match py_key.downcast_into::() {
+ match py_key.cast_into::() {
Ok(value) => Ok(Self::String(value)),
Err(downcast_error) => Err(ValError::new(
ErrorTypeDefaults::StringType,
@@ -40,9 +40,9 @@ impl<'py> StringMapping<'py> {
}
pub fn new_value(py_value: Bound<'py, PyAny>) -> ValResult {
- match py_value.downcast_into::() {
+ match py_value.cast_into::() {
Ok(py_str) => Ok(Self::String(py_str)),
- Err(downcast_error) => match downcast_error.into_inner().downcast_into::() {
+ Err(downcast_error) => match downcast_error.into_inner().cast_into::() {
Ok(value) => Ok(Self::Mapping(value)),
Err(downcast_error) => Err(ValError::new(
ErrorTypeDefaults::StringType,
diff --git a/src/input/return_enums.rs b/src/input/return_enums.rs
index 526d2c970..40ed25d16 100644
--- a/src/input/return_enums.rs
+++ b/src/input/return_enums.rs
@@ -334,7 +334,7 @@ pub(crate) fn iterate_attributes<'a, 'py>(
// or we get to the end of the list of attributes
let name = attributes_iterator.next()?;
// from benchmarks this is 14x faster than using the python `startswith` method
- let name_cow = match name.downcast::() {
+ let name_cow = match name.cast::() {
Ok(name) => name.to_string_lossy(),
Err(e) => return Some(Err(e.into())),
};
@@ -706,9 +706,11 @@ impl Rem for &Int {
}
}
-impl FromPyObject<'_> for Int {
- fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult {
- match extract_int(obj) {
+impl FromPyObject<'_, '_> for Int {
+ type Error = PyErr;
+
+ fn extract(obj: Borrowed<'_, '_, PyAny>) -> PyResult {
+ match extract_int(&obj) {
Some(i) => Ok(i),
None => py_err!(PyTypeError; "Expected int, got {}", obj.get_type()),
}
diff --git a/src/lookup_key.rs b/src/lookup_key.rs
index 7fe5d61e9..79356ea43 100644
--- a/src/lookup_key.rs
+++ b/src/lookup_key.rs
@@ -47,7 +47,7 @@ impl fmt::Display for LookupKey {
impl LookupKey {
pub fn from_py(py: Python, value: &Bound<'_, PyAny>, alt_alias: Option<&str>) -> PyResult {
- if let Ok(alias_py) = value.downcast::() {
+ if let Ok(alias_py) = value.cast::() {
let alias: String = alias_py.extract()?;
let path1 = LookupPath::from_str(py, &alias, Some(alias_py.clone()));
match alt_alias {
@@ -58,11 +58,11 @@ impl LookupKey {
None => Ok(Self::Simple(path1)),
}
} else {
- let list = value.downcast::()?;
+ let list = value.cast::()?;
let Ok(first) = list.get_item(0) else {
return py_schema_err!("Lookup paths should have at least one element");
};
- let mut locs: Vec = if first.downcast::().is_ok() {
+ let mut locs: Vec = if first.cast::().is_ok() {
// list of strings rather than list of lists
vec![LookupPath::from_list(list)?]
} else {
@@ -385,13 +385,13 @@ impl LookupPath {
}
fn from_list(obj: &Bound<'_, PyAny>) -> PyResult {
- let mut iter = obj.downcast::()?.iter();
+ let mut iter = obj.cast::()?.iter();
let Some(first_item) = iter.next() else {
return py_schema_err!("Each alias path should have at least one element");
};
- let Ok(first_item_py_str) = first_item.downcast_into::() else {
+ let Ok(first_item_py_str) = first_item.cast_into::() else {
return py_err!(PyTypeError; "The first item in an alias path should be a string");
};
@@ -485,7 +485,7 @@ impl<'a, 'py> IntoPyObject<'py> for &'a PathItemString {
impl PathItem {
pub fn from_py(obj: Bound<'_, PyAny>) -> PyResult {
- let obj = match obj.downcast_into::() {
+ let obj = match obj.cast_into::() {
Ok(py_str_key) => {
let str_key = py_str_key.to_str()?.to_string();
return Ok(Self::S(PathItemString {
@@ -507,7 +507,7 @@ impl PathItem {
pub fn py_get_item<'py>(&self, py_any: &Bound<'py, PyAny>) -> Option> {
// we definitely don't want to index strings, so explicitly omit this case
- if py_any.downcast::().is_ok() {
+ if py_any.cast::().is_ok() {
None
} else {
// otherwise, blindly try getitem on v since no better logic is realistic
@@ -560,7 +560,7 @@ impl PathItem {
impl PathItemString {
fn py_get_attrs<'py>(&self, obj: &Bound<'py, PyAny>) -> PyResult