pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

Guide docs for all protocol methods

Open davidhewitt opened this issue 5 years ago • 6 comments
trafficstars

Just thinking that for the guide it would be nice to add a table to the #[pyproto] section listing all the dunder methods that can be implemented and the protocols they are a part of (e.g. __int__ -> PyNumberProtocol etc.)

davidhewitt avatar Jul 09 '20 21:07 davidhewitt

Please note for anyone who looks at this that the #[pyproto] methods are planned to be merged into #[pymethods], see #1206

davidhewitt avatar Jul 04 '21 21:07 davidhewitt

After #[pymethods] are ready, the docs we need will probably be very similar to these excellent ones for Cython: https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html

davidhewitt avatar Sep 17 '21 07:09 davidhewitt

I volunteer for that.

birkenfeld avatar Sep 20 '21 05:09 birkenfeld

Thanks! I think @mejrs also expressed desire to write something in #1864 ? You might want to double-check you don't end up duplicating effort.

davidhewitt avatar Sep 20 '21 07:09 davidhewitt

I'm leaning towards this:

  • A table at https://pyo3.rs/main/doc/pyo3/attr.pymethods.html summarizing all the dunders like https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html#special-method-table
  • Examples in the guide, like https://pyo3.rs/main/class.html?#callable-objects We might want to structure that in a different way .e.g. a chapter for each protocol.

mejrs avatar Sep 20 '21 12:09 mejrs

Sounds good to me. There is extensive material on the Python side on how these protocols work, and we should mainly state what we support and what the Rust/PyO3-specific snags are.

birkenfeld avatar Sep 21 '21 06:09 birkenfeld

We now have https://pyo3.rs/v0.20.0/class/protocols, plus some more detailed examples by @mejrs and @birkenfeld for specific protocols. I'm going to close this one as resolved, though of course more documentation improvements are always possible!

davidhewitt avatar Nov 28 '23 08:11 davidhewitt