Jij-Inc / pyo3-stub-gen

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

New trait for creating stub file without `pyo3/experimental-inspect` feature #16

Closed termoshtt closed 3 months ago

termoshtt commented 3 months ago

experimental-inspect has very limited feature. For example, Option<String> should generate str | None (or Optional[str]) in stub file, but it generates Any.

aldanor commented 3 months ago

Option<> of anything seems to be mapping to PyAny 🙁 And it's quite typical to have in the signature for kwargs that default to None.

Also, Vec<T> and other containers doesn't seem to work either if T is a pyclass. E.g. if you have

#[pyclass]
struct X {}

#[pyclass]
struct Y {}

#[pyfunction]
fn f(x: Vec<X>) -> PyResult<Vec<Y>> {}

this will be encoded as

def f(x: Sequence[Any]) -> List[Any]: ...