Skip to content

Commit f3e581c

Browse files
Use the correct error types
1 parent b3c89bb commit f3e581c

15 files changed

Lines changed: 23 additions & 21 deletions

File tree

src/action.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Increase the capacity to a value that is greater or equal to *val*.
147147
:param val: new capacity of an action instance.
148148
:type val: int
149149
150-
:raises ValueError: if ``val`` is too large.
150+
:raises MemoryError: if ``val`` is too large.
151151
152152
:complexity:
153153
At most linear in the :any:`size()` of the :py:class:`Action`.

src/adapters.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ This call operator returns the image of *pt* acted on by *x*.
102102
:rtype: Point
103103
104104
:raises TypeError:
105-
If the wrapped C++ type of the sample objects passed via *element* and
105+
If the wrapped C++ type of the sample objects passed via *x* and
106106
*point* are not the same as the wrapped types of the arguments in any
107107
invocation of the call operator. For example, if *point* is ``PPerm([], [],
108108
256)``, then the underlying C++ type uses 8-bit integers to store image
@@ -171,7 +171,7 @@ This call operator returns the image of *pt* acted on by *x*.
171171
:rtype: Point
172172
173173
:raises TypeError:
174-
If the wrapped C++ type of the sample objects passed via *element* and
174+
If the wrapped C++ type of the sample objects passed via *x* and
175175
*point* are not the same as the wrapped types of the arguments in any
176176
invocation of the call operator. For example, if *point* is ``PPerm([], [],
177177
256)``, then the underlying C++ type uses 8-bit integers to store image

src/froidure-pin.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ Copy a :any:`FroidurePin` object.
132132
:returns: A copy.
133133
:rtype: FroidurePin
134134
)pbdoc");
135+
// This function should really throw a ValueError if the degree of x is
136+
// incompatible with the existing degree, but this doesn't get detected at
137+
// the Python level, so a LibsemigroupsError is thrown instead. It would
138+
// be possible to intercept this, but it probably isn't worth the effort.
135139
thing.def("add_generator",
136140
&FroidurePin_::add_generator,
137141
py::arg("x"),
@@ -166,7 +170,7 @@ elements than before (whether it is fully enumerating or not).
166170
:returns: ``self``.
167171
:rtype: FroidurePin
168172
169-
:raises ValueError:
173+
:raises LibsemigroupsError:
170174
if the degree of *x* is incompatible with the existing degree (if any).
171175
172176
:raises TypeError:
@@ -199,7 +203,7 @@ See :any:`add_generator` for a detailed description.
199203
:raises TypeError:
200204
if any item in *gens* is not of the same type as the existing generators (if any).
201205
202-
:raises ValueError:
206+
:raises LibsemigroupsError:
203207
if the degree of any item in *gens* is incompatible with the existing degree (if any).
204208
)pbdoc");
205209

src/libsemigroups_pybind11/action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def __init__(self: _Self, *args, generators=None, seeds=None, func=None, side=No
207207
if _to_cxx(self) is not None:
208208
return
209209
if len(args) != 0:
210-
raise ValueError(f"expected 0 positional arguments, but found {len(args)}")
210+
raise TypeError(f"expected 0 positional arguments, but found {len(args)}")
211211
if not isinstance(generators, list):
212212
raise TypeError(
213213
"expected the keyword argument 'generators' to be "

src/libsemigroups_pybind11/adapters.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def __init__(self: _Self, *args, point=None, element=None) -> None:
6868
if _to_cxx(self) is not None:
6969
return
7070
if len(args) != 0:
71-
raise ValueError(
72-
f"expected 0 positional arguments, but found {len(args)}"
73-
)
71+
raise TypeError(f"expected 0 positional arguments, but found {len(args)}")
7472
self.py_template_params = (
7573
type(_to_cxx(element)),
7674
type(_to_cxx(point)),

src/libsemigroups_pybind11/detail/cxx_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ def __init__(
8181

8282
for kwarg in required_kwargs:
8383
if kwarg not in kwargs:
84-
raise ValueError(
84+
raise TypeError(
8585
f'required keyword argument "{kwarg}" not found, '
8686
f"found {tuple(kwargs.keys())} instead"
8787
)
8888
for kwarg in kwargs:
8989
if kwarg not in required_kwargs and kwarg not in optional_kwargs:
90-
raise ValueError(
90+
raise TypeError(
9191
f'unexpected keyword argument "{kwarg}", '
9292
f"required keyword arguments are {required_kwargs} "
9393
f"and optional keyword arguments are {optional_kwargs}"

src/libsemigroups_pybind11/froidure_pin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(self: _Self, *args) -> None:
162162
if _to_cxx(self) is not None:
163163
return
164164
if len(args) == 0:
165-
raise ValueError("expected at least 1 argument, found 0")
165+
raise TypeError("expected at least 1 argument, found 0")
166166

167167
if isinstance(args[0], list) and len(args) == 1:
168168
gens = args[0]

src/libsemigroups_pybind11/konieczny.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(self: Self, *args) -> None:
130130
if _to_cxx(self) is not None:
131131
return
132132
if len(args) == 0:
133-
raise ValueError("expected at least 1 argument, found 0")
133+
raise TypeError("expected at least 1 argument, found 0")
134134

135135
if isinstance(args[0], list) and len(args) == 1:
136136
gens = args[0]

src/libsemigroups_pybind11/presentation/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self: Self, *args, **kwargs) -> None:
104104
or (len(args) == 1 and len(kwargs) > 0)
105105
or len(args) > 1
106106
):
107-
raise ValueError(
107+
raise TypeError(
108108
'expected 1 positional argument or the keyword argument "Word"'
109109
f" but found {len(args)} positional arguments, and keywords arguments "
110110
f"{tuple(kwargs.keys())}"
@@ -124,7 +124,7 @@ def __init__(self: Self, *args, **kwargs) -> None:
124124
f"but found {type(args[0])}"
125125
)
126126
if isinstance(args[0], list) and not all(isinstance(x, int) for x in args[0]):
127-
raise ValueError("expected the argument to consist of int values")
127+
raise TypeError("expected the argument to consist of int values")
128128
if isinstance(args[0], str):
129129
self.py_template_params = (str,)
130130
if isinstance(args[0], list):

src/libsemigroups_pybind11/schreier_sims.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self: _Self, *args) -> None:
7171
if _to_cxx(self) is not None:
7272
return
7373
if len(args) == 0:
74-
raise ValueError("expected at least 1 argument, found 0")
74+
raise TypeError("expected at least 1 argument, found 0")
7575

7676
if isinstance(args[0], list) and len(args) == 1:
7777
gens = args[0]

0 commit comments

Comments
 (0)