[pygi] Make the "wrong argument count" exception more explicit.
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygi] Make the "wrong argument count" exception more explicit.
- Date: Thu, 10 Jun 2010 07:32:38 +0000 (UTC)
commit 07df124dc06cf506634e95d08397f50a2d07fce2
Author: Steve Frécinaux <code istique net>
Date: Mon Jun 7 09:47:23 2010 +0200
Make the "wrong argument count" exception more explicit.
Previously we had messages like this one:
TypeError: takes exactly 2 argument(s) (1 given)
With this patch, they become like this:
TypeError: get_end_iter() takes exactly 2 argument(s) (1 given)
It makes things much easier to debug when there are several pygi calls
on the same line.
https://bugzilla.gnome.org/show_bug.cgi?id=620804
gi/pygi-invoke.c | 3 ++-
tests/test_everything.py | 6 ++++++
2 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 7ac1685..63e57e7 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -233,7 +233,8 @@ _prepare_invocation_state (struct invocation_state *state,
if (state->n_py_args != n_py_args_expected) {
PyErr_Format (PyExc_TypeError,
- "takes exactly %zd argument(s) (%zd given)",
+ "%s() takes exactly %zd argument(s) (%zd given)",
+ g_base_info_get_name ( (GIBaseInfo *) function_info),
n_py_args_expected, state->n_py_args);
return FALSE;
}
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 0463d2c..06a8d8c 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -79,6 +79,12 @@ class TestEverything(unittest.TestCase):
self.assertEquals(struct_b.nested_a.some_double, struct_b_clone.nested_a.some_double)
self.assertEquals(struct_b.nested_a.some_enum, struct_b_clone.nested_a.some_enum)
+ def test_wrong_type_of_arguments(self):
+ try:
+ Everything.test_int8()
+ except TypeError, e:
+ self.assertEquals(e.args, ("test_int8() takes exactly 1 argument(s) (0 given)",))
+
class TestNullableArgs(unittest.TestCase):
def test_in_nullable_hash(self):
Everything.test_ghash_null_in(None)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]