Skip to content

Commit 37b7e8c

Browse files
committed
chore(python): Update PyO3 to 0.21.0
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent cc55213 commit 37b7e8c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

bindings/python/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Changed
1010

1111
- Update `html5ever` to `0.27`.
12+
- Update `PyO3` to `0.21.0`.
1213

1314
## [0.13.0] - 2024-01-19
1415

bindings/python/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ crate-type = ["cdylib"]
1414
built = { version = "0.7.1", features = ["cargo-lock", "chrono"] }
1515

1616
[dependencies]
17-
pyo3 = { version = "0.20.0", features = ["extension-module", "abi3-py37"] }
17+
pyo3 = { version = "0.21.0", features = ["extension-module", "abi3-py37"] }
1818
pyo3-built = "0.4"
1919
rayon = "1"
2020
url = "2"

bindings/python/src/lib.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct StylesheetCache {
8484
impl StylesheetCache {
8585
#[new]
8686
#[pyo3(text_signature = "(size=8)")]
87-
fn new(size: Option<&PyAny>) -> PyResult<Self> {
87+
fn new(size: Option<&Bound<'_, PyAny>>) -> PyResult<Self> {
8888
let size = if let Some(size) = size {
8989
const ERROR_MESSAGE: &str = "Cache size must be an integer greater than zero";
9090
let size = size
@@ -173,7 +173,7 @@ impl CSSInliner {
173173
///
174174
/// Inline CSS in multiple HTML documents
175175
#[pyo3(text_signature = "(htmls)")]
176-
fn inline_many(&self, htmls: &PyList) -> PyResult<Vec<String>> {
176+
fn inline_many(&self, htmls: &Bound<'_, PyList>) -> PyResult<Vec<String>> {
177177
inline_many_impl(&self.inner, htmls)
178178
}
179179
}
@@ -219,7 +219,7 @@ fn inline(
219219
)]
220220
#[allow(clippy::too_many_arguments)]
221221
fn inline_many(
222-
htmls: &PyList,
222+
htmls: &Bound<'_, PyList>,
223223
inline_style_tags: Option<bool>,
224224
keep_style_tags: Option<bool>,
225225
keep_link_tags: Option<bool>,
@@ -244,10 +244,10 @@ fn inline_many(
244244

245245
fn inline_many_impl(
246246
inliner: &rust_inline::CSSInliner<'_>,
247-
htmls: &PyList,
247+
htmls: &Bound<'_, PyList>,
248248
) -> PyResult<Vec<String>> {
249249
// Extract strings from the list. It will fail if there is any non-string value
250-
let extracted: Result<Vec<_>, _> = htmls.iter().map(pyo3::PyAny::extract::<&str>).collect();
250+
let extracted: Result<Vec<_>, _> = htmls.iter().map(|h| h.extract::<String>()).collect();
251251
let output: Result<Vec<_>, _> = extracted?
252252
.par_iter()
253253
.map(|html| inliner.inline(html))
@@ -262,14 +262,15 @@ mod build {
262262

263263
/// Fast CSS inlining written in Rust
264264
#[pymodule]
265-
fn css_inline(py: Python<'_>, module: &PyModule) -> PyResult<()> {
265+
fn css_inline(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> {
266266
module.add_class::<CSSInliner>()?;
267267
module.add_class::<StylesheetCache>()?;
268268
module.add_wrapped(wrap_pyfunction!(inline))?;
269269
module.add_wrapped(wrap_pyfunction!(inline_many))?;
270-
let inline_error = py.get_type::<InlineError>();
270+
let inline_error = py.get_type_bound::<InlineError>();
271271
inline_error.setattr("__doc__", INLINE_ERROR_DOCSTRING)?;
272272
module.add("InlineError", inline_error)?;
273+
#[allow(deprecated)]
273274
module.add("__build__", pyo3_built::pyo3_built!(py, build))?;
274275
Ok(())
275276
}

0 commit comments

Comments
 (0)