From ec5d71e0b8791e7ea88e9d7a7d3b346946ee8044 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 14 Apr 2026 20:17:28 +0200 Subject: [PATCH 1/8] upgrade pyo to 0.18 - no relevant changes 0.16 -> 0.17 - two relevant changes in 0.17 -> 0.18 https://pyo3.rs/main/migration.html#from-017-to-018 - text signature is automatically generated - required arguments after Option<_> no longer inferred --- Cargo.lock | 136 ++++++++++++++++++++++------------------------------- Cargo.toml | 2 +- src/lib.rs | 33 ++++--------- 3 files changed, 67 insertions(+), 104 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 999805e46..e230e7eef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adblock" @@ -10,7 +10,7 @@ checksum = "27785ef5b89bc88fd2def3e1ecfefdf5ec1583795b916667afd15b13058f8315" dependencies = [ "addr", "base64", - "bitflags", + "bitflags 1.3.2", "flate2", "idna", "itertools", @@ -76,6 +76,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" + [[package]] name = "byteorder" version = "1.4.3" @@ -136,9 +142,9 @@ dependencies = [ [[package]] name = "indoc" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05a0bd019339e5d968b37855180087b7b9d512c5046fbd244cf8c95687927d6e" +checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" [[package]] name = "itertools" @@ -157,11 +163,10 @@ checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" dependencies = [ - "autocfg", "scopeguard", ] @@ -177,6 +182,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + [[package]] name = "miniz_oxide" version = "0.5.3" @@ -197,15 +211,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" dependencies = [ "lock_api", "parking_lot_core", @@ -213,15 +227,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-link", ] [[package]] @@ -238,9 +252,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] @@ -262,13 +276,14 @@ checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" [[package]] name = "pyo3" -version = "0.16.5" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6302e85060011447471887705bb7838f14aba43fcb06957d823739a496b3dc" +checksum = "e3b1ac5b3731ba34fdaa9785f8d74d17448cd18f30cf19e0c7e7b1fdb5272109" dependencies = [ "cfg-if", "indoc", "libc", + "memoffset", "parking_lot", "pyo3-build-config", "pyo3-ffi", @@ -278,9 +293,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.16.5" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b65b546c35d8a3b1b2f0ddbac7c6a569d759f357f2b9df884f5d6b719152c8" +checksum = "9cb946f5ac61bb61a5014924910d936ebd2b23b705f7a4a3c40b05c720b079a3" dependencies = [ "once_cell", "target-lexicon", @@ -288,9 +303,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.16.5" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c275a07127c1aca33031a563e384ffdd485aee34ef131116fcd58e3430d1742b" +checksum = "fd4d7c5337821916ea2a1d21d1092e8443cf34879e53a0ac653fbb98f44ff65c" dependencies = [ "libc", "pyo3-build-config", @@ -298,9 +313,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.16.5" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284fc4485bfbcc9850a6d661d627783f18d19c2ab55880b021671c4ba83e90f7" +checksum = "a9d39c55dab3fc5a4b25bbd1ac10a2da452c4aca13bb450f22818a002e29648d" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -310,9 +325,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.16.5" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53bda0f58f73f5c5429693c96ed57f7abdb38fdfc28ae06da4101a257adb7faf" +checksum = "97daff08a4c48320587b5224cc98d609e3c27b6d437315bd40b605c98eeb5918" dependencies = [ "proc-macro2", "quote", @@ -321,20 +336,20 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.20" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags", + "bitflags 2.11.1", ] [[package]] @@ -389,9 +404,9 @@ dependencies = [ [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "seahash" @@ -421,9 +436,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "syn" @@ -438,9 +453,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.4" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tinyvec" @@ -496,9 +511,9 @@ dependencies = [ [[package]] name = "unindent" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52fee519a3e570f7df377a06a1a7775cdbfb7aa460be7e08de2b1f0e69973a44" +checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" [[package]] name = "url" @@ -513,44 +528,7 @@ dependencies = [ ] [[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" diff --git a/Cargo.toml b/Cargo.toml index dc2f5f982..a5e395ec8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ debug = true [dependencies] adblock = { version = "=0.5.6", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] } -pyo3 = { version = "0.16", features = ["abi3-py37", "extension-module"] } +pyo3 = { version = "0.18", features = ["abi3-py37", "extension-module"] } [lib] name = "adblock" diff --git a/src/lib.rs b/src/lib.rs index e8797d298..7b1ba880d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -252,7 +252,6 @@ fn rule_types_from_string(rule_types: &str) -> PyResult { /// created. FilterSet allows assembling a compound list from multiple /// different sources before compiling the rules into an Engine. #[pyclass] -#[pyo3(text_signature = "($self, debug)")] #[derive(Clone)] pub struct FilterSet { filter_set: RustFilterSet, @@ -279,7 +278,6 @@ impl FilterSet { /// /// The format is a string containing either "standard" (ABP/uBO-style) /// or "hosts". - #[pyo3(text_signature = "($self, filter_list, format, include_redirect_urls, rule_types)")] #[args( filter_list, format = "\"standard\"", @@ -311,7 +309,6 @@ impl FilterSet { /// /// The format is a string containing either "standard" (ABP/uBO-style) /// or "hosts". - #[pyo3(text_signature = "($self, filters, format, include_redirect_urls, rule_types)")] #[args( filters, format = "\"standard\"", @@ -418,7 +415,6 @@ impl UrlSpecificResources { /// /// [1]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/ResourceType #[pyclass] -#[pyo3(text_signature = "($self, filter_set, optimize)")] pub struct Engine { engine: RustEngine, optimize: bool, @@ -442,7 +438,6 @@ impl Engine { /// * `url` - The URL of the request to check /// * `source_url` - The URL from where the request is made /// * `request_type` - The resource type that the request points to - #[pyo3(text_signature = "($self, url, source_url, request_type)")] pub fn check_network_urls( &self, url: &str, @@ -465,9 +460,6 @@ impl Engine { /// * `third_party_request` - Is the given request to a third-party? Here, /// `None` can be given and the engine will figure it out based on the /// `hostname` and `source_hostname`. - #[pyo3( - text_signature = "($self, url, hostname, source_hostname, requsest_type, third_party_request)" - )] pub fn check_network_urls_with_hostnames( &self, url: &str, @@ -499,11 +491,16 @@ impl Engine { /// * `previously_matched_rule` - Return a match as long as there are no /// exceptions /// * `force_check_exceptions` - Check exceptions even if no other rule matches - #[pyo3( - text_signature = "($self, url, hostname, source_hostname, request_type, \ - third_party_request, previously_matched_rule, force_check_exceptions)" - )] #[allow(clippy::too_many_arguments)] + #[pyo3(signature = ( + url, + hostname, + source_hostname, + request_type, + third_party_request, + previously_matched_rule, + force_check_exceptions + ))] pub fn check_network_urls_with_hostnames_subset( &self, url: &str, @@ -534,7 +531,6 @@ impl Engine { /// Use `"template"` if wanting to specify a template resource type. /// * `content`: The resource data, encoded using standard base64 configuration /// * `aliases`: List of aliases for the resource - #[pyo3(text_signature = "($self, name, content_type, content, aliases)")] pub fn add_resource( &mut self, name: &str, @@ -569,7 +565,6 @@ impl Engine { /// Serialize this blocking engine to bytes. They can then be deserialized /// using `deserialize()` to get the same engine again. - #[pyo3(text_signature = "($self)")] pub fn serialize<'p>(&mut self, py: Python<'p>) -> PyResult<&'p PyBytes> { let bytes = self.serialize_inner()?; let py_bytes = PyBytes::new(py, &bytes); @@ -590,7 +585,6 @@ impl Engine { /// Serialize this blocking engine to a file. The file can then be /// deserialized using `deserialize_from_file()` to get the same engine /// again. - #[pyo3(text_signature = "($self, file)")] pub fn serialize_to_file(&mut self, file: &str) -> PyResult<()> { let data = self.serialize_inner()?; let mut fd = fs::OpenOptions::new() @@ -603,7 +597,6 @@ impl Engine { } /// Deserialize a blocking engine from bytes produced with `serialize()`. - #[pyo3(text_signature = "($self, serialized)")] pub fn deserialize(&mut self, serialized: &[u8]) -> PyResult<()> { let result = self.engine.deserialize(serialized); match result { @@ -617,7 +610,6 @@ impl Engine { /// Deserialize a blocking engine from file produced with /// `serialize_to_file()`. - #[pyo3(text_signature = "($self, file)")] pub fn deserialize_from_file(&mut self, file: &str) -> PyResult<()> { let mut fd = fs::File::open(file)?; let mut data: Vec = Vec::new(); @@ -626,7 +618,6 @@ impl Engine { } /// Checks if the given filter exists in the blocking engine. - #[pyo3(text_signature = "($self, filter)")] pub fn filter_exists(&self, filter: &str) -> bool { self.engine.filter_exists(filter) } @@ -635,7 +626,6 @@ impl Engine { /// /// Tags can be used to cheaply enable or disable network rules with a /// corresponding $tag option. - #[pyo3(text_signature = "($self, tags)")] pub fn use_tags(&mut self, tags: Vec<&str>) { self.engine.use_tags(&tags); } @@ -645,7 +635,6 @@ impl Engine { /// /// Tags can be used to cheaply enable or disable network rules with a /// corresponding $tag option. - #[pyo3(text_signature = "($self, tags)")] pub fn enable_tags(&mut self, tags: Vec<&str>) { self.engine.enable_tags(&tags); } @@ -655,7 +644,6 @@ impl Engine { /// /// Tags can be used to cheaply enable or disable network rules with a /// corresponding $tag option. - #[pyo3(text_signature = "($self, tags)")] pub fn disable_tags(&mut self, tags: Vec<&str>) { self.engine.disable_tags(&tags); } @@ -664,7 +652,6 @@ impl Engine { /// /// Tags can be used to cheaply enable or disable network rules with a /// corresponding $tag option. - #[pyo3(text_signature = "($self, tag)")] pub fn tag_exists(&self, tag: &str) -> bool { self.engine.tag_exists(tag) } @@ -673,7 +660,6 @@ impl Engine { /// url. Once this has been called, all CSS ids and classes on a /// page should be passed to hidden_class_id_selectors to obtain any /// stylesheets consisting of generic rules. - #[pyo3(text_signature = "($self, url)")] pub fn url_cosmetic_resources(&self, url: &str) -> UrlSpecificResources { self.engine.url_cosmetic_resources(url).into() } @@ -685,7 +671,6 @@ impl Engine { /// are not excepted. /// /// Exceptions should be passed directly from UrlSpecificResources. - #[pyo3(text_signature = "($self, classes, ids, exceptions)")] pub fn hidden_class_id_selectors( &self, classes: Vec, From 12c4e19d97872e018263ad6a73be5416053e7669 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 14 Apr 2026 20:33:01 +0200 Subject: [PATCH 2/8] pyo: fix name conflict from #[pymodule] --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7b1ba880d..7613b3484 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,19 +11,19 @@ deprecated )] -use adblock::blocker::BlockerResult as RustBlockerResult; -use adblock::blocker::{BlockerError as RustBlockerError, Redirection}; -use adblock::cosmetic_filter_cache::UrlSpecificResources as RustUrlSpecificResources; -use adblock::engine::Engine as RustEngine; -use adblock::lists::FilterSet as RustFilterSet; -use adblock::lists::{FilterFormat, ParseOptions, RuleTypes}; +use ::adblock::blocker::BlockerResult as RustBlockerResult; +use ::adblock::blocker::{BlockerError as RustBlockerError, Redirection}; +use ::adblock::cosmetic_filter_cache::UrlSpecificResources as RustUrlSpecificResources; +use ::adblock::engine::Engine as RustEngine; +use ::adblock::lists::FilterSet as RustFilterSet; +use ::adblock::lists::{FilterFormat, ParseOptions, RuleTypes}; use pyo3::create_exception; use pyo3::exceptions::PyException; use pyo3::prelude::*; use pyo3::types::PyBytes; use pyo3::PyErr; -use adblock::resources::{ +use ::adblock::resources::{ AddResourceError as RustAddResourceError, MimeType, Resource, ResourceType, }; use std::collections::HashMap; From fb04c505eb85ba542b3bc19ad9ed34eada7efc4f Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 14 Apr 2026 20:40:50 +0200 Subject: [PATCH 3/8] upgrade to pyo3 0.20 - no relevant changes in 0.18 -> 0.19 - two relevant change in 0.19 -> 0.20 https://pyo3.rs/main/migration.html#from-019-to-020 - minimum Rust version raised to 1.56 - removed #[args] in favour of #[pyo3(signature=...)] --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 5 +++ Cargo.lock | 73 +++++++++++++++++++++++++++++----------- Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 24 ++++++------- 6 files changed, 74 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe1f4e14c..511378a14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -147,7 +147,7 @@ jobs: platform: [ { - toolchain: "1.53", + toolchain: "1.56", manylinux: "2014", target: "x86_64-unknown-linux-gnu", arch: "x86_64", diff --git a/CHANGELOG.md b/CHANGELOG.md index 90616340f..b26cd93b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch ## Unreleased --- +### Changes +* Update PyO3 dependency to `0.20`. + +### Breaks +* Minimum Rust version is now `1.56`. ## 0.6.0 - (2022-07-17) --- diff --git a/Cargo.lock b/Cargo.lock index e230e7eef..8189f3340 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "idna" version = "0.2.3" @@ -142,9 +148,12 @@ dependencies = [ [[package]] name = "indoc" -version = "1.0.9" +version = "2.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" +checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" +dependencies = [ + "rustversion", +] [[package]] name = "itertools" @@ -184,9 +193,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" dependencies = [ "autocfg", ] @@ -250,6 +259,12 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + [[package]] name = "proc-macro2" version = "1.0.106" @@ -276,15 +291,16 @@ checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" [[package]] name = "pyo3" -version = "0.18.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b1ac5b3731ba34fdaa9785f8d74d17448cd18f30cf19e0c7e7b1fdb5272109" +checksum = "53bdbb96d49157e65d45cc287af5f32ffadd5f4761438b527b055fb0d4bb8233" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", "parking_lot", + "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -293,9 +309,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.18.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cb946f5ac61bb61a5014924910d936ebd2b23b705f7a4a3c40b05c720b079a3" +checksum = "deaa5745de3f5231ce10517a1f5dd97d53e5a2fd77aa6b5842292085831d48d7" dependencies = [ "once_cell", "target-lexicon", @@ -303,9 +319,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.18.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd4d7c5337821916ea2a1d21d1092e8443cf34879e53a0ac653fbb98f44ff65c" +checksum = "62b42531d03e08d4ef1f6e85a2ed422eb678b8cd62b762e53891c05faf0d4afa" dependencies = [ "libc", "pyo3-build-config", @@ -313,25 +329,27 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.18.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d39c55dab3fc5a4b25bbd1ac10a2da452c4aca13bb450f22818a002e29648d" +checksum = "7305c720fa01b8055ec95e484a6eca7a83c841267f0dd5280f0c8b8551d2c158" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn", + "syn 2.0.117", ] [[package]] name = "pyo3-macros-backend" -version = "0.18.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97daff08a4c48320587b5224cc98d609e3c27b6d437315bd40b605c98eeb5918" +checksum = "7c7e9b68bb9c3149c5b0cade5d07f953d6d125eb4337723c4ccdb665f1f96185" dependencies = [ + "heck", "proc-macro2", + "pyo3-build-config", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -402,6 +420,12 @@ dependencies = [ "serde", ] +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "scopeguard" version = "1.2.0" @@ -431,7 +455,7 @@ checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.98", ] [[package]] @@ -451,6 +475,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "target-lexicon" version = "0.12.16" @@ -511,9 +546,9 @@ dependencies = [ [[package]] name = "unindent" -version = "0.1.11" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" +checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" [[package]] name = "url" diff --git a/Cargo.toml b/Cargo.toml index a5e395ec8..2df460680 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ debug = true [dependencies] adblock = { version = "=0.5.6", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] } -pyo3 = { version = "0.18", features = ["abi3-py37", "extension-module"] } +pyo3 = { version = "0.20", features = ["abi3-py37", "extension-module"] } [lib] name = "adblock" diff --git a/README.md b/README.md index ee9343195..50872984b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Python wrapper for Brave's adblocking library, which is written in Rust. | Build Dependency | Versions | Arch Linux | Url | | ---------------- | -------- | ---------- | ------------------------------- | | Python | `>=3.7` | `python` | - | -| Rust | `>=1.53` | `rust` | - | +| Rust | `>=1.56` | `rust` | - | | Maturin | `>=0.10` | `maturin` | https://github.com/PyO3/maturin | #### PEP 517 diff --git a/src/lib.rs b/src/lib.rs index 7613b3484..f39264fcc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -265,7 +265,7 @@ impl FilterSet { /// the more compact internal representation. If enabled, this information /// will be passed to the corresponding Engine. #[new] - #[args(debug = false)] + #[pyo3(signature = (debug=false))] pub fn new(debug: bool) -> Self { Self { filter_set: RustFilterSet::new(debug), @@ -278,12 +278,12 @@ impl FilterSet { /// /// The format is a string containing either "standard" (ABP/uBO-style) /// or "hosts". - #[args( + #[pyo3(signature = ( filter_list, - format = "\"standard\"", - include_redirect_urls = "false", - rule_types = "\"all\"" - )] + format = "standard", + include_redirect_urls = false, + rule_types = "all" + ))] pub fn add_filter_list( &mut self, filter_list: &str, @@ -309,12 +309,12 @@ impl FilterSet { /// /// The format is a string containing either "standard" (ABP/uBO-style) /// or "hosts". - #[args( + #[pyo3(signature = ( filters, - format = "\"standard\"", - include_redirect_urls = "false", - rule_types = "\"all\"" - )] + format = "standard", + include_redirect_urls = false, + rule_types = "all" + ))] pub fn add_filters( &mut self, filters: Vec, @@ -424,7 +424,7 @@ pub struct Engine { impl Engine { /// Create a new adblocking engine #[new] - #[args(filter_set, optimize = true)] + #[pyo3(signature = (filter_set, optimize = true))] pub fn new(filter_set: FilterSet, optimize: bool) -> Self { let engine = RustEngine::from_filter_set(filter_set.filter_set, optimize); Self { engine, optimize } From f9aa5fedf65ca9d5ce21f7180903eb095b8d122b Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 14 Apr 2026 21:09:04 +0200 Subject: [PATCH 4/8] upgrade to pyo3 0.21 Convert to using the pyo3::Bound smart pointer instead of refs. In the case of the use_tags, enable_tags and disable_tags functions, it would alternatively be possible to use Vec but this seems to me to be even more complicated. --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- src/lib.rs | 38 ++++++++++++++++++++++---------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8189f3340..1d5463a02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,9 +291,9 @@ checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" [[package]] name = "pyo3" -version = "0.20.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53bdbb96d49157e65d45cc287af5f32ffadd5f4761438b527b055fb0d4bb8233" +checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" dependencies = [ "cfg-if", "indoc", @@ -309,9 +309,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.20.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deaa5745de3f5231ce10517a1f5dd97d53e5a2fd77aa6b5842292085831d48d7" +checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" dependencies = [ "once_cell", "target-lexicon", @@ -319,9 +319,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.20.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b42531d03e08d4ef1f6e85a2ed422eb678b8cd62b762e53891c05faf0d4afa" +checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" dependencies = [ "libc", "pyo3-build-config", @@ -329,9 +329,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.20.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7305c720fa01b8055ec95e484a6eca7a83c841267f0dd5280f0c8b8551d2c158" +checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -341,9 +341,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.20.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c7e9b68bb9c3149c5b0cade5d07f953d6d125eb4337723c4ccdb665f1f96185" +checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 2df460680..39957bbe3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ debug = true [dependencies] adblock = { version = "=0.5.6", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] } -pyo3 = { version = "0.20", features = ["abi3-py37", "extension-module"] } +pyo3 = { version = "0.21", features = ["abi3-py37", "extension-module"] } [lib] name = "adblock" diff --git a/src/lib.rs b/src/lib.rs index f39264fcc..a54a75ce7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,39 +35,42 @@ use std::io::{Read, Write}; /// Brave's adblocking library in Python! #[pymodule] -fn adblock(py: Python<'_>, m: &PyModule) -> PyResult<()> { +fn adblock<'py>(py: Python<'py>, m: Bound<'py, PyModule>) -> PyResult<()> { m.add("__version__", env!("CARGO_PKG_VERSION"))?; m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?; - m.add("AdblockException", py.get_type::())?; - m.add("BlockerException", py.get_type::())?; - m.add("SerializationError", py.get_type::())?; + m.add("AdblockException", py.get_type_bound::())?; + m.add("BlockerException", py.get_type_bound::())?; + m.add( + "SerializationError", + py.get_type_bound::(), + )?; m.add( "DeserializationError", - py.get_type::(), + py.get_type_bound::(), )?; m.add( "OptimizedFilterExistence", - py.get_type::(), + py.get_type_bound::(), )?; m.add( "BadFilterAddUnsupported", - py.get_type::(), + py.get_type_bound::(), )?; - m.add("FilterExists", py.get_type::())?; + m.add("FilterExists", py.get_type_bound::())?; m.add( "AddResourceException", - py.get_type::(), + py.get_type_bound::(), )?; m.add( "InvalidBase64ContentError", - py.get_type::(), + py.get_type_bound::(), )?; m.add( "InvalidUtf8ContentError", - py.get_type::(), + py.get_type_bound::(), )?; Ok(()) } @@ -565,9 +568,9 @@ impl Engine { /// Serialize this blocking engine to bytes. They can then be deserialized /// using `deserialize()` to get the same engine again. - pub fn serialize<'p>(&mut self, py: Python<'p>) -> PyResult<&'p PyBytes> { + pub fn serialize<'p>(&mut self, py: Python<'p>) -> PyResult> { let bytes = self.serialize_inner()?; - let py_bytes = PyBytes::new(py, &bytes); + let py_bytes = PyBytes::new_bound(py, &bytes); Ok(py_bytes) } @@ -626,7 +629,8 @@ impl Engine { /// /// Tags can be used to cheaply enable or disable network rules with a /// corresponding $tag option. - pub fn use_tags(&mut self, tags: Vec<&str>) { + pub fn use_tags(&mut self, tags: Vec) { + let tags = tags.iter().map(String::as_str).collect::>(); self.engine.use_tags(&tags); } @@ -635,7 +639,8 @@ impl Engine { /// /// Tags can be used to cheaply enable or disable network rules with a /// corresponding $tag option. - pub fn enable_tags(&mut self, tags: Vec<&str>) { + pub fn enable_tags(&mut self, tags: Vec) { + let tags = tags.iter().map(String::as_str).collect::>(); self.engine.enable_tags(&tags); } @@ -644,7 +649,8 @@ impl Engine { /// /// Tags can be used to cheaply enable or disable network rules with a /// corresponding $tag option. - pub fn disable_tags(&mut self, tags: Vec<&str>) { + pub fn disable_tags(&mut self, tags: Vec) { + let tags = tags.iter().map(String::as_str).collect::>(); self.engine.disable_tags(&tags); } From 5ded1b47a41dfbe3beba1d9b3e022496ae2a5fd0 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 14 Apr 2026 21:15:24 +0200 Subject: [PATCH 5/8] upgrade to pyo3 0.22 Implicit default for trailing optional arguments deprecated. --- Cargo.lock | 93 ++++++++---------------------------------------------- Cargo.toml | 2 +- src/lib.rs | 13 ++++++++ 3 files changed, 28 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d5463a02..67f5ee8c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "27785ef5b89bc88fd2def3e1ecfefdf5ec1583795b916667afd15b13058f8315" dependencies = [ "addr", "base64", - "bitflags 1.3.2", + "bitflags", "flate2", "idna", "itertools", @@ -76,12 +76,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" - [[package]] name = "byteorder" version = "1.4.3" @@ -131,9 +125,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "idna" @@ -170,15 +164,6 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - [[package]] name = "matches" version = "0.1.9" @@ -224,29 +209,6 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" -[[package]] -name = "parking_lot" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link", -] - [[package]] name = "paste" version = "1.0.7" @@ -291,15 +253,15 @@ checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" [[package]] name = "pyo3" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -309,9 +271,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38" dependencies = [ "once_cell", "target-lexicon", @@ -319,9 +281,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636" dependencies = [ "libc", "pyo3-build-config", @@ -329,9 +291,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -341,9 +303,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe" dependencies = [ "heck", "proc-macro2", @@ -361,15 +323,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -dependencies = [ - "bitflags 2.11.1", -] - [[package]] name = "regex" version = "1.6.0" @@ -426,12 +379,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "seahash" version = "3.0.7" @@ -458,12 +405,6 @@ dependencies = [ "syn 1.0.98", ] -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - [[package]] name = "syn" version = "1.0.98" @@ -561,9 +502,3 @@ dependencies = [ "matches", "percent-encoding", ] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" diff --git a/Cargo.toml b/Cargo.toml index 39957bbe3..9b34d6772 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ debug = true [dependencies] adblock = { version = "=0.5.6", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] } -pyo3 = { version = "0.21", features = ["abi3-py37", "extension-module"] } +pyo3 = { version = "0.22", features = ["abi3-py37", "extension-module"] } [lib] name = "adblock" diff --git a/src/lib.rs b/src/lib.rs index a54a75ce7..1d78c5024 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -463,6 +463,13 @@ impl Engine { /// * `third_party_request` - Is the given request to a third-party? Here, /// `None` can be given and the engine will figure it out based on the /// `hostname` and `source_hostname`. + #[pyo3(signature = ( + url, + hostname, + source_hostname, + request_type, + third_party_request, + ))] pub fn check_network_urls_with_hostnames( &self, url: &str, @@ -534,6 +541,12 @@ impl Engine { /// Use `"template"` if wanting to specify a template resource type. /// * `content`: The resource data, encoded using standard base64 configuration /// * `aliases`: List of aliases for the resource + #[pyo3(signature = ( + name, + content_type, + content, + aliases=None, + ))] pub fn add_resource( &mut self, name: &str, From 1534d1a366cd73091aaa5f8593b22f1be57cfc2e Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 14 Apr 2026 21:18:07 +0200 Subject: [PATCH 6/8] upgrade to pyo3 0.23 gil-refs feature removed and _bound functions have now become the "normal" versions of the respective functions. --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- src/lib.rs | 25 +++++++++++-------------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67f5ee8c8..2db5c9d2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -253,9 +253,9 @@ checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" [[package]] name = "pyo3" -version = "0.22.6" +version = "0.23.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884" +checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872" dependencies = [ "cfg-if", "indoc", @@ -271,9 +271,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.6" +version = "0.23.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38" +checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb" dependencies = [ "once_cell", "target-lexicon", @@ -281,9 +281,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.6" +version = "0.23.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636" +checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d" dependencies = [ "libc", "pyo3-build-config", @@ -291,9 +291,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.6" +version = "0.23.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453" +checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -303,9 +303,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.22.6" +version = "0.23.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe" +checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 9b34d6772..383af1105 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ debug = true [dependencies] adblock = { version = "=0.5.6", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] } -pyo3 = { version = "0.22", features = ["abi3-py37", "extension-module"] } +pyo3 = { version = "0.23", features = ["abi3-py37", "extension-module"] } [lib] name = "adblock" diff --git a/src/lib.rs b/src/lib.rs index 1d78c5024..b04012ace 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,36 +41,33 @@ fn adblock<'py>(py: Python<'py>, m: Bound<'py, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; - m.add("AdblockException", py.get_type_bound::())?; - m.add("BlockerException", py.get_type_bound::())?; - m.add( - "SerializationError", - py.get_type_bound::(), - )?; + m.add("AdblockException", py.get_type::())?; + m.add("BlockerException", py.get_type::())?; + m.add("SerializationError", py.get_type::())?; m.add( "DeserializationError", - py.get_type_bound::(), + py.get_type::(), )?; m.add( "OptimizedFilterExistence", - py.get_type_bound::(), + py.get_type::(), )?; m.add( "BadFilterAddUnsupported", - py.get_type_bound::(), + py.get_type::(), )?; - m.add("FilterExists", py.get_type_bound::())?; + m.add("FilterExists", py.get_type::())?; m.add( "AddResourceException", - py.get_type_bound::(), + py.get_type::(), )?; m.add( "InvalidBase64ContentError", - py.get_type_bound::(), + py.get_type::(), )?; m.add( "InvalidUtf8ContentError", - py.get_type_bound::(), + py.get_type::(), )?; Ok(()) } @@ -583,7 +580,7 @@ impl Engine { /// using `deserialize()` to get the same engine again. pub fn serialize<'p>(&mut self, py: Python<'p>) -> PyResult> { let bytes = self.serialize_inner()?; - let py_bytes = PyBytes::new_bound(py, &bytes); + let py_bytes = PyBytes::new(py, &bytes); Ok(py_bytes) } From 6b7aab95fed7e09956c4946ffd7f05bd485ef9d3 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 14 Apr 2026 21:30:30 +0200 Subject: [PATCH 7/8] upgrade to pyo3 0.28 no relevant changes in 0.23 -> 0.27 one relevant change in 0.27 -> 0.28 - deprecation of automatic FromPyObject for #[pyclass] - because of the use in Engine::new, the FromPyObject is needed for FilterSet, so it is explicity enabled. --- CHANGELOG.md | 2 +- Cargo.lock | 59 +++++++++++----------------------------------------- Cargo.toml | 2 +- src/lib.rs | 2 +- 4 files changed, 15 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b26cd93b0..5e4a85725 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch ## Unreleased --- ### Changes -* Update PyO3 dependency to `0.20`. +* Update PyO3 dependency to `0.28`. ### Breaks * Minimum Rust version is now `1.56`. diff --git a/Cargo.lock b/Cargo.lock index 2db5c9d2a..4dd2f85bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -140,15 +140,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indoc" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" -dependencies = [ - "rustversion", -] - [[package]] name = "itertools" version = "0.10.3" @@ -176,15 +167,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - [[package]] name = "miniz_oxide" version = "0.5.3" @@ -253,37 +235,32 @@ checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" [[package]] name = "pyo3" -version = "0.23.5" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872" +checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12" dependencies = [ - "cfg-if", - "indoc", "libc", - "memoffset", "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", - "unindent", ] [[package]] name = "pyo3-build-config" -version = "0.23.5" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb" +checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e" dependencies = [ - "once_cell", "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.23.5" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d" +checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e" dependencies = [ "libc", "pyo3-build-config", @@ -291,9 +268,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.23.5" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da" +checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -303,9 +280,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.23.5" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028" +checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb" dependencies = [ "heck", "proc-macro2", @@ -373,12 +350,6 @@ dependencies = [ "serde", ] -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - [[package]] name = "seahash" version = "3.0.7" @@ -429,9 +400,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.16" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" +checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" [[package]] name = "tinyvec" @@ -485,12 +456,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unindent" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" - [[package]] name = "url" version = "2.2.2" diff --git a/Cargo.toml b/Cargo.toml index 383af1105..2e1248b04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ debug = true [dependencies] adblock = { version = "=0.5.6", default-features = false, features = ["full-regex-handling", "embedded-domain-resolver"] } -pyo3 = { version = "0.23", features = ["abi3-py37", "extension-module"] } +pyo3 = { version = "0.28", features = ["abi3-py37", "extension-module"] } [lib] name = "adblock" diff --git a/src/lib.rs b/src/lib.rs index b04012ace..d588247d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -251,7 +251,7 @@ fn rule_types_from_string(rule_types: &str) -> PyResult { /// allow optimizations, all rules must be available when the Engine is first /// created. FilterSet allows assembling a compound list from multiple /// different sources before compiling the rules into an Engine. -#[pyclass] +#[pyclass(from_py_object)] #[derive(Clone)] pub struct FilterSet { filter_set: RustFilterSet, From c9d11a7bb5f717033a65003d46763146b6a443cc Mon Sep 17 00:00:00 2001 From: Johann150 Date: Wed, 15 Apr 2026 07:17:55 +0200 Subject: [PATCH 8/8] format with black --- adblock/adblock.pyi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/adblock/adblock.pyi b/adblock/adblock.pyi index 6c4398f0b..5a8802629 100644 --- a/adblock/adblock.pyi +++ b/adblock/adblock.pyi @@ -55,6 +55,7 @@ class UrlSpecificResources: class FilterSet: def __init__(self, debug: bool = False) -> None: pass + def add_filter_list( self, filter_list: str, @@ -63,6 +64,7 @@ class FilterSet: rule_types: str = "all", ) -> None: pass + def add_filters( self, filters: List[str], @@ -75,10 +77,12 @@ class FilterSet: class Engine: def __init__(self, filter_set: FilterSet, optimize: bool = True) -> None: pass + def check_network_urls( self, url: str, source_url: str, request_type: str ) -> BlockerResult: pass + def check_network_urls_with_hostnames( self, url: str, @@ -88,6 +92,7 @@ class Engine: third_party_request: Optional[bool], ) -> BlockerResult: pass + def check_network_urls_with_hostnames_subset( self, url: str, @@ -99,24 +104,34 @@ class Engine: force_check_exceptions: bool, ) -> BlockerResult: pass + def serialize(self) -> bytes: pass + def serialize_to_file(self, file: str) -> None: pass + def deserialize(self, serialized: bytes) -> None: pass + def deserialize_from_file(self, file: str) -> None: pass + def filter_exists(self, filter: str) -> bool: pass + def use_tags(self, tags: List[str]) -> None: pass + def enable_tags(self, tags: List[str]) -> None: pass + def disable_tags(self, tags: List[str]) -> None: pass + def tag_exists(self, tag: str) -> bool: pass + def add_resource( self, name: str, @@ -125,8 +140,10 @@ class Engine: aliases: Optional[List[str]] = None, ) -> bool: pass + def url_cosmetic_resources(self, url: str) -> UrlSpecificResources: pass + def hidden_class_id_selectors( self, classes: List[str], ids: List[str], exceptions: Set[str] ) -> List[str]: