diff --git a/Cargo.lock b/Cargo.lock index 48fa0c56d..22b74c543 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -278,7 +278,7 @@ dependencies = [ "ahash", "libc", "ndarray", - "num-complex 0.2.4", + "num-complex 0.4.1", "num-integer", "num-traits", "pyo3", @@ -352,9 +352,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.17.2" +version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201b6887e5576bf2f945fe65172c1fcbf3fcf285b23e4d71eb171d9736e38d32" +checksum = "268be0c73583c183f2b14052337465768c07726936a260f480f0857cb95ba543" dependencies = [ "cfg-if", "hashbrown", @@ -363,7 +363,7 @@ dependencies = [ "libc", "memoffset", "num-bigint", - "num-complex 0.2.4", + "num-complex 0.4.1", "parking_lot", "pyo3-build-config", "pyo3-ffi", @@ -373,9 +373,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.17.2" +version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf0708c9ed01692635cbf056e286008e5a2927ab1a5e48cdd3aeb1ba5a6fef47" +checksum = "28fcd1e73f06ec85bf3280c48c67e731d8290ad3d730f8be9dc07946923005c8" dependencies = [ "once_cell", "target-lexicon", @@ -383,9 +383,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.17.2" +version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90352dea4f486932b72ddf776264d293f85b79a1d214de1d023927b41461132d" +checksum = "0f6cb136e222e49115b3c51c32792886defbfb0adead26a688142b346a0b9ffc" dependencies = [ "libc", "pyo3-build-config", @@ -393,9 +393,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.17.2" +version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb24b804a2d9e88bfcc480a5a6dd76f006c1e3edaf064e8250423336e2cd79d" +checksum = "94144a1266e236b1c932682136dc35a9dee8d3589728f68130c7c3861ef96b28" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -405,9 +405,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.17.2" +version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22bb49f6a7348c253d7ac67a6875f2dc65f36c2ae64a82c381d528972bea6d6" +checksum = "c8df9be978a2d2f0cdebabb03206ed73b11314701a5bfe71b0d753b81997777f" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 193b2403e..44398438f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ serde_json = "1.0" rustworkx-core = { path = "rustworkx-core", version = "=0.12.0" } [dependencies.pyo3] -version = "0.17.2" +version = "0.17.3" features = ["extension-module", "hashbrown", "num-bigint", "num-complex", "indexmap"] [dependencies.hashbrown] diff --git a/releasenotes/notes/fix-sequence-protocol-e95246e864cc850a.yaml b/releasenotes/notes/fix-sequence-protocol-e95246e864cc850a.yaml new file mode 100644 index 000000000..4bfb6fe37 --- /dev/null +++ b/releasenotes/notes/fix-sequence-protocol-e95246e864cc850a.yaml @@ -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 `__. diff --git a/src/iterators.rs b/src/iterators.rs index 3a403d492..b6e496cc5 100644 --- a/src/iterators.rs +++ b/src/iterators.rs @@ -475,7 +475,7 @@ impl PyConvertToPyArray for Vec<(usize, usize, PyObject)> { macro_rules! custom_vec_iter_impl { ($name:ident, $data:ident, $T:ty, $doc:literal) => { #[doc = $doc] - #[pyclass(module = "rustworkx")] + #[pyclass(module = "rustworkx", sequence)] #[derive(Clone)] pub struct $name { pub $data: Vec<$T>, diff --git a/tests/rustworkx_tests/test_custom_return_types.py b/tests/rustworkx_tests/test_custom_return_types.py index 8abf87ae2..2362f125b 100644 --- a/tests/rustworkx_tests/test_custom_return_types.py +++ b/tests/rustworkx_tests/test_custom_return_types.py @@ -174,6 +174,12 @@ def test_slices_negatives(self): self.assertEqual([2, 3], slice_return) self.assertEqual([], indices[-1:-2]) + def test_reversed(self): + indices = self.dag.node_indices() + reversed_slice = indices[::-1] + reversed_elems = list(reversed(indices)) + self.assertEqual(reversed_slice, reversed_elems) + def test_numpy_conversion(self): res = self.dag.node_indexes() np.testing.assert_array_equal(np.asarray(res, dtype=np.uintp), np.array([0, 1]))