1
0
forked from pool/python-libcst
python-libcst/pyo3-022.patch

349 lines
12 KiB
Diff

From 03ca79632fe42ff2d4b22ed6d03c2289497e8d6c Mon Sep 17 00:00:00 2001
From: Jelmer Vernooij <jelmer@jelmer.uk>
Date: Tue, 30 Jul 2024 15:34:55 +0000
Subject: [PATCH] Upgrade pyo3 to 0.22
---
native/Cargo.lock | 57 +++++++------------------------
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, 40 insertions(+), 66 deletions(-)
--- a/native/Cargo.lock
+++ b/native/Cargo.lock
@@ -36,12 +36,6 @@ source = "registry+https://github.com/ru
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
-name = "bitflags"
-version = "2.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
-
-[[package]]
name = "bumpalo"
version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -229,9 +223,9 @@ checksum = "e5274423e17b7c9fc20b6e7e2085
[[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"
@@ -333,16 +327,6 @@ dependencies = [
]
[[package]]
-name = "lock_api"
-version = "0.4.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
-dependencies = [
- "autocfg",
- "scopeguard",
-]
-
-[[package]]
name = "log"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -485,15 +469,15 @@ dependencies = [
[[package]]
name = "pyo3"
-version = "0.20.3"
+version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "53bdbb96d49157e65d45cc287af5f32ffadd5f4761438b527b055fb0d4bb8233"
+checksum = "831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433"
dependencies = [
"cfg-if",
"indoc",
"libc",
"memoffset",
- "parking_lot",
+ "once_cell",
"portable-atomic",
"pyo3-build-config",
"pyo3-ffi",
@@ -503,9 +487,9 @@ dependencies = [
[[package]]
name = "pyo3-build-config"
-version = "0.20.3"
+version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "deaa5745de3f5231ce10517a1f5dd97d53e5a2fd77aa6b5842292085831d48d7"
+checksum = "1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8"
dependencies = [
"once_cell",
"target-lexicon",
@@ -513,9 +497,9 @@ dependencies = [
[[package]]
name = "pyo3-ffi"
-version = "0.20.3"
+version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62b42531d03e08d4ef1f6e85a2ed422eb678b8cd62b762e53891c05faf0d4afa"
+checksum = "5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6"
dependencies = [
"libc",
"pyo3-build-config",
@@ -523,9 +507,9 @@ dependencies = [
[[package]]
name = "pyo3-macros"
-version = "0.20.3"
+version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7305c720fa01b8055ec95e484a6eca7a83c841267f0dd5280f0c8b8551d2c158"
+checksum = "eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
@@ -535,9 +519,9 @@ dependencies = [
[[package]]
name = "pyo3-macros-backend"
-version = "0.20.3"
+version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7c7e9b68bb9c3149c5b0cade5d07f953d6d125eb4337723c4ccdb665f1f96185"
+checksum = "ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372"
dependencies = [
"heck",
"proc-macro2",
@@ -576,15 +560,6 @@ dependencies = [
]
[[package]]
-name = "redox_syscall"
-version = "0.5.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4"
-dependencies = [
- "bitflags",
-]
-
-[[package]]
name = "regex"
version = "1.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -676,12 +651,6 @@ dependencies = [
]
[[package]]
-name = "smallvec"
-version = "1.13.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
-
-[[package]]
name = "syn"
version = "2.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
--- 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"
--- a/native/libcst/src/nodes/expression.rs
+++ b/native/libcst/src/nodes/expression.rs
@@ -2524,6 +2524,7 @@ impl<'r, 'a> Inflate<'a> for DeflatedNam
#[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::<Vec<_>>()
- .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::<Vec<_>>()
- .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())
}
}
--- 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<
("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<()> {
--- 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::<PyResult<Vec<_>>>()?
.into_iter();
- Ok(PyTuple::new(py, converted).into())
+ Ok(PyTuple::new_bound(py, converted).into())
}
}
--- 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)
}
}
--- 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<PyModule>) -> PyResult<()> {
#[pyfn(m)]
fn parse_module(source: String, encoding: Option<&str>) -> PyResult<PyObject> {
let m = crate::parse_module(source.as_str(), encoding)?;
--- 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,
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
#[automatically_derived]
impl#generics crate::nodes::traits::py::TryIntoPy<pyo3::PyObject> for #ident #generics {
fn try_into_py(self, py: pyo3::Python) -> pyo3::PyResult<pyo3::PyObject> {
- 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_
#(#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_
.filter(|x| x.is_some())
.map(|x| x.as_ref().unwrap())
.collect::<Vec<_>>()
- .into_py_dict(py)
+ .into_py_dict_bound(py)
}
}
}