Skip to content

Commit b9965b5

Browse files
committed
refactor: update pyo3 to v0.21
1 parent 4237f1a commit b9965b5

File tree

4 files changed

+65
-101
lines changed

4 files changed

+65
-101
lines changed

Cargo.lock

Lines changed: 60 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "djc_core_html_parser"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.19.0", features = ["extension-module"] }
12+
pyo3 = { version = "0.21.0", features = ["extension-module"] }
1313
quick-xml = "0.37.2"
1414

1515
# https://ohadravid.github.io/posts/2023-03-rusty-python

src/html_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn set_html_attributes(
4848
all_attributes: Vec<String>,
4949
check_end_names: Option<bool>,
5050
watch_on_attribute: Option<String>,
51-
) -> PyResult<PyObject> {
51+
) -> PyResult<Py<PyAny>> {
5252
let config = HtmlTransformerConfig::new(
5353
root_attributes,
5454
all_attributes,
@@ -59,12 +59,12 @@ pub fn set_html_attributes(
5959
match transform(&config, html) {
6060
Ok((html, captured)) => {
6161
// Convert captured attributes to a Python dictionary
62-
let captured_dict = PyDict::new(py);
62+
let captured_dict = PyDict::new_bound(py);
6363
for (id, attrs) in captured {
6464
captured_dict.set_item(id, attrs)?;
6565
}
6666

67-
let result = PyTuple::new(py, &[html.into_py(py), captured_dict.into_py(py)]);
67+
let result = PyTuple::new_bound(py, &[html.into_py(py), captured_dict.into_py(py)]);
6868
Ok(result.into())
6969
}
7070
Err(e) => Err(PyValueError::new_err(e.to_string())),

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use pyo3::prelude::*;
2-
use pyo3::types::PyModule;
32

43
mod html_parser;
54

65
/// A Python module implemented in Rust for high-performance HTML transformation.
76
#[pymodule]
8-
fn djc_core_html_parser(_py: Python, m: &PyModule) -> PyResult<()> {
7+
fn djc_core_html_parser(m: &Bound<'_, PyModule>) -> PyResult<()> {
98
m.add_function(wrap_pyfunction!(html_parser::set_html_attributes, m)?)?;
109
Ok(())
1110
}

0 commit comments

Comments
 (0)