Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix support of sequence protocol for returned lists (#730)
* Fix support of sequence protocol for returned lists Add the `sequence` option to PyO3's `pyclass`, so that the `sq_length` slot is implemented [1]. Implementing this method is required for sequence types, or Python C API functions like `PySequence_Size` will fail with an error. The `reversed` built-in method relies on `PySequence_*` methods. A test reversing `NodeIndices` is added to guard against future violations of the sequence protocol. Fixes #696. [1]: PyO3/pyo3#2567 * Add release note Co-authored-by: Matthew Treinish <mtreinish@kortar.org> (cherry picked from commit 4592bc0)
- Loading branch information
1 parent
17c178f
commit 3a696a6
Showing
3 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
releasenotes/notes/fix-sequence-protocol-e95246e864cc850a.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixed an issue with the custom sequence return types, | ||
:class:`~.BFSSuccessors`, :class:`~.NodeIndices`, :class:`~.EdgeList`, | ||
:class:`~.WeightedEdgeList`, :class:`~.EdgeIndices`, and :class:`~.Chains` | ||
where they previosuly were missing certain attributes that prevented them | ||
being used as a sequence for certain built-in functions such as | ||
``reversed()``. | ||
Fixed `#696 <https://github.com/Qiskit/rustworkx/issues/696>`__. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters