diff options
author | Lauro Neto <lauro.neto@openbossa.org> | 2011-02-11 18:18:14 -0300 |
---|---|---|
committer | Lauro Neto <lauro.neto@openbossa.org> | 2011-02-11 19:32:41 -0300 |
commit | 0298a342892684f9832fb840574d30e254360e5c (patch) | |
tree | cf8132a5afa83f4a2c8c440b2b0c7e96ddc55d8d | |
parent | 7b4d24f09459d3005314e366f13d3473c4236019 (diff) | |
download | pyside-0298a342892684f9832fb840574d30e254360e5c.tar.gz pyside-0298a342892684f9832fb840574d30e254360e5c.tar.xz pyside-0298a342892684f9832fb840574d30e254360e5c.zip |
Raise error when slot argument is unknown.
Instead of accepting it silently and generating potential
segfault and undefined behavior, raise TypeError when
the type of an argument is unknown to PySide type system.
An example of such erratic behavior is in declarations like:
@Slot
def foo(self):
Slots without arguments must be explicitly declared this way:
@Slot()
def foo(self):
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Reviewer: Hugo Lima <hugo.lima@openbossa.org>
-rw-r--r-- | libpyside/pysideslot.cpp | 3 | ||||
-rw-r--r-- | tests/signals/decorators_test.py | 9 |
2 files changed, 12 insertions, 0 deletions
diff --git a/libpyside/pysideslot.cpp b/libpyside/pysideslot.cpp index 7d22ca9..28c6ed6 100644 --- a/libpyside/pysideslot.cpp +++ b/libpyside/pysideslot.cpp @@ -121,6 +121,9 @@ int slotTpInit(PyObject *self, PyObject *args, PyObject *kw) } else { data->args = typeName; } + } else { + PyErr_Format(PyExc_TypeError, "Unknown signal argument type: %s", argType->ob_type->tp_name); + return -1; } } diff --git a/tests/signals/decorators_test.py b/tests/signals/decorators_test.py index c4497ab..b25e129 100644 --- a/tests/signals/decorators_test.py +++ b/tests/signals/decorators_test.py @@ -56,5 +56,14 @@ class StaticMetaObjectTest(unittest.TestCase): m = mo.method(i) self.assertEqual(m.typeName(), "int") + +class SlotWithoutArgs(unittest.TestCase): + + def testError(self): + # It should be an error to call the slot without the + # arguments, as just @Slot would end up in a slot + # accepting argument functions + self.assertRaises(TypeError, Slot, lambda: 3) + if __name__ == '__main__': unittest.main() |