From 03ca79632fe42ff2d4b22ed6d03c2289497e8d6c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 30 Jul 2024 15:34:55 +0000 Subject: [PATCH] Upgrade pyo3 to 0.22 --- native/Cargo.lock | 123 ++++++----------------- native/libcst/Cargo.toml | 2 +- native/libcst/src/nodes/expression.rs | 13 +-- native/libcst/src/nodes/parser_config.rs | 2 +- native/libcst/src/nodes/traits.rs | 2 +- native/libcst/src/parser/errors.rs | 13 +-- native/libcst/src/py.rs | 2 +- native/libcst_derive/src/into_py.rs | 15 +-- 8 files changed, 60 insertions(+), 112 deletions(-) diff --git a/native/Cargo.lock b/native/Cargo.lock index e62007e44..6996a8827 100644 --- a/native/Cargo.lock +++ b/native/Cargo.lock @@ -35,12 +35,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.4.0" @@ -263,9 +257,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[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 = "hermit-abi" @@ -288,15 +282,6 @@ version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "is-terminal" version = "0.4.9" @@ -376,7 +361,7 @@ name = "libcst_derive" version = "1.4.0" dependencies = [ "quote", - "syn 2.0.41", + "syn 2.0.72", "trybuild", ] @@ -386,16 +371,6 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" -[[package]] -name = "lock_api" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.17" @@ -460,31 +435,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] - [[package]] name = "paste" version = "1.0.9" @@ -546,26 +496,33 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "portable-atomic" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" + [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.20.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a89dc7a5850d0e983be1ec2a463a171d20990487c3cfcd68b5363f1ee3d6fe0" +checksum = "831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433" dependencies = [ "cfg-if", "indoc", "libc", "memoffset 0.9.0", - "parking_lot", + "once_cell", + "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -574,9 +531,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.20.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07426f0d8fe5a601f26293f300afd1a7b1ed5e78b2a705870c5f30893c5163be" +checksum = "1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8" dependencies = [ "once_cell", "target-lexicon", @@ -584,9 +541,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.20.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb7dec17e17766b46bca4f1a4215a85006b4c2ecde122076c562dd058da6cf1" +checksum = "5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6" dependencies = [ "libc", "pyo3-build-config", @@ -594,33 +551,34 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.20.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f738b4e40d50b5711957f142878cfa0f28e054aa0ebdfc3fd137a843f74ed3" +checksum = "eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.41", + "syn 2.0.72", ] [[package]] name = "pyo3-macros-backend" -version = "0.20.2" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc910d4851847827daf9d6cdd4a823fbdaab5b8818325c5e97a86da79e8881f" +checksum = "ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372" dependencies = [ "heck", "proc-macro2", + "pyo3-build-config", "quote", - "syn 2.0.41", + "syn 2.0.72", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -647,15 +605,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "redox_syscall" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "regex" version = "1.9.3" @@ -691,7 +640,7 @@ version = "0.38.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" dependencies = [ - "bitflags 2.4.0", + "bitflags", "errno", "libc", "linux-raw-sys", @@ -750,12 +699,6 @@ dependencies = [ "serde", ] -[[package]] -name = "smallvec" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc88c725d61fc6c3132893370cac4a0200e3fedf5da8331c570664b1987f5ca2" - [[package]] name = "syn" version = "1.0.109" @@ -769,9 +712,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -780,9 +723,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.4" +version = "0.12.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1" +checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" [[package]] name = "termcolor" diff --git a/native/libcst/Cargo.toml b/native/libcst/Cargo.toml index 2fd6ced53..52489199d 100644 --- a/native/libcst/Cargo.toml +++ b/native/libcst/Cargo.toml @@ -36,7 +36,7 @@ trace = ["peg/trace"] [dependencies] paste = "1.0.9" -pyo3 = { version = "0.20", optional = true } +pyo3 = { version = "0.22", optional = true } thiserror = "1.0.37" peg = "0.8.1" chic = "1.2.2" diff --git a/native/libcst/src/nodes/expression.rs b/native/libcst/src/nodes/expression.rs index 971ef8bc6..bc3699bf7 100644 --- a/native/libcst/src/nodes/expression.rs +++ b/native/libcst/src/nodes/expression.rs @@ -2524,6 +2524,7 @@ impl<'r, 'a> Inflate<'a> for DeflatedNamedExpr<'r, 'a> { #[cfg(feature = "py")] mod py { + use pyo3::types::PyAnyMethods; use pyo3::types::PyModule; use super::*; @@ -2535,7 +2536,7 @@ mod py { match self { Self::Starred(s) => s.try_into_py(py), Self::Simple { value, comma } => { - let libcst = PyModule::import(py, "libcst")?; + let libcst = PyModule::import_bound(py, "libcst")?; let kwargs = [ Some(("value", value.try_into_py(py)?)), comma @@ -2547,11 +2548,11 @@ mod py { .filter(|x| x.is_some()) .map(|x| x.as_ref().unwrap()) .collect::>() - .into_py_dict(py); + .into_py_dict_bound(py); Ok(libcst .getattr("Element") .expect("no Element found in libcst") - .call((), Some(kwargs))? + .call((), Some(&kwargs))? .into()) } } @@ -2571,7 +2572,7 @@ mod py { whitespace_before_colon, .. } => { - let libcst = PyModule::import(py, "libcst")?; + let libcst = PyModule::import_bound(py, "libcst")?; let kwargs = [ Some(("key", key.try_into_py(py)?)), Some(("value", value.try_into_py(py)?)), @@ -2592,11 +2593,11 @@ mod py { .filter(|x| x.is_some()) .map(|x| x.as_ref().unwrap()) .collect::>() - .into_py_dict(py); + .into_py_dict_bound(py); Ok(libcst .getattr("DictElement") .expect("no Element found in libcst") - .call((), Some(kwargs))? + .call((), Some(&kwargs))? .into()) } } diff --git a/native/libcst/src/nodes/parser_config.rs b/native/libcst/src/nodes/parser_config.rs index 6dfdf544c..4a80a048b 100644 --- a/native/libcst/src/nodes/parser_config.rs +++ b/native/libcst/src/nodes/parser_config.rs @@ -125,7 +125,7 @@ fn parser_config_asdict<'py>(py: Python<'py>, config: PyRef<'py, ParserConfig>) ("version", config.version.clone_ref(py)), ("future_imports", config.future_imports.clone_ref(py)), ] - .into_py_dict(py) + .into_py_dict_bound(py) } pub fn init_module(_py: Python, m: &PyModule) -> PyResult<()> { diff --git a/native/libcst/src/nodes/traits.rs b/native/libcst/src/nodes/traits.rs index 1dd58132c..397f64042 100644 --- a/native/libcst/src/nodes/traits.rs +++ b/native/libcst/src/nodes/traits.rs @@ -170,7 +170,7 @@ pub mod py { .map(|x| x.try_into_py(py)) .collect::>>()? .into_iter(); - Ok(PyTuple::new(py, converted).into()) + Ok(PyTuple::new_bound(py, converted).into()) } } diff --git a/native/libcst/src/parser/errors.rs b/native/libcst/src/parser/errors.rs index 79132ce14..85690c978 100644 --- a/native/libcst/src/parser/errors.rs +++ b/native/libcst/src/parser/errors.rs @@ -28,7 +28,7 @@ pub enum ParserError<'a> { #[cfg(feature = "py")] mod py_error { - use pyo3::types::{IntoPyDict, PyModule}; + use pyo3::types::{IntoPyDict, PyAnyMethods, PyModule}; use pyo3::{IntoPy, PyErr, PyErrArguments, Python}; use super::ParserError; @@ -65,13 +65,14 @@ mod py_error { ("raw_line", (line + 1).into_py(py)), ("raw_column", col.into_py(py)), ] - .into_py_dict(py); - let libcst = PyModule::import(py, "libcst").expect("libcst cannot be imported"); - PyErr::from_value( + .into_py_dict_bound(py); + let libcst = + PyModule::import_bound(py, "libcst").expect("libcst cannot be imported"); + PyErr::from_value_bound( libcst .getattr("ParserSyntaxError") .expect("ParserSyntaxError not found") - .call((), Some(kwargs)) + .call((), Some(&kwargs)) .expect("failed to instantiate"), ) }) @@ -86,7 +87,7 @@ mod py_error { ("raw_line", self.raw_line.into_py(py)), ("raw_column", self.raw_column.into_py(py)), ] - .into_py_dict(py) + .into_py_dict_bound(py) .into_py(py) } } diff --git a/native/libcst/src/py.rs b/native/libcst/src/py.rs index 960fac3ae..963a71a8e 100644 --- a/native/libcst/src/py.rs +++ b/native/libcst/src/py.rs @@ -8,7 +8,7 @@ use pyo3::prelude::*; #[pymodule] #[pyo3(name = "native")] -pub fn libcst_native(_py: Python, m: &PyModule) -> PyResult<()> { +pub fn libcst_native(_py: Python, m: &Bound) -> PyResult<()> { #[pyfn(m)] fn parse_module(source: String, encoding: Option<&str>) -> PyResult { let m = crate::parse_module(source.as_str(), encoding)?; diff --git a/native/libcst_derive/src/into_py.rs b/native/libcst_derive/src/into_py.rs index 3894212fd..ac656cb49 100644 --- a/native/libcst_derive/src/into_py.rs +++ b/native/libcst_derive/src/into_py.rs @@ -38,12 +38,14 @@ fn impl_into_py_enum(ast: &DeriveInput, e: &DataEnum) -> TokenStream { let kwargs_toks = fields_to_kwargs(&var.fields, true); toks.push(quote! { Self::#varname { #(#fieldnames,)* .. } => { - let libcst = pyo3::types::PyModule::import(py, "libcst")?; + use pyo3::types::PyAnyMethods; + + let libcst = pyo3::types::PyModule::import_bound(py, "libcst")?; let kwargs = #kwargs_toks ; Ok(libcst .getattr(stringify!(#varname)) .expect(stringify!(no #varname found in libcst)) - .call((), Some(kwargs))? + .call((), Some(&kwargs))? .into()) } }) @@ -87,12 +89,13 @@ fn impl_into_py_struct(ast: &DeriveInput, e: &DataStruct) -> TokenStream { #[automatically_derived] impl#generics crate::nodes::traits::py::TryIntoPy for #ident #generics { fn try_into_py(self, py: pyo3::Python) -> pyo3::PyResult { - let libcst = pyo3::types::PyModule::import(py, "libcst")?; + use pyo3::types::PyAnyMethods; + let libcst = pyo3::types::PyModule::import_bound(py, "libcst")?; let kwargs = #kwargs_toks ; Ok(libcst .getattr(stringify!(#ident)) .expect(stringify!(no #ident found in libcst)) - .call((), Some(kwargs))? + .call((), Some(&kwargs))? .into()) } } @@ -162,7 +165,7 @@ fn fields_to_kwargs(fields: &Fields, is_enum: bool) -> quote::__private::TokenSt #(#optional_rust_varnames.map(|x| x.try_into_py(py)).transpose()?.map(|x| (stringify!(#optional_py_varnames), x)),)* }; if empty_kwargs { - quote! { pyo3::types::PyDict::new(py) } + quote! { pyo3::types::PyDict::new_bound(py) } } else { quote! { [ #kwargs_pairs #optional_pairs ] @@ -170,7 +173,7 @@ fn fields_to_kwargs(fields: &Fields, is_enum: bool) -> quote::__private::TokenSt .filter(|x| x.is_some()) .map(|x| x.as_ref().unwrap()) .collect::>() - .into_py_dict(py) + .into_py_dict_bound(py) } } }