diff --git a/functions.cpp b/functions.cpp index 373339a3..2e9c2b52 100644 --- a/functions.cpp +++ b/functions.cpp @@ -154,7 +154,7 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const message += description_as_string(desc); message += ",\nbut got "; tuple arguments(ref(args, ref::increment_count)); - message += argument_tuple_as_string(arguments); + message += arguments_as_string(arguments); message += " instead."; PyErr_SetObject(PyExc_TypeError, message.get()); } @@ -177,7 +177,7 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const message += " matches argument(s):\n"; tuple arguments(ref(args, ref::increment_count)); - message += argument_tuple_as_string(arguments); + message += arguments_as_string(arguments); message += "\nCandidates are:\n"; for (const function* f1 = this; f1 != 0; f1 = f1->m_overloads.get()) @@ -192,6 +192,11 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const return 0; } +string function::arguments_as_string(tuple arguments) const +{ + return argument_tuple_as_string(arguments); +} + bound_function* bound_function::create(const ref& target, const ref& fn) { bound_function* const result = free_list; diff --git a/functions.h b/functions.h index acf883b5..ebcb52e2 100644 --- a/functions.h +++ b/functions.h @@ -46,6 +46,7 @@ class function : public python_object protected: virtual PyObject* description() const = 0; + virtual string arguments_as_string(tuple args) const; private: virtual PyObject* do_call(PyObject* args, PyObject* keywords) const = 0; virtual string function_name() const = 0; diff --git a/gen_init_function.py b/gen_init_function.py index 984a3d4b..45ca5c20 100644 --- a/gen_init_function.py +++ b/gen_init_function.py @@ -130,6 +130,7 @@ private: // override function hook PyObject* do_call(PyObject* args, PyObject* keywords) const; private: virtual instance_holder_base* create_holder(extension_instance* self, PyObject* tail_args, PyObject* keywords) const = 0; + string arguments_as_string(tuple arguments) const; }; """ + gen_functions(""" diff --git a/init_function.cpp b/init_function.cpp index f29e914a..9a257d63 100644 --- a/init_function.cpp +++ b/init_function.cpp @@ -33,4 +33,9 @@ namespace python { namespace detail { return none(); } + string init::arguments_as_string(tuple arguments) const + { + return argument_tuple_as_string(arguments.slice(1, arguments.size())); + } + }} // namespace python::detail diff --git a/init_function.h b/init_function.h index 016e47f7..495e92cf 100644 --- a/init_function.h +++ b/init_function.h @@ -165,6 +165,7 @@ private: // override function hook PyObject* do_call(PyObject* args, PyObject* keywords) const; private: virtual instance_holder_base* create_holder(extension_instance* self, PyObject* tail_args, PyObject* keywords) const = 0; + string arguments_as_string(tuple arguments) const; }; diff --git a/test_extclass.py b/test_extclass.py index cc6b2267..8682ec6e 100644 --- a/test_extclass.py +++ b/test_extclass.py @@ -15,13 +15,13 @@ a single long parameter. ... print str(err) ... else: print 'no exception' 'demo.Foo.__init__' expected argument(s) (int), - but got (demo.Foo) instead. + but got () instead. >>> try: ext = Foo('foo') ... except TypeError, err: ... print str(err) ... else: print 'no exception' 'demo.Foo.__init__' expected argument(s) (int), - but got (demo.Foo, string) instead. + but got (string) instead. >>> ext = Foo(1) Call a virtual function. This call takes a trip into C++ where @@ -363,7 +363,7 @@ Some simple overloading tests: ... print str(err) ... else: print 'no exception' No variant of overloaded function 'demo.Range.__init__' matches argument(s): - (demo.Range, string) + (string) Candidates are: (int) (int, int) @@ -617,7 +617,7 @@ Testing overloaded constructors ... else: ... print 'no exception' No variant of overloaded function 'demo.OverloadTest.__init__' matches argument(s): - (demo.OverloadTest, int, string) + (int, string) Candidates are: () (demo.OverloadTest)