Jij-Inc / pyo3-stub-gen

Stub file (*.pyi) generator for PyO3
Apache License 2.0
56 stars 11 forks source link

Compile error for functions with `&str` argument #22

Closed aldanor closed 2 months ago

aldanor commented 3 months ago
/// Returns the length of the string.
#[gen_stub_pyfunction]
#[pyfunction]
fn f(x: &str) -> PyResult<usize> {
    Ok(x.len())
}

results in

error[E0277]: the trait bound `&str: pyo3::FromPyObject<'_>` is not satisfied
  --> pyo3-stub-gen-testing-pure/src/lib.rs:24:9
   |
24 | fn f(x: &str) -> PyResult<usize> {
   |         ^^^^ the trait `PyClass` is not implemented for `&str`, which is required by `&str: pyo3::FromPyObject<'_>`
   |
   = help: the following other types implement trait `pyo3::FromPyObject<'py>`:
             <(T0, T1) as pyo3::FromPyObject<'py>>
             <(T0, T1, T2) as pyo3::FromPyObject<'py>>
             <(T0, T1, T2, T3) as pyo3::FromPyObject<'py>>
             <(T0, T1, T2, T3, T4) as pyo3::FromPyObject<'py>>
             <(T0, T1, T2, T3, T4, T5) as pyo3::FromPyObject<'py>>
             <(T0, T1, T2, T3, T4, T5, T6) as pyo3::FromPyObject<'py>>
             <(T0, T1, T2, T3, T4, T5, T6, T7) as pyo3::FromPyObject<'py>>
             <(T0, T1, T2, T3, T4, T5, T6, T7, T8) as pyo3::FromPyObject<'py>>
           and 53 others
   = note: required for `&str` to implement `pyo3::FromPyObject<'_>`
termoshtt commented 2 months ago

This has been fixed via #37, and tested in #49. Thanks report!