Skip to content

Commit c2169d2

Browse files
authored
Update PyO3 to 0.26 (#1413)
1 parent 73b17d8 commit c2169d2

File tree

9 files changed

+61
-62
lines changed

9 files changed

+61
-62
lines changed

native/Cargo.lock

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

native/libcst/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trace = ["peg/trace"]
3636

3737
[dependencies]
3838
paste = "1.0.15"
39-
pyo3 = { version = "0.25.1", optional = true }
39+
pyo3 = { version = "0.26", optional = true }
4040
thiserror = "2.0.12"
4141
peg = "0.8.5"
4242
annotate-snippets = "0.11.5"

native/libcst/src/nodes/expression.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,8 +2670,8 @@ mod py {
26702670
use crate::nodes::traits::py::TryIntoPy;
26712671

26722672
// TODO: this could be a derive helper attribute to override the python class name
2673-
impl<'a> TryIntoPy<pyo3::PyObject> for Element<'a> {
2674-
fn try_into_py(self, py: pyo3::Python) -> pyo3::PyResult<pyo3::PyObject> {
2673+
impl<'a> TryIntoPy<pyo3::Py<pyo3::PyAny>> for Element<'a> {
2674+
fn try_into_py(self, py: pyo3::Python) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
26752675
match self {
26762676
Self::Starred(s) => s.try_into_py(py),
26772677
Self::Simple { value, comma } => {
@@ -2699,8 +2699,8 @@ mod py {
26992699
}
27002700

27012701
// TODO: this could be a derive helper attribute to override the python class name
2702-
impl<'a> TryIntoPy<pyo3::PyObject> for DictElement<'a> {
2703-
fn try_into_py(self, py: pyo3::Python) -> pyo3::PyResult<pyo3::PyObject> {
2702+
impl<'a> TryIntoPy<pyo3::Py<pyo3::PyAny>> for DictElement<'a> {
2703+
fn try_into_py(self, py: pyo3::Python) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
27042704
match self {
27052705
Self::Starred(s) => s.try_into_py(py),
27062706
Self::Simple {

native/libcst/src/nodes/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ macro_rules! py_import {
1717
( $module_name:expr, $member_name:expr, $getter_fn:ident ) => {
1818
paste::paste! {
1919
static [<IMPORT_CELL_ $getter_fn:snake:upper>]
20-
: pyo3::once_cell::GILOnceCell<pyo3::PyResult<pyo3::PyObject>>
21-
= pyo3::once_cell::GILOnceCell::new();
20+
: pyo3::once_cell::PyOnceLock<pyo3::PyResult<pyo3::Py<pyo3::PyAny>>>
21+
= pyo3::once_cell::PyOnceLock::new();
2222

2323
fn $getter_fn<'py>(py: pyo3::Python<'py>) -> pyo3::PyResult<&'py pyo3::PyAny> {
2424
Ok([<IMPORT_CELL_ $getter_fn:snake:upper>].get_or_init(py, || {

native/libcst/src/nodes/parser_config.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ impl BaseWhitespaceParserConfig {
2929
}
3030

3131
#[getter]
32-
fn get_lines(&self, py: Python) -> PyObject {
32+
fn get_lines(&self, py: Python) -> Py<PyAny> {
3333
self.lines.to_object(py)
3434
}
3535

3636
#[getter]
37-
fn get_default_newline(&self, py: Python) -> PyObject {
37+
fn get_default_newline(&self, py: Python) -> Py<PyAny> {
3838
self.default_newline.to_object(py)
3939
}
4040
}
@@ -62,36 +62,36 @@ impl BaseWhitespaceParserConfig {
6262
}
6363
}
6464

65-
// These fields are private and PyObject, since we don't currently care about using them from
65+
// These fields are private and Py<PyAny>, since we don't currently care about using them from
6666
// within rust.
6767
#[pyclass(extends=BaseWhitespaceParserConfig, module="libcst_native.parser_config")]
6868
#[text_signature = "(*, lines, encoding, default_indent, default_newline, has_trailing_newline, version, future_imports)"]
6969
pub struct ParserConfig {
7070
// lines is inherited
7171
#[pyo3(get)]
72-
encoding: PyObject,
72+
encoding: Py<PyAny>,
7373
#[pyo3(get)]
74-
default_indent: PyObject,
74+
default_indent: Py<PyAny>,
7575
// default_newline is inherited
7676
#[pyo3(get)]
77-
has_trailing_newline: PyObject,
77+
has_trailing_newline: Py<PyAny>,
7878
#[pyo3(get)]
79-
version: PyObject,
79+
version: Py<PyAny>,
8080
#[pyo3(get)]
81-
future_imports: PyObject,
81+
future_imports: Py<PyAny>,
8282
}
8383

8484
#[pymethods]
8585
impl ParserConfig {
8686
#[new]
8787
fn new(
8888
lines: &PySequence,
89-
encoding: PyObject,
90-
default_indent: PyObject,
89+
encoding: Py<PyAny>,
90+
default_indent: Py<PyAny>,
9191
default_newline: &PyString,
92-
has_trailing_newline: PyObject,
93-
version: PyObject,
94-
future_imports: PyObject,
92+
has_trailing_newline: Py<PyAny>,
93+
version: Py<PyAny>,
94+
future_imports: Py<PyAny>,
9595
) -> PyResult<(Self, BaseWhitespaceParserConfig)> {
9696
Ok((
9797
Self {

native/libcst/src/nodes/py_cached.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use pyo3::prelude::*;
77
use std::convert::AsRef;
88
use std::ops::Deref;
99

10-
/// An immutable wrapper around a rust type T and it's PyObject equivalent. Caches the conversion
11-
/// to and from the PyObject.
10+
/// An immutable wrapper around a rust type T and its Py<PyAny> equivalent. Caches the conversion
11+
/// to and from the Py<PyAny>.
1212
pub struct PyCached<T> {
1313
native: T,
14-
py_object: PyObject,
14+
py_object: Py<PyAny>,
1515
}
1616

1717
impl<T> PyCached<T>
@@ -31,7 +31,7 @@ where
3131
T: FromPyObject<'source>,
3232
{
3333
fn extract(ob: &'source PyAny) -> PyResult<Self> {
34-
Python::with_gil(|py| {
34+
Python::attach(|py| {
3535
Ok(PyCached {
3636
native: ob.extract()?,
3737
py_object: ob.to_object(py),
@@ -40,14 +40,14 @@ where
4040
}
4141
}
4242

43-
impl<T> IntoPy<PyObject> for PyCached<T> {
44-
fn into_py(self, _py: Python) -> PyObject {
43+
impl<T> IntoPy<Py<PyAny>> for PyCached<T> {
44+
fn into_py(self, _py: Python) -> Py<PyAny> {
4545
self.py_object
4646
}
4747
}
4848

4949
impl<T> ToPyObject for PyCached<T> {
50-
fn to_object(&self, py: Python) -> PyObject {
50+
fn to_object(&self, py: Python) -> Py<PyAny> {
5151
self.py_object.clone_ref(py)
5252
}
5353
}
@@ -71,6 +71,6 @@ where
7171
T: ToPyObject,
7272
{
7373
fn from(val: T) -> Self {
74-
Python::with_gil(|py| Self::new(py, val))
74+
Python::attach(|py| Self::new(py, val))
7575
}
7676
}

native/libcst/src/nodes/traits.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, T: Inflate<'a>> Inflate<'a> for Vec<T> {
118118
}
119119
#[cfg(feature = "py")]
120120
pub mod py {
121-
use pyo3::{types::PyTuple, IntoPyObjectExt, PyObject, PyResult, Python};
121+
use pyo3::{types::PyTuple, IntoPyObjectExt, Py, PyAny, PyResult, Python};
122122

123123
// TODO: replace with upstream implementation once
124124
// https://github.com/PyO3/pyo3/issues/1813 is resolved
@@ -133,38 +133,38 @@ pub mod py {
133133
// }
134134
// }
135135

136-
impl TryIntoPy<PyObject> for bool {
137-
fn try_into_py(self, py: Python) -> PyResult<PyObject> {
136+
impl TryIntoPy<Py<PyAny>> for bool {
137+
fn try_into_py(self, py: Python) -> PyResult<Py<PyAny>> {
138138
self.into_py_any(py)
139139
}
140140
}
141141

142-
impl<T: TryIntoPy<PyObject>> TryIntoPy<PyObject> for Box<T>
142+
impl<T: TryIntoPy<Py<PyAny>>> TryIntoPy<Py<PyAny>> for Box<T>
143143
where
144-
T: TryIntoPy<PyObject>,
144+
T: TryIntoPy<Py<PyAny>>,
145145
{
146-
fn try_into_py(self, py: Python) -> PyResult<PyObject> {
146+
fn try_into_py(self, py: Python) -> PyResult<Py<PyAny>> {
147147
(*self).try_into_py(py)
148148
}
149149
}
150150

151-
impl<T> TryIntoPy<PyObject> for Option<T>
151+
impl<T> TryIntoPy<Py<PyAny>> for Option<T>
152152
where
153-
T: TryIntoPy<PyObject>,
153+
T: TryIntoPy<Py<PyAny>>,
154154
{
155-
fn try_into_py(self, py: Python) -> PyResult<PyObject> {
155+
fn try_into_py(self, py: Python) -> PyResult<Py<PyAny>> {
156156
Ok(match self {
157157
None => py.None(),
158158
Some(x) => x.try_into_py(py)?,
159159
})
160160
}
161161
}
162162

163-
impl<T> TryIntoPy<PyObject> for Vec<T>
163+
impl<T> TryIntoPy<Py<PyAny>> for Vec<T>
164164
where
165-
T: TryIntoPy<PyObject>,
165+
T: TryIntoPy<Py<PyAny>>,
166166
{
167-
fn try_into_py(self, py: Python) -> PyResult<PyObject> {
167+
fn try_into_py(self, py: Python) -> PyResult<Py<PyAny>> {
168168
let converted = self
169169
.into_iter()
170170
.map(|x| x.try_into_py(py))
@@ -174,8 +174,8 @@ pub mod py {
174174
}
175175
}
176176

177-
impl<'a> TryIntoPy<PyObject> for &'a str {
178-
fn try_into_py(self, py: Python) -> PyResult<PyObject> {
177+
impl<'a> TryIntoPy<Py<PyAny>> for &'a str {
178+
fn try_into_py(self, py: Python) -> PyResult<Py<PyAny>> {
179179
self.into_py_any(py)
180180
}
181181
}

native/libcst/src/parser/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mod py_error {
3535

3636
impl<'a> From<ParserError<'a>> for PyErr {
3737
fn from(e: ParserError) -> Self {
38-
Python::with_gil(|py| {
38+
Python::attach(|py| {
3939
let lines = match &e {
4040
ParserError::TokenizerError(_, text) | ParserError::ParserError(_, text) => {
4141
text.lines().collect::<Vec<_>>()

native/libcst/src/py.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ use pyo3::prelude::*;
1111
pub fn libcst_native(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
1212
#[pyfn(m)]
1313
#[pyo3(signature = (source, encoding=None))]
14-
fn parse_module(source: String, encoding: Option<&str>) -> PyResult<PyObject> {
14+
fn parse_module(source: String, encoding: Option<&str>) -> PyResult<Py<PyAny>> {
1515
let m = crate::parse_module(source.as_str(), encoding)?;
16-
Python::with_gil(|py| m.try_into_py(py))
16+
Python::attach(|py| m.try_into_py(py))
1717
}
1818

1919
#[pyfn(m)]
20-
fn parse_expression(source: String) -> PyResult<PyObject> {
20+
fn parse_expression(source: String) -> PyResult<Py<PyAny>> {
2121
let expr = crate::parse_expression(source.as_str())?;
22-
Python::with_gil(|py| expr.try_into_py(py))
22+
Python::attach(|py| expr.try_into_py(py))
2323
}
2424

2525
#[pyfn(m)]
26-
fn parse_statement(source: String) -> PyResult<PyObject> {
26+
fn parse_statement(source: String) -> PyResult<Py<PyAny>> {
2727
let stm = crate::parse_statement(source.as_str())?;
28-
Python::with_gil(|py| stm.try_into_py(py))
28+
Python::attach(|py| stm.try_into_py(py))
2929
}
3030

3131
Ok(())

0 commit comments

Comments
 (0)