Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 47a2258

Browse files
committed
fix: cargo build warnings
1 parent 797a384 commit 47a2258

6 files changed

Lines changed: 36 additions & 46 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["xonsh_tokenizer", "rs-ply"]
44

55
[workspace.dependencies]
6-
pyo3 = { version = "0.23.*", features = [
6+
pyo3 = { version = "0.27.*", features = [
77
"extension-module",
88
"experimental-inspect",
99
] }

ply_parser/ply/lrparser.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,8 @@ def load_parser(parser_table: Path | str, module: ParserProtocol) -> Union[LRPar
587587
parser_table = str(parser_table)
588588

589589
if HAS_RS_PLY and parser_table.endswith(".jsonl"):
590-
try:
591-
fsm = RustStateMachine.new_from_file(parser_table)
592-
return RustLRParser(fsm, module, errorf=getattr(module, "p_error", None))
593-
except Exception:
594-
pass
590+
fsm = RustStateMachine.new_from_file(parser_table)
591+
return RustLRParser(fsm, module, errorf=getattr(module, "p_error", None))
595592

596593
fsm = StateMachine(parser_table)
597594
return LRParser(fsm, errorf=getattr(module, "p_error", None), module=module)

rs-ply/src/lrparser.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use pyo3::prelude::*;
88
#[derive(Debug)]
99
pub struct LRParser {
1010
pub fsm: Py<StateMachine>,
11-
pub errorf: Option<PyObject>,
12-
pub module: PyObject,
11+
pub errorf: Option<Py<PyAny>>,
12+
pub module: Py<PyAny>,
1313
pub errorok: bool,
1414
pub state: u16,
1515
}
@@ -18,7 +18,7 @@ pub struct LRParser {
1818
impl LRParser {
1919
#[new]
2020
#[pyo3(signature = (fsm, module, errorf=None))]
21-
fn new(fsm: Py<StateMachine>, module: PyObject, errorf: Option<PyObject>) -> Self {
21+
fn new(fsm: Py<StateMachine>, module: Py<PyAny>, errorf: Option<Py<PyAny>>) -> Self {
2222
LRParser {
2323
fsm,
2424
errorf,
@@ -36,7 +36,7 @@ impl LRParser {
3636
lexer: Option<Bound<'py, PyAny>>,
3737
debug: u8,
3838
tracking: bool,
39-
) -> PyResult<PyObject> {
39+
) -> PyResult<Py<PyAny>> {
4040
let lexer = lexer
4141
.ok_or_else(|| PyErr::new::<pyo3::exceptions::PyValueError, _>("Lexer is required"))?;
4242

@@ -105,7 +105,7 @@ impl LRParser {
105105
lookahead = Some(end_sym);
106106
} else {
107107
let r#type: String = tok.getattr("type")?.extract()?;
108-
let value: PyObject = tok.getattr("value")?.extract()?;
108+
let value: Py<PyAny> = tok.getattr("value")?.extract()?;
109109
let lineno: Option<usize> =
110110
tok.getattr("lineno").ok().and_then(|a| a.extract().ok());
111111
let lexpos: Option<usize> =

rs-ply/src/yacc_types.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use pyo3::prelude::*;
77
#[derive(Debug)]
88
pub struct YaccSymbol {
99
pub r#type: String,
10-
pub value: Option<PyObject>,
10+
pub value: Option<Py<PyAny>>,
1111
pub lineno: Option<usize>,
1212
pub lexpos: Option<usize>,
1313
pub endlineno: Option<usize>,
@@ -20,7 +20,7 @@ impl YaccSymbol {
2020
#[pyo3(signature = (r#type, value=None, lineno=None, lexpos=None, endlineno=None, endlexpos=None))]
2121
pub fn new(
2222
r#type: String,
23-
value: Option<PyObject>,
23+
value: Option<Py<PyAny>>,
2424
lineno: Option<usize>,
2525
lexpos: Option<usize>,
2626
endlineno: Option<usize>,
@@ -48,9 +48,9 @@ impl YaccSymbol {
4848
#[pyclass(get_all, set_all)]
4949
pub struct YaccProduction {
5050
// The lexer that produced the token stream
51-
pub lexer: PyObject,
51+
pub lexer: Py<PyAny>,
5252
// The parser that is running this production
53-
pub parser: PyObject,
53+
pub parser: Py<PyAny>,
5454
// The slice of the input stream that is covered by this production
5555
pub slice: Vec<Py<YaccSymbol>>,
5656
pub stack: Vec<Py<YaccSymbol>>,
@@ -59,7 +59,7 @@ pub struct YaccProduction {
5959
#[pymethods]
6060
impl YaccProduction {
6161
#[new]
62-
pub fn new(lexer: PyObject, parser: PyObject) -> Self {
62+
pub fn new(lexer: Py<PyAny>, parser: Py<PyAny>) -> Self {
6363
YaccProduction {
6464
lexer,
6565
parser,
@@ -68,7 +68,7 @@ impl YaccProduction {
6868
}
6969
}
7070

71-
fn __getitem__<'py>(&self, py: Python<'py>, n: Bound<'py, PyAny>) -> PyResult<PyObject> {
71+
fn __getitem__<'py>(&self, py: Python<'py>, n: Bound<'py, PyAny>) -> PyResult<Py<PyAny>> {
7272
if let Ok(index) = n.extract::<isize>() {
7373
let sym_py = if index >= 0 {
7474
self.slice.get(index as usize).ok_or_else(|| {
@@ -94,7 +94,7 @@ impl YaccProduction {
9494
.unwrap_or_else(|| py.None()));
9595
}
9696

97-
if let Ok(sl) = n.downcast::<pyo3::types::PySlice>() {
97+
if let Ok(sl) = n.cast::<pyo3::types::PySlice>() {
9898
let indices = sl.indices(self.slice.len() as isize)?;
9999
let mut result = Vec::new();
100100
let mut cur = indices.start;
@@ -111,7 +111,7 @@ impl YaccProduction {
111111
);
112112
cur += indices.step;
113113
}
114-
return Ok(result.into_py(py));
114+
return Ok(result.into_pyobject(py)?.unbind());
115115
}
116116

117117
Err(pyo3::exceptions::PyTypeError::new_err(
@@ -123,7 +123,7 @@ impl YaccProduction {
123123
&mut self,
124124
py: Python<'py>,
125125
index: usize,
126-
value: Option<PyObject>,
126+
value: Option<Py<PyAny>>,
127127
) -> PyResult<()> {
128128
let sym_py = self.slice.get_mut(index).ok_or_else(|| {
129129
PyIndexError::new_err(format!("Index out of range in production slice: {}", index))

xonsh_tokenizer/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ impl PyTokInfo {
4040
))
4141
}
4242

43-
fn __getattr__<'py>(slf: PyRef<'py, Self>, py: Python<'py>, name: &str) -> PyResult<PyObject> {
43+
fn __getattr__<'py>(slf: PyRef<'py, Self>, py: Python<'py>, name: &str) -> PyResult<Py<PyAny>> {
4444
let obj = match name {
4545
"type" => format!("{:?}", slf.inner.typ)
4646
.to_shouty_snake_case()
47-
.into_py(py),
48-
"start" => slf.inner.start.clone().into_py(py),
49-
"end" => slf.inner.end.clone().into_py(py),
50-
"span" => slf.inner.span.clone().into_py(py),
47+
.into_pyobject(py)?
48+
.into_any(),
49+
"start" => slf.inner.start.clone().into_pyobject(py)?.into_any(),
50+
"end" => slf.inner.end.clone().into_pyobject(py)?.into_any(),
51+
"span" => slf.inner.span.clone().into_pyobject(py)?.into_any(),
5152
_ => return Err(PyTypeError::new_err(format!("Unknown attribute: {}", name))),
5253
};
53-
Ok(obj)
54+
Ok(obj.into())
5455
}
5556

5657
fn is_exact_type(&self, typ: &str) -> bool {

0 commit comments

Comments
 (0)