From: William S F. <ws...@fu...> - 2009-08-08 22:56:53
|
FermiPhysics wrote: > > > Josh Cherry wrote: >> >> >> On Fri, 31 Jul 2009, FermiPhysics wrote: >> >>> Looking at the SWIG-generated .py module, the __init__ function simply >>> says: >>> >>> def __init__(self, *args, *kwargs): raise AttributeError("No constructor >>> defined") >>> >>> The constructor is defined in the source, and declared in the header as >>> well >>> as the SWIG input (.i) file. Anyone had a similar problem? >> Have a look at http://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_nn9. >> >> It might be nice if SWIG generated different exception text in the case of >> abstract classes, e.g., "Class is abstract". >> Good idea. If one of the reasons the constructor is missing because the class is abstract, the code generated is now: def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract") > That's what I initially thought. I tried running swig with the -Wall option > so that it would raise a warning if it thought my class were abstract, and > there were no warnings. > > The class that has the __init__ function which raises the error is derived > from another C++ class. If SWIG thought the BASE class were abstract, would > it raise a warning with the -Wall option? That may be my problem. > No it does not raise a warning. There is no reason to do so, the designer of the C++ class intended it to be this way and the c++ compiler doesn't issue such a warning, it gives an error when attempting to invoke the method, so SWIG follows this approach. William |