Review conversions and ensure consistency
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Continued from https://github.com/PyO3/pyo3/pull/3197#discussion_r1225910628
We would like to ensure that we're consistent in how conversions from Python objects to Rust objects select for what's allowed.
I think the right approach would be to do something like https://github.com/PyO3/pyo3/blob/main/guide/src/conversions/tables.md where for each Rust type we state what Python types will convert to it (i.e. FromPyObject), and what Python type(s) it will convert back into (i.e. IntoPy<PyObject>).
That information does live on that page, but perhaps it can benefit from being rearranged.
In general we seem to be preferring conversions which are allow the user to be a bit loose with typing (e.g. string for IP address). So I think we should ensure we stick to this philosophy everywhere (e.g. maybe we should accept int for bool, or even all truthy types)?
We may also wish to consider a "strict" mode where only the exact Python type can be input (e.g. Python bool <-> Rust bool).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the discussion in pull request 3197 and the conversion table at guide/src/conversions/tables.md. Review the documented FromPyObject and IntoPy behavior for each Rust type, then identify inconsistencies in accepted Python types and whether a strict mode is within scope. Done means the conversion policy is agreed and consistently documented or implemented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- backend-api-design, documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100