Skip to content
Merged
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
27 changes: 10 additions & 17 deletions rust/Cargo.lock

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

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ strip = true
overflow-checks = false

[dependencies]
pyo3 = { version = "0.24", features = ["extension-module", "generate-import-lib"] }
pyo3 = { version = "0.25", features = ["extension-module", "generate-import-lib"] }

[features]
extension-module = ["pyo3/extension-module"]
20 changes: 9 additions & 11 deletions rust/src/python/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ use pyo3::prelude::*;
use pyo3::types::PyDate;
use pyo3::types::PyDateTime;
use pyo3::types::PyTime;
use pyo3::IntoPyObjectExt;

use crate::parsing::Parser;
use crate::python::types::{Duration, FixedTimezone};

// TODO: pyO3 v0.23 deprecates `ToPyObject`, function below must be migrated as per
// https://pyo3.rs/v0.23.0/migration
#[allow(deprecated)]
#[pyfunction]
pub fn parse_iso8601(py: Python, input: &str) -> PyResult<PyObject> {
let parsed = Parser::new(input).parse();
Expand All @@ -31,12 +29,12 @@ pub fn parse_iso8601(py: Python, input: &str) -> PyResult<PyObject> {
datetime.microsecond,
Some(
Py::new(py, FixedTimezone::new(offset, datetime.tzname))?
.to_object(py)
.into_any()
.downcast_bound(py)?,
),
)?;

Ok(dt.to_object(py))
Ok(dt.into_any().unbind())
}
None => {
let dt = PyDateTime::new(
Expand All @@ -51,7 +49,7 @@ pub fn parse_iso8601(py: Python, input: &str) -> PyResult<PyObject> {
None,
)?;

Ok(dt.to_object(py))
Ok(dt.into_any().unbind())
}
},
(true, false) => {
Expand All @@ -62,7 +60,7 @@ pub fn parse_iso8601(py: Python, input: &str) -> PyResult<PyObject> {
datetime.day as u8,
)?;

Ok(dt.to_object(py))
Ok(dt.into_any().unbind())
}
(false, true) => match datetime.offset {
Some(offset) => {
Expand All @@ -74,12 +72,12 @@ pub fn parse_iso8601(py: Python, input: &str) -> PyResult<PyObject> {
datetime.microsecond,
Some(
Py::new(py, FixedTimezone::new(offset, datetime.tzname))?
.to_object(py)
.into_any()
.downcast_bound(py)?,
),
)?;

Ok(dt.to_object(py))
Ok(dt.into_any().unbind())
}
None => {
let dt = PyTime::new(
Expand All @@ -91,7 +89,7 @@ pub fn parse_iso8601(py: Python, input: &str) -> PyResult<PyObject> {
None,
)?;

Ok(dt.to_object(py))
Ok(dt.into_any().unbind())
}
},
(_, _) => Err(exceptions::PyValueError::new_err(
Expand All @@ -111,7 +109,7 @@ pub fn parse_iso8601(py: Python, input: &str) -> PyResult<PyObject> {
Some(duration.microseconds),
),
)?
.to_object(py)),
.into_py_any(py)?),
(_, _, _) => Err(exceptions::PyValueError::new_err(
"Not yet implemented".to_string(),
)),
Expand Down
Loading