Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 6ff7168

Browse files
committed
raise TypeError instead of dgpyError in dg.plug
As, from the docs: > Passing arguments of the wrong type (e.g. passing a list when an int > is expected) should result in a TypeError. Thanks @jmirabel
1 parent 1c9e8d8 commit 6ff7168

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/dynamic_graph/dynamic-graph-py.cc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ namespace python {
1717
/**
1818
\brief plug a signal into another one.
1919
*/
20-
PyObject* plug(
21-
#if PY_MAJOR_VERSION >= 3
22-
PyObject* m, PyObject* args
23-
#else
24-
PyObject*, PyObject* args
25-
#endif
26-
) {
20+
PyObject* plug(PyObject* /*self*/, PyObject* args) {
2721
PyObject* objOut = NULL;
2822
PyObject* objIn = NULL;
2923
void* pObjOut;
@@ -47,21 +41,19 @@ PyObject* plug(
4741
pObjIn = PyCapsule_GetPointer(objIn, "dynamic_graph.Signal");
4842
SignalBase<int>* signalIn = (SignalBase<int>*)pObjIn;
4943
if (signalIn == NULL) {
50-
struct module_state* st = GETSTATE(m);
5144
std::ostringstream oss;
5245
oss << "dynamic_graph.plug(a, b): Argument 'b' must be of type 'dynamic_graph.Signal', but got "
5346
<< PyCapsule_GetName(objIn);
54-
PyErr_SetString(st->dgpyError, oss.str().c_str());
47+
PyErr_SetString(PyExc_TypeError, oss.str().c_str());
5548
return NULL;
5649
}
5750
pObjOut = PyCapsule_GetPointer(objOut, "dynamic_graph.Signal");
5851
SignalBase<int>* signalOut = (SignalBase<int>*)pObjOut;
5952
if (signalOut == NULL) {
60-
struct module_state* st = GETSTATE(m);
6153
std::ostringstream oss;
6254
oss << "dynamic_graph.plug(a, b): Argument 'a' must be of type 'dynamic_graph.Signal', but got "
6355
<< PyCapsule_GetName(objOut);
64-
PyErr_SetString(st->dgpyError, oss.str().c_str());
56+
PyErr_SetString(PyExc_TypeError, oss.str().c_str());
6557
return NULL;
6658
}
6759
std::ostringstream os;

unitTesting/test_bindings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def test_type_check(self):
2020
dg.plug(first.signal('out_double'), second.signal('in_double'))
2121

2222
# Check that we can't connect first.out to second
23-
with self.assertRaises(dg.dgpyError) as cm_in:
23+
with self.assertRaises(TypeError) as cm_in:
2424
dg.plug(first.signal('out_double'), second)
2525
self.assertEqual(str(cm_in.exception), ERR % 'b')
2626

2727
# Check that we can't connect first to second.in
28-
with self.assertRaises(dg.dgpyError) as cm_out:
28+
with self.assertRaises(TypeError) as cm_out:
2929
dg.plug(first, second.signal('in_double'))
3030
self.assertEqual(str(cm_out.exception), ERR % 'a')
3131

0 commit comments

Comments
 (0)