Skip to content

Commit

Permalink
Add some excepts (#1)
Browse files Browse the repository at this point in the history
For C-return-type functions that raise exceptions (and their heirs).
  • Loading branch information
gmou3 authored Aug 14, 2024
1 parent c4d3b66 commit 31d6a6b
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/sage/matroids/basis_exchange_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ cdef class BasisExchangeMatroid(Matroid):
cpdef _move_current_basis(self, X, Y)

cpdef frozenset _max_independent(self, frozenset F)
cpdef int _rank(self, frozenset F) noexcept
cpdef int _rank(self, frozenset F) except -1
cpdef frozenset _circuit(self, frozenset F)
cpdef frozenset _fundamental_circuit(self, frozenset B, e)
cpdef frozenset _closure(self, frozenset F)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/basis_exchange_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ cdef class BasisExchangeMatroid(Matroid):
self.__max_independent(self._output, self._input)
return self.__unpack(self._output)

cpdef int _rank(self, frozenset F) noexcept:
cpdef int _rank(self, frozenset F) except -1:
"""
Compute the rank of a subset of the groundset.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/circuit_closures_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cdef class CircuitClosuresMatroid(Matroid):
cdef dict _circuit_closures # _CC
cdef int _matroid_rank # _R
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) noexcept
cpdef int _rank(self, frozenset X) except -1
cpdef full_rank(self)
cpdef bint _is_independent(self, frozenset F) noexcept
cpdef frozenset _max_independent(self, frozenset F)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/circuit_closures_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ cdef class CircuitClosuresMatroid(Matroid):
"""
return frozenset(self._groundset)

cpdef int _rank(self, frozenset X) noexcept:
cpdef int _rank(self, frozenset X) except -1:
"""
Return the rank of a set ``X``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/circuits_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cdef class CircuitsMatroid(Matroid):
cdef list _sorted_C_lens
cdef bint _nsc_defined
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) noexcept
cpdef int _rank(self, frozenset X) except -1
cpdef full_rank(self)
cpdef bint _is_independent(self, frozenset X) noexcept
cpdef frozenset _max_independent(self, frozenset X)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/circuits_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cdef class CircuitsMatroid(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) noexcept:
cpdef int _rank(self, frozenset X) except -1:
"""
Return the rank of a set ``X``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/flats_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cdef class FlatsMatroid(Matroid):
cdef object _L # lattice of flats
cpdef frozenset groundset(self)

cpdef int _rank(self, frozenset X) noexcept
cpdef int _rank(self, frozenset X) except -1
cpdef frozenset _closure(self, frozenset X)
cpdef bint _is_closed(self, frozenset X) noexcept

Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/flats_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ cdef class FlatsMatroid(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) noexcept:
cpdef int _rank(self, frozenset X) except -1:
"""
Return the rank of a set ``X``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/graphic_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cdef class GraphicMatroid(Matroid):
cdef dict _vertex_map
cdef dict _groundset_edge_map
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) noexcept
cpdef int _rank(self, frozenset X) except -1
cpdef _vertex_stars(self)
cpdef _minor(self, contractions, deletions)
cpdef _has_minor(self, N, bint certificate=*)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/graphic_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ cdef class GraphicMatroid(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) noexcept:
cpdef int _rank(self, frozenset X) except -1:
"""
Return the rank of a set ``X``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cdef class Matroid(SageObject):

# virtual methods
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) noexcept
cpdef int _rank(self, frozenset X) except -1

# internal methods, assuming verified input
cpdef frozenset _max_independent(self, frozenset X)
Expand Down
7 changes: 4 additions & 3 deletions src/sage/matroids/matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ cdef class Matroid(SageObject):
"""
raise NotImplementedError("subclasses need to implement this")

cpdef int _rank(self, frozenset X) noexcept:
cpdef int _rank(self, frozenset X) except -1:
r"""
Return the rank of a set ``X``.
Expand All @@ -513,8 +513,9 @@ cdef class Matroid(SageObject):
sage: M = sage.matroids.matroid.Matroid()
sage: M._rank(frozenset([0, 1, 2]))
NotImplementedError: subclasses need to implement this
Traceback (most recent call last):
...
NotImplementedError: subclasses need to implement this
"""
raise NotImplementedError("subclasses need to implement this")

Expand Down Expand Up @@ -2338,7 +2339,7 @@ cdef class Matroid(SageObject):
TESTS::
sage: def r(X):
....: return -1
....: return -2
sage: M = Matroid(groundset=[0,1,2], rank_function=r)
sage: M.is_valid()
False
Expand Down
6 changes: 3 additions & 3 deletions src/sage/matroids/union_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ cdef class MatroidUnion(Matroid):
cdef list matroids
cdef frozenset _groundset
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) noexcept
cpdef int _rank(self, frozenset X) except -1

cdef class MatroidSum(Matroid):
cdef list summands
cdef frozenset _groundset
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) noexcept
cpdef int _rank(self, frozenset X) except -1

cdef class PartitionMatroid(Matroid):
cdef dict p
cdef frozenset _groundset
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) noexcept
cpdef int _rank(self, frozenset X) except -1
6 changes: 3 additions & 3 deletions src/sage/matroids/union_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cdef class MatroidUnion(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) noexcept:
cpdef int _rank(self, frozenset X) except -1:
r"""
Return the rank of a set ``X``.
Expand Down Expand Up @@ -195,7 +195,7 @@ cdef class MatroidSum(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) noexcept:
cpdef int _rank(self, frozenset X) except -1:
r"""
Return the rank of a set ``X``.
Expand Down Expand Up @@ -290,7 +290,7 @@ cdef class PartitionMatroid(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) noexcept:
cpdef int _rank(self, frozenset X) except -1:
r"""
Return the rank of a set ``X``.
Expand Down
4 changes: 2 additions & 2 deletions src/sage/sets/disjoint_set.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ cdef class DisjointSet_class(SageObject):
cpdef number_of_subsets(self)

cdef class DisjointSet_of_integers(DisjointSet_class):
cpdef int find(self, int i) noexcept
cpdef void union(self, int i, int j) noexcept
cpdef int find(self, int i) except -1
cpdef void union(self, int i, int j) except *
cpdef root_to_elements_dict(self)
cpdef element_to_root_dict(self)
cpdef to_digraph(self)
Expand Down
10 changes: 6 additions & 4 deletions src/sage/sets/disjoint_set.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class):
for i, parent in enumerate(l):
self.union(parent, i)

cpdef int find(self, int i) noexcept:
cpdef int find(self, int i) except -1:
r"""
Return the representative of the set that ``i`` currently belongs to.
Expand Down Expand Up @@ -479,8 +479,9 @@ cdef class DisjointSet_of_integers(DisjointSet_class):
sage: [e.find(i) for i in range(5)]
[0, 1, 1, 1, 1]
sage: e.find(2**10)
ValueError: i must be between 0 and 4 (1024 given)
Traceback (most recent call last):
...
ValueError: i must be between 0 and 4 (1024 given)
.. NOTE::
Expand All @@ -492,7 +493,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class):
raise ValueError('i must be between 0 and %s (%s given)' % (card - 1, i))
return OP_find(self._nodes, i)

cpdef void union(self, int i, int j) noexcept:
cpdef void union(self, int i, int j) except *:
r"""
Combine the set of ``i`` and the set of ``j`` into one.
Expand Down Expand Up @@ -520,8 +521,9 @@ cdef class DisjointSet_of_integers(DisjointSet_class):
sage: d
{{0, 1, 2, 4}, {3}}
sage: d.union(1, 5)
ValueError: j must be between 0 and 4 (5 given)
Traceback (most recent call last):
...
ValueError: j must be between 0 and 4 (5 given)
.. NOTE::
Expand Down

0 comments on commit 31d6a6b

Please sign in to comment.