[C++-sig] ArgumentError: Python argument types in None.None

Anand, Kumar kanand at qualcomm.com
Sun Nov 12 06:49:32 CET 2006


I have a base class and a derived class (in say userTypes.h &
userTypes.cpp) and this is built into a static library (say
libuserTypes.a)
----------------------------
class Base {
public:
  int x;
  Base(int i);
};

class Derived : public Base {
public:
  int y;
  Derived(int i, int j);
};
----------------------------
I exposed both these classes to python (using Boost Python) in a
Boost_UserTypes.so module. (Note: My .so links against the static
libuserTypes.a). 
All this works perfectly and I am able to import the module in a python
script and use it.

Now I built another module Boost_UserInterfaces.so which exposes a C++
interface (using the types from libuserTypes.a). Code is as follows.
----------------------------
namespace TestFrmwkEg_Wrapper {
   Base* createDerivedTest(int baseX, int derivedY) {
      return new Derived(baseX, derivedY);
   }
}
BOOST_PYTHON_MODULE (Boost_UserInterfaces)  {
  def("createDerivedTest", &TestFrmwkEg_Wrapper::createDerivedTest,
bp::return_value_policy<bp::manage_new_object>());
}
----------------------------
Note: My function returns a base class pointer to derived class
instance. Boost_UserInterfaces.so also links against the static
libuserTypes.a.

Now in my python script when I do the following:
----------------------------
import Boost_UserInterfaces
import Boost_UserTypes

dr = Boost_UserInterfaces.createDerivedTest(3, 8) 
print dr.y
----------------------------

I get the following error when I try to access attribute 'y' of the
derived object.

Boost.Python.ArgumentError: Python argument types in
    None.None(Derived)
did not match C++ signature:
    None(Derived {lvalue})

-Can anyone explain to me why this is happening? I used pdb.set_trace to
examine the dr variable and everything looks ok.

(Pdb) dir(dr)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__instance_size__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__', 'x', 'y']
(Pdb) print dr
<Boost_UserTypes.Derived object at 0x2b13d969b0c0>

I understand that linking the static .a library twice (once in every
.so) is a bad thing to do, but I would still like to understand the
reasons for this error. If print and dir command are showing the correct
derived object as expected, why is the access to the derived class
attribute failing?

Thanks
Kumar


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20061111/51d0ff0e/attachment.htm>


More information about the Cplusplus-sig mailing list