From 4c83bc9bab4c36461294602ccce81f0df0691f1a Mon Sep 17 00:00:00 2001 From: Rui Luo Date: Wed, 16 Sep 2026 16:54:08 +0800 Subject: [PATCH 1/2] fix(cuda.core): preserve adjacency set semantics --- cuda_core/cuda/core/graph/_adjacency_set_proxy.pyx | 2 ++ .../tests/graph/test_graph_definition_mutation.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cuda_core/cuda/core/graph/_adjacency_set_proxy.pyx b/cuda_core/cuda/core/graph/_adjacency_set_proxy.pyx index 2c2c67e5005..225f75339a1 100644 --- a/cuda_core/cuda/core/graph/_adjacency_set_proxy.pyx +++ b/cuda_core/cuda/core/graph/_adjacency_set_proxy.pyx @@ -15,6 +15,7 @@ from cuda.core._rt cimport ( graph_node_get_graph, ) from cuda.core._utils.cuda_utils cimport HANDLE_RETURN +import cython from collections.abc import Iterable, Iterator, MutableSet, Set from typing import Any, TypeVar @@ -59,6 +60,7 @@ class AdjacencySetProxy(MutableSet[GraphNode]): return (<_AdjacencySetCore>self._core).add_edge(value) + @cython.annotation_typing(False) def discard(self, value: GraphNode) -> None: (<_AdjacencySetCore>self._core).check_owner_mutable() if value not in self: diff --git a/cuda_core/tests/graph/test_graph_definition_mutation.py b/cuda_core/tests/graph/test_graph_definition_mutation.py index 7542a50fa19..3b4e5e1185e 100644 --- a/cuda_core/tests/graph/test_graph_definition_mutation.py +++ b/cuda_core/tests/graph/test_graph_definition_mutation.py @@ -389,6 +389,20 @@ def test_add_wrong_type(init_cuda): node.succ.add(42) +@pytest.mark.agent_authored(model="gpt-5.6-sol") +def test_discard_wrong_type_is_noop(init_cuda): + """Discarding a non-GraphNode is a no-op, matching MutableSet semantics.""" + g = GraphDefinition() + owner = g.empty() + neighbor = g.empty() + owner.succ.add(neighbor) + + owner.succ.discard("not a node") + owner.succ.discard(42) + + assert owner.succ == {neighbor} + + @pytest.mark.agent_authored(model="gpt-5.6") def test_discard_absent_invalid_value_is_noop(init_cuda): graph = GraphDefinition() From 57c7a6822fd67d949e74d65db3888e20a0347e3d Mon Sep 17 00:00:00 2001 From: Rui Luo Date: Fri, 18 Sep 2026 09:21:08 +0800 Subject: [PATCH 2/2] docs(core): note adjacency discard behavior change --- cuda_core/docs/source/release/1.3.0-notes.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cuda_core/docs/source/release/1.3.0-notes.rst b/cuda_core/docs/source/release/1.3.0-notes.rst index 413465d8b3c..3ddf04b1ded 100644 --- a/cuda_core/docs/source/release/1.3.0-notes.rst +++ b/cuda_core/docs/source/release/1.3.0-notes.rst @@ -113,3 +113,8 @@ Fixes and enhancements - :attr:`Stream.device` and related queries on a stream whose context is not current now restore the caller's context even when the device query fails. + +- Calling ``discard()`` on the set-like :attr:`graph.GraphNode.pred` and + :attr:`graph.GraphNode.succ` views with an object that is not a + :class:`~graph.GraphNode` is now a no-op instead of raising ``TypeError``, + consistent with :class:`collections.abc.MutableSet` semantics.