Skip to content

Commit

Permalink
gh-38944: no longer ignore errors in method union of DisjointSet
Browse files Browse the repository at this point in the history
    
Fixes #38939.

This PR changes the declaration of method `union` from `noexcept` to
`except *` to properly raise errors.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - #12345: short description why this is a dependency -->
<!-- - #34567: ... -->
    
URL: #38944
Reported by: David Coudert
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Nov 14, 2024
2 parents c7e2e48 + e93a360 commit 5c957f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/sage/sets/disjoint_set.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class):
cdef list _int_to_el
cdef dict _el_to_int
cpdef find(self, e)
cpdef void union(self, e, f) noexcept
cpdef void union(self, e, f) except *
cpdef root_to_elements_dict(self)
cpdef element_to_root_dict(self)
cpdef to_digraph(self)
5 changes: 3 additions & 2 deletions src/sage/sets/disjoint_set.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class):
cdef int r = <int> OP_find(self._nodes, i)
return self._int_to_el[r]

cpdef void union(self, e, f) noexcept:
cpdef void union(self, e, f) except *:
r"""
Combine the set of ``e`` and the set of ``f`` into one.
Expand Down Expand Up @@ -861,8 +861,9 @@ cdef class DisjointSet_of_hashables(DisjointSet_class):
sage: e
{{'a', 'b', 'c', 'e'}, {'d'}}
sage: e.union('a', 2**10)
KeyError: 1024
Traceback (most recent call last):
...
KeyError: 1024
"""
cdef int i = <int> self._el_to_int[e]
cdef int j = <int> self._el_to_int[f]
Expand Down

0 comments on commit 5c957f8

Please sign in to comment.