guide: better document negative index behavior w.r.t. PySequence

Fixes #2601
This commit is contained in:
Georg Brandl 2022-11-19 07:46:35 +01:00
parent 740cfa0057
commit 77f5fc107e
1 changed files with 8 additions and 1 deletions

View File

@ -243,18 +243,25 @@ Use the `#[pyclass(sequence)]` annotation to instruct PyO3 to fill the `sq_lengt
Implements retrieval of the `self[a]` element.
*Note:* Negative integer indexes are not handled specially.
*Note:* Negative integer indexes are not handled specially by PyO3.
However, for classes with `#[pyclass(sequence)]`, when a negative index is
accessed via `PySequence::get_item`, the underlying C API already adjusts
the index to be positive.
- `__setitem__(<self>, object, object) -> ()`
Implements assignment to the `self[a]` element.
Should only be implemented if elements can be replaced.
Same behavior regarding negative indices as for `__getitem__`.
- `__delitem__(<self>, object) -> ()`
Implements deletion of the `self[a]` element.
Should only be implemented if elements can be deleted.
Same behavior regarding negative indices as for `__getitem__`.
* `fn __concat__(&self, other: impl FromPyObject) -> PyResult<impl ToPyObject>`
Concatenates two sequences.