Merge pull request #2751 from PyO3/2601-fix
guide: better document negative index behavior w.r.t. PySequence
This commit is contained in:
commit
6af46596e0
|
@ -243,18 +243,25 @@ Use the `#[pyclass(sequence)]` annotation to instruct PyO3 to fill the `sq_lengt
|
||||||
|
|
||||||
Implements retrieval of the `self[a]` element.
|
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) -> ()`
|
- `__setitem__(<self>, object, object) -> ()`
|
||||||
|
|
||||||
Implements assignment to the `self[a]` element.
|
Implements assignment to the `self[a]` element.
|
||||||
Should only be implemented if elements can be replaced.
|
Should only be implemented if elements can be replaced.
|
||||||
|
|
||||||
|
Same behavior regarding negative indices as for `__getitem__`.
|
||||||
|
|
||||||
- `__delitem__(<self>, object) -> ()`
|
- `__delitem__(<self>, object) -> ()`
|
||||||
|
|
||||||
Implements deletion of the `self[a]` element.
|
Implements deletion of the `self[a]` element.
|
||||||
Should only be implemented if elements can be deleted.
|
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>`
|
* `fn __concat__(&self, other: impl FromPyObject) -> PyResult<impl ToPyObject>`
|
||||||
|
|
||||||
Concatenates two sequences.
|
Concatenates two sequences.
|
||||||
|
|
Loading…
Reference in New Issue