Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rust-version = "1.75"
[dependencies]
# TODO it would be very nice to remove the "py-clone" feature as it can panic,
# but needs a bit of work to make sure it's not used in the codebase
pyo3 = { version = "0.26", features = ["generate-import-lib", "num-bigint", "py-clone"] }
pyo3 = { version = "0.27", features = ["generate-import-lib", "num-bigint", "py-clone"] }
regex = "1.11.3"
strum = { version = "0.27", features = ["derive"] }
strum_macros = "0.27"
Expand Down Expand Up @@ -69,12 +69,12 @@ debug = true
strip = false

[dev-dependencies]
pyo3 = { version = "0.26", features = ["auto-initialize"] }
pyo3 = { version = "0.27", features = ["auto-initialize"] }

[build-dependencies]
version_check = "0.9.5"
# used where logic has to be version/distribution specific, e.g. pypy
pyo3-build-config = { version = "0.26" }
pyo3-build-config = { version = "0.27" }

[lints.clippy]
dbg_macro = "warn"
Expand Down Expand Up @@ -105,3 +105,8 @@ too_many_lines = "allow"
unnecessary_wraps = "allow"
unused_self = "allow"
used_underscore_binding = "allow"

[patch.crates-io]
pyo3 = { git = "https://github.com/pyo3/pyo3.git", branch = "release-0.27.0" }
pyo3-build-config = { git = "https://github.com/pyo3/pyo3.git", branch = "release-0.27.0" }
jiter = { git = "https://github.com/pydantic/jiter.git", branch = "dh/pyo3-0.27" }
6 changes: 3 additions & 3 deletions src/build_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::OnceLock;
use pyo3::exceptions::PyException;
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyList, PyString};
use pyo3::{intern, FromPyObject, PyErrArguments};
use pyo3::{intern, PyErrArguments};

use crate::errors::{PyLineError, ValError};
use crate::input::InputType;
Expand All @@ -21,7 +21,7 @@ pub fn schema_or_config<'py, T>(
config_key: &Bound<'py, PyString>,
) -> PyResult<Option<T>>
where
T: FromPyObject<'py>,
T: FromPyObjectOwned<'py>,
{
match schema.get_as(schema_key)? {
Some(v) => Ok(Some(v)),
Expand All @@ -38,7 +38,7 @@ pub fn schema_or_config_same<'py, T>(
key: &Bound<'py, PyString>,
) -> PyResult<Option<T>>
where
T: FromPyObject<'py>,
T: FromPyObjectOwned<'py>,
{
schema_or_config(schema, config, key, key)
}
Expand Down
16 changes: 8 additions & 8 deletions src/errors/line_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::convert::Infallible;

use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use pyo3::DowncastError;
use pyo3::DowncastIntoError;
use pyo3::CastError;
use pyo3::CastIntoError;

use jiter::JsonValue;

Expand Down Expand Up @@ -45,15 +45,15 @@ impl From<PyErr> for ValError {
}
}

impl From<DowncastError<'_, '_>> for ValError {
fn from(py_downcast: DowncastError) -> Self {
Self::InternalErr(PyTypeError::new_err(py_downcast.to_string()))
impl From<CastError<'_, '_>> for ValError {
fn from(py_cast: CastError) -> Self {
Self::InternalErr(PyTypeError::new_err(py_cast.to_string()))
}
}

impl From<DowncastIntoError<'_>> for ValError {
fn from(py_downcast: DowncastIntoError) -> Self {
Self::InternalErr(PyTypeError::new_err(py_downcast.to_string()))
impl From<CastIntoError<'_>> for ValError {
fn from(py_cast: CastIntoError) -> Self {
Self::InternalErr(PyTypeError::new_err(py_cast.to_string()))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/errors/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ impl TryFrom<Option<&Bound<'_, PyAny>>> for Location {
/// Thus this expects the location to *not* be reversed and reverses it before storing it.
fn try_from(location: Option<&Bound<'_, PyAny>>) -> PyResult<Self> {
if let Some(location) = location {
let mut loc_vec: Vec<LocItem> = if let Ok(tuple) = location.downcast::<PyTuple>() {
let mut loc_vec: Vec<LocItem> = if let Ok(tuple) = location.cast::<PyTuple>() {
tuple.iter().map(Into::into).collect()
} else if let Ok(list) = location.downcast::<PyList>() {
} else if let Ok(list) = location.cast::<PyList>() {
list.iter().map(Into::into).collect()
} else {
return Err(PyTypeError::new_err(
Expand Down
14 changes: 8 additions & 6 deletions src/errors/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn list_all_errors(py: Python<'_>) -> PyResult<Bound<'_, PyList>> {
PyList::new(py, errors)
}

fn field_from_context<'py, T: FromPyObject<'py>>(
fn field_from_context<'py, T: FromPyObjectOwned<'py>>(
context: Option<&Bound<'py, PyDict>>,
field_name: &str,
enum_name: &str,
Expand All @@ -56,7 +56,7 @@ fn field_from_context<'py, T: FromPyObject<'py>>(
.map_err(|_| py_error_type!(PyTypeError; "{}: '{}' context value must be a {}", enum_name, field_name, type_name_fn()))
}

fn cow_field_from_context<'py, T: FromPyObject<'py>, B: ToOwned<Owned = T> + ?Sized + 'static>(
fn cow_field_from_context<'py, T: FromPyObjectOwned<'py>, B: ToOwned<Owned = T> + ?Sized + 'static>(
context: Option<&Bound<'py, PyDict>>,
field_name: &str,
enum_name: &str,
Expand Down Expand Up @@ -127,7 +127,7 @@ macro_rules! error_types {
dict.set_item(stringify!($key), $key)?;
)*
if let Some(ctx) = context {
dict.update(ctx.bind(py).downcast::<PyMapping>()?)?;
dict.update(ctx.bind(py).cast::<PyMapping>()?)?;
Ok(true)
} else {
Ok(false)
Expand Down Expand Up @@ -809,9 +809,11 @@ impl From<Int> for Number {
}
}

impl FromPyObject<'_> for Number {
fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult<Self> {
if let Some(int) = extract_i64(obj) {
impl FromPyObject<'_, '_> for Number {
type Error = PyErr;

fn extract(obj: Borrowed<'_, '_, PyAny>) -> PyResult<Self> {
if let Some(int) = extract_i64(&obj) {
Ok(Number::Int(int))
} else if let Ok(float) = obj.extract::<f64>() {
Ok(Number::Float(float))
Expand Down
4 changes: 2 additions & 2 deletions src/errors/validation_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,14 @@ impl TryFrom<&Bound<'_, PyAny>> for PyLineError {
type Error = PyErr;

fn try_from(value: &Bound<'_, PyAny>) -> PyResult<Self> {
let dict = value.downcast::<PyDict>()?;
let dict = value.cast::<PyDict>()?;
let py = value.py();

let type_raw = dict
.get_item(intern!(py, "type"))?
.ok_or_else(|| PyKeyError::new_err("type"))?;

let error_type = if let Ok(type_str) = type_raw.downcast::<PyString>() {
let error_type = if let Ok(type_str) = type_raw.cast::<PyString>() {
let context: Option<Bound<'_, PyDict>> = dict.get_as(intern!(py, "ctx"))?;
ErrorType::new(py, type_str.to_str()?, context)?
} else if let Ok(custom_error) = type_raw.extract::<PydanticCustomError>() {
Expand Down
4 changes: 2 additions & 2 deletions src/errors/value_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl PydanticCustomError {
let mut message = message_template.to_string();
if let Some(ctx) = context {
for (key, value) in ctx.iter() {
let key = key.downcast::<PyString>()?;
if let Ok(py_str) = value.downcast::<PyString>() {
let key = key.cast::<PyString>()?;
if let Ok(py_str) = value.cast::<PyString>() {
message = message.replace(&format!("{{{}}}", key.to_str()?), py_str.to_str()?);
} else if let Some(value_int) = extract_i64(&value) {
message = message.replace(&format!("{{{}}}", key.to_str()?), &value_int.to_string());
Expand Down
6 changes: 3 additions & 3 deletions src/input/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ impl<'py> TryFrom<&'_ Bound<'py, PyAny>> for EitherTimedelta<'py> {
type Error = PyErr;

fn try_from(value: &Bound<'py, PyAny>) -> PyResult<Self> {
if let Ok(dt) = value.downcast_exact() {
if let Ok(dt) = value.cast_exact() {
Ok(EitherTimedelta::PyExact(dt.clone()))
} else {
let dt = value.downcast()?;
let dt = value.cast()?;
Ok(EitherTimedelta::PySubclass(dt.clone()))
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ fn time_as_tzinfo<'py>(py: Python<'py>, time: &Time) -> PyResult<Option<Bound<'p
match time.tz_offset {
Some(offset) => {
let tz_info: TzInfo = offset.try_into()?;
Ok(Some(Bound::new(py, tz_info)?.into_any().downcast_into()?))
Ok(Some(Bound::new(py, tz_info)?.into_any().cast_into()?))
}
None => Ok(None),
}
Expand Down
Loading
Loading