Menu

#146 [python] more helpful error msg when overload lookup fails

closed-fixed
nobody
None
5
2007-05-03
2006-04-04
No

Short explanation:

In Python, instead of the scarcely helpful error message

NotImplementedError: No matching function for
overloaded 'Foo_setCoord'

print

NotImplementedError: Wrong number of arguments for
overloaded function 'Foo_setCoord'.
Possible prototypes are:
self.setCoord(int,int) # Foo *self,int x,int y
self.setCoord(int) # Foo *self,int x

Long explanation:

Currently, if you wrap the following class

class Foo {
private:
int X, Y;
public:
Foo(int id);
Foo(const char *name);
void setCoord(int x, int y);
void setCoord(int x);
};

and you say
f = Foo( 1, 2 )
the dispatcher function generates this error message:

NotImplementedError: No matching function for
overloaded 'new_Foo'

This is hardly helpful. With this patch you get:

NotImplementedError: Wrong number of arguments for
overloaded function 'new_Foo'.
Possible prototypes are:
Foo(int) # int id
Foo(char const *) # char const *name

Similarly, if you say
f.setCoord( 1, 2, 3)
you currently get

NotImplementedError: No matching function for
overloaded 'Foo_setCoord'

whereas

NotImplementedError: Wrong number of arguments for
overloaded function 'Foo_setCoord'.
Possible prototypes are:
self.setCoord(int,int) # Foo *self,int x,int y
self.setCoord(int) # Foo *self,int x

might help users of the extension module more.

Note that this patch only applies to a wrong number of
arguments. For the other case (correct number of
arguments, but at least one of them is of a wrong type)
the error message is already very detailed and helpful.

Discussion

  • Tijs Michels

    Tijs Michels - 2006-04-07

    Logged In: YES
    user_id=1259995

    With the latest patch the output has less redundancy, and
    also includes the return type.

    NotImplementedError: Wrong number of arguments for
    overloaded function 'setCoord'.
    Possible prototypes are:
    void Foo.setCoord(int,int) # self, x, y
    void Foo.setCoord(int) # self, x

    This version splits the string over multiple lines, as some
    compilers (notably MSVC) impose a maximum on the source code
    line length.

     
  • Tijs Michels

    Tijs Michels - 2006-04-07

    small patch against python.cxx,v 1.203

     
  • Olly Betts

    Olly Betts - 2006-09-25
    • summary: more helpful error message when overload lookup fails --> [python] more helpful error msg when overload lookup fails
     
  • Tijs Michels

    Tijs Michels - 2007-05-03
    • status: open --> closed-fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.