[C++-sig] unfriendly python error message (no line number)

2009-11-08 Thread Thomas Daniel

No, it is not about template-related error messages :-)...

I am wrapping a class:
#include 

struct X {
   X() : _x(0) {}
   int get() const { return _x; }
   int _x;
};

BOOST_PYTHON_MODULE(Test) {
   class_("X")
   .def("get", &X::get)
   ;
}

and testing it with python:
x = X();
print x.get()
print x.get

Obviously, the error is that I forgot '()' in the second get(). I am 
getting this error message:


0
> 

Is there a way to give user a more friendly error message in such case, 
with at least a line number where it happened?


Note that if mistype the attribute name, I am getting something I much 
nicer:


Traceback (most recent call last):
 File "test.py", line 5, in 
   print x.foo
AttributeError: 'X' object has no attribute 'foo'

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] unfriendly python error message (no line number)

2009-11-08 Thread amohr
> No, it is not about template-related error messages :-)...
> 
> I am wrapping a class:
> Obviously, the error is that I forgot '()' in the second get(). I 
> am 
> getting this error message:
> 
> 0
> > 
> 
> Is there a way to give user a more friendly error message in such 
> case, 
> with at least a line number where it happened?

This has nothing to do with boost.python.  It's how python works.  For example:

>>> class X(object):
def __init__(self):
self._x = 0
def get(self):
return self._x


>>> x = X()
>>> print x.get()
0
>>> print x.get
>

And accessing 'x.get' is not in itself an error.  You may want to pass that 
bound method to a function expecting a callable, for instance.

Alex
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig