AndrejOrsula / pyo3_bindgen

Automatic Python —> Rust FFI bindings
Apache License 2.0
11 stars 2 forks source link

Function default values #27

Open NiklasVousten opened 2 months ago

NiklasVousten commented 2 months ago

The rust function signature did not allow default values. Instead the user had to know these values to fill them in.

Every paramter, that has a default value, will now be wrapped inside an option. A user can this then set to None. If this option is None, it will be excluded from the kwargs dict, and thus the default value will be used.

Furthermore, the Optional Value from typing is excluded.

I am not sure if everything was done correctly and every occurence was changed. There might be edge cases where this will break, however on the tested examples this worked fine.

NiklasVousten commented 2 months ago

The pipeline is now failing with the same clippy issues as the last commit on main.

So I assume all issues on my side are fixed

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.

Project coverage is 66.73%. Comparing base (cd5f278) to head (149c0c7). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pyo3_bindgen_engine/src/syntax/function.rs 89.65% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #27 +/- ## ========================================== + Coverage 66.55% 66.73% +0.18% ========================================== Files 22 22 Lines 3199 3223 +24 ========================================== + Hits 2129 2151 +22 - Misses 1070 1072 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

AndrejOrsula commented 2 months ago

Also, the tooling/test suite in the repository is generally lacking. Maybe you already found something better, but this helped me debug specific cases (not optimal, yet better than what is included...).

  1. Include the following in pyo3_bindgen_engine/src/lib.rs:
mod test;
  1. Iterate with this (either inside a script or as a one-liner):
rm ./pyo3_bindgen_engine/src/test.rs
touch ./pyo3_bindgen_engine/src/test.rs
cargo run -- -m <decently_complex_python_module> -o ./pyo3_bindgen_engine/src/test.rs
cargo fmt
cargo check