Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to pyo3 0.21.2 #78

Merged
merged 2 commits into from
Jun 24, 2024
Merged

upgrade to pyo3 0.21.2 #78

merged 2 commits into from
Jun 24, 2024

Conversation

samuelcolvin
Copy link
Owner

@davidhewitt, a quick review would be much appreciated.

Copy link

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me.

Generally these days I prefer change fn foo(py: Python, obj: Bound<...>) { to fn foo(obj: Bound<...>) { let py = obj.py(); ...

But that's not a deal breaker by any stretch of the imagination.

src/datetime.rs Outdated
Comment on lines 9 to 12
let py_dt: PyObject = match &datetime.date {
Some(date) => match &datetime.time {
Some(t) => {
let py_tz: PyObject;
let tzinfo = match &datetime.offset {
let tzinfo: Option<Bound<'_, PyTzInfo>> = match &datetime.offset {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistically I might have been tempted to do this with match (&datetime.date, &datetime.time, &datetime.offset)

src/datetime.rs Outdated
Some(offset) => {
let tz_info = match offset {
TomlOffset::Z => TzInfo::new(0, 0),
TomlOffset::Custom { hours, minutes } => TzInfo::new(*hours, *minutes),
};
py_tz = Py::new(py, tz_info)?.to_object(py);
Some(py_tz.extract(py)?)
Some(Bound::new(py, tz_info)?.into_any().downcast_into()?)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is one of the more painful part of the current design, I will probably add .cast_into() as a future replacement for .into_any().downcast_into(). PyO3/pyo3#3988 (comment)

src/datetime.rs Outdated Show resolved Hide resolved
src/datetime.rs Outdated Show resolved Hide resolved
src/py_type.rs Outdated Show resolved Hide resolved
@@ -9,30 +9,40 @@ use toml::value::Datetime;
use crate::py_type::PyTypeLookup;

pub struct SerializePyObject<'py> {
obj: &'py PyAny,
py: Python<'py>,
obj: Bound<'py, PyAny>,
none_value: Option<&'py str>,
ob_type_lookup: &'py PyTypeLookup,
}

impl<'py> SerializePyObject<'py> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be that you can rely on toml::value::Value implementing Deserialize and use pythonize::depythonize here. Not sure if you need some special logic.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need custom logic.

@samuelcolvin samuelcolvin merged commit dbeda14 into main Jun 24, 2024
10 checks passed
@samuelcolvin samuelcolvin deleted the newest-pyo3 branch June 24, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants