Skip to content

Commit 0a1306a

Browse files
committed
move over final few _bound functions
1 parent df5ec3f commit 0a1306a

File tree

16 files changed

+35
-35
lines changed

16 files changed

+35
-35
lines changed

src/build_tools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl SchemaError {
9090
ValidationError::new(line_errors, "Schema".to_object(py), InputType::Python, false);
9191
let schema_error = SchemaError(SchemaErrorEnum::ValidationError(validation_error));
9292
match Py::new(py, schema_error) {
93-
Ok(err) => PyErr::from_value_bound(err.into_bound(py).into_any()),
93+
Ok(err) => PyErr::from_value(err.into_bound(py).into_any()),
9494
Err(err) => err,
9595
}
9696
}

src/errors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub use self::validation_exception::ValidationError;
1313
pub use self::value_exception::{PydanticCustomError, PydanticKnownError, PydanticOmit, PydanticUseDefault};
1414

1515
pub fn py_err_string(py: Python, err: PyErr) -> String {
16-
let value = err.value_bound(py);
16+
let value = err.value(py);
1717
match value.get_type().qualname() {
1818
Ok(type_name) => match value.str() {
1919
Ok(py_str) => {

src/errors/validation_exception.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::{Display, Write};
33
use std::str::from_utf8;
44

55
use pyo3::exceptions::{PyKeyError, PyTypeError, PyValueError};
6-
use pyo3::ffi;
6+
use pyo3::ffi::{self, c_str};
77
use pyo3::intern;
88
use pyo3::prelude::*;
99
use pyo3::sync::GILOnceCell;
@@ -73,7 +73,7 @@ impl ValidationError {
7373
return cause_problem;
7474
}
7575
}
76-
PyErr::from_value_bound(err.into_bound(py).into_any())
76+
PyErr::from_value(err.into_bound(py).into_any())
7777
}
7878
Err(err) => err,
7979
}
@@ -145,7 +145,7 @@ impl ValidationError {
145145
use pyo3::exceptions::PyUserWarning;
146146

147147
let wrapped = PyUserWarning::new_err((note,));
148-
wrapped.set_cause(py, Some(PyErr::from_value_bound(err.clone_ref(py).into_bound(py))));
148+
wrapped.set_cause(py, Some(PyErr::from_value(err.clone_ref(py).into_bound(py))));
149149
user_py_errs.push(wrapped);
150150
}
151151
}
@@ -202,10 +202,10 @@ fn include_url_env(py: Python) -> bool {
202202
match std::env::var_os("PYDANTIC_ERRORS_OMIT_URL") {
203203
Some(val) => {
204204
// We don't care whether warning succeeded or not, hence the assignment
205-
let _ = PyErr::warn_bound(
205+
let _ = PyErr::warn(
206206
py,
207-
&py.get_type_bound::<pyo3::exceptions::PyDeprecationWarning>(),
208-
"PYDANTIC_ERRORS_OMIT_URL is deprecated, use PYDANTIC_ERRORS_INCLUDE_URL instead",
207+
&py.get_type::<pyo3::exceptions::PyDeprecationWarning>(),
208+
c_str!("PYDANTIC_ERRORS_OMIT_URL is deprecated, use PYDANTIC_ERRORS_INCLUDE_URL instead"),
209209
1,
210210
);
211211
// If OMIT_URL exists but is empty, we include the URL:

src/input/input_python.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
8787
Some(self)
8888
}
8989

90-
fn as_kwargs(&self, py: Python<'py>) -> Option<Bound<'py, PyDict>> {
91-
self.downcast::<PyDict>()
92-
.ok()
93-
.map(|dict| dict.to_owned().unbind().into_bound(py))
90+
fn as_kwargs(&self, _py: Python<'py>) -> Option<Bound<'py, PyDict>> {
91+
self.downcast::<PyDict>().ok().map(Bound::to_owned)
9492
}
9593

9694
type Arguments<'a>
@@ -620,7 +618,7 @@ impl<'py> Input<'py> for Bound<'py, PyAny> {
620618
if strict {
621619
return Err(ValError::new(
622620
ErrorType::IsInstanceOf {
623-
class: PyComplex::type_object_bound(py)
621+
class: PyComplex::type_object(py)
624622
.qualname()
625623
.and_then(|name| name.extract())
626624
.unwrap_or_else(|_| "complex".to_owned()),

src/input/return_enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ pub enum EitherComplex<'a> {
755755
impl IntoPy<PyObject> for EitherComplex<'_> {
756756
fn into_py(self, py: Python<'_>) -> PyObject {
757757
match self {
758-
Self::Complex(c) => PyComplex::from_doubles_bound(py, c[0], c[1]).into_py(py),
758+
Self::Complex(c) => PyComplex::from_doubles(py, c[0], c[1]).into_py(py),
759759
Self::Py(c) => c.into_py(py),
760760
}
761761
}

src/lookup_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ fn py_get_attrs<'py>(obj: &Bound<'py, PyAny>, attr_name: &Py<PyString>) -> PyRes
511511
match obj.getattr(attr_name) {
512512
Ok(attr) => Ok(Some(attr)),
513513
Err(err) => {
514-
if err.get_type_bound(obj.py()).is_subclass_of::<PyAttributeError>()? {
514+
if err.get_type(obj.py()).is_subclass_of::<PyAttributeError>()? {
515515
Ok(None)
516516
} else {
517517
Err(err)

src/serializers/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ impl BytesMode {
189189
}
190190

191191
pub fn utf8_py_error(py: Python, err: Utf8Error, data: &[u8]) -> PyErr {
192-
match pyo3::exceptions::PyUnicodeDecodeError::new_utf8_bound(py, data, err) {
193-
Ok(decode_err) => PyErr::from_value_bound(decode_err.into_any()),
192+
match pyo3::exceptions::PyUnicodeDecodeError::new_utf8(py, data, err) {
193+
Ok(decode_err) => PyErr::from_value(decode_err.into_any()),
194194
Err(err) => err,
195195
}
196196
}

src/serializers/extra.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::CString;
12
use std::fmt;
23
use std::sync::Mutex;
34

@@ -472,7 +473,7 @@ impl CollectWarnings {
472473
let message = format!("Pydantic serializer warnings:\n {}", warnings.join("\n "));
473474
if self.mode == WarningsMode::Warn {
474475
let user_warning_type = PyUserWarning::type_object(py);
475-
PyErr::warn_bound(py, &user_warning_type, &message, 0)
476+
PyErr::warn(py, &user_warning_type, &CString::new(message)?, 0)
476477
} else {
477478
Err(PydanticSerializationError::new_err(message))
478479
}

src/serializers/type_serializers/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl FunctionPlainSerializer {
189189
}
190190

191191
fn on_error(py: Python, err: PyErr, function_name: &str, extra: &Extra) -> PyResult<()> {
192-
let exception = err.value_bound(py);
192+
let exception = err.value(py);
193193
if let Ok(ser_err) = exception.extract::<PydanticSerializationUnexpectedValue>() {
194194
if extra.check.enabled() {
195195
Err(err)

src/validators/call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ impl Validator for CallValidator {
8484
let args = self.arguments_validator.validate(py, input, state)?.into_bound(py);
8585

8686
let return_value = if let Ok((args, kwargs)) = args.extract::<(Bound<PyTuple>, Bound<PyDict>)>() {
87-
self.function.call_bound(py, args, Some(&kwargs))?
87+
self.function.call(py, args, Some(&kwargs))?
8888
} else if let Ok(kwargs) = args.downcast::<PyDict>() {
89-
self.function.call_bound(py, (), Some(kwargs))?
89+
self.function.call(py, (), Some(kwargs))?
9090
} else {
9191
let msg = "Arguments validator should return a tuple of (args, kwargs) or a dict of kwargs";
9292
return Err(PyTypeError::new_err(msg).into());

0 commit comments

Comments
 (0)