[PyQt] SIP: deriving a python class from a C++ ABC results in a TypeError exception
I have a C++ class which is declared with pure virtual methods, but if I derive from this class in python and implement the pure virtual methods, I get an exception: TypeError: pyvoip.opal.OpalPCSSEndPoint cannot be instantiated or sub-classed My python class is declared as following: class PCSSEndPoint(OpalPCSSEndPoint): def __init__(self): super(OpalPCSSEndPoint, self).__init__() def OnShowIncoming(self, connection): return True def OnShowOutgoing(self, connection): return True def GetMediaFormats(self): return [] SIP definitions: class OpalPCSSEndPoint : OpalLocalEndPoint /Abstract/ { /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowIncoming( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowOutgoing( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; }; Now the base class of OpalPCSSEndPoint is also an ABC, as it derives from an ABC but does not re-define the pure virtual function: class OpalLocalEndPoint : OpalEndPoint /Abstract/ { ... }; class OpalEndPoint /Abstract/ { virtual OpalMediaFormatList GetMediaFormats() const = 0; }; I tried removing /Abstract/ from OpalLocalEndPoint, but it made no difference. Any idea what's wrong in this scenario? The only way this works, is if I subclass OpalPCSSEndPoint in C++ and then in Python create a class derived from my OpalPCSSEndPoint subclass. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] SIP: deriving a python class from a C++ ABC results in a TypeError exception
Actually I made a small mistake, OpalLocalEndPoint has a GetMediaFormats implementation, but the issue remains. class OpalLocalEndPoint : OpalEndPoint { virtual OpalMediaFormatList GetMediaFormats() const; }; On Sat, Jul 2, 2011 at 5:39 PM, Demetrius Cassidy dcassid...@gmail.comwrote: I have a C++ class which is declared with pure virtual methods, but if I derive from this class in python and implement the pure virtual methods, I get an exception: TypeError: pyvoip.opal.OpalPCSSEndPoint cannot be instantiated or sub-classed My python class is declared as following: class PCSSEndPoint(OpalPCSSEndPoint): def __init__(self): super(OpalPCSSEndPoint, self).__init__() def OnShowIncoming(self, connection): return True def OnShowOutgoing(self, connection): return True def GetMediaFormats(self): return [] SIP definitions: class OpalPCSSEndPoint : OpalLocalEndPoint /Abstract/ { /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowIncoming( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowOutgoing( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; }; Now the base class of OpalPCSSEndPoint is also an ABC, as it derives from an ABC but does not re-define the pure virtual function: class OpalLocalEndPoint : OpalEndPoint /Abstract/ { ... }; class OpalEndPoint /Abstract/ { virtual OpalMediaFormatList GetMediaFormats() const = 0; }; I tried removing /Abstract/ from OpalLocalEndPoint, but it made no difference. Any idea what's wrong in this scenario? The only way this works, is if I subclass OpalPCSSEndPoint in C++ and then in Python create a class derived from my OpalPCSSEndPoint subclass. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] SIP: deriving a python class from a C++ ABC results in a TypeError exception
On Sat, 2 Jul 2011 17:39:14 +, Demetrius Cassidy dcassid...@gmail.com wrote: I have a C++ class which is declared with pure virtual methods, but if I derive from this class in python and implement the pure virtual methods, I get an exception: TypeError: pyvoip.opal.OpalPCSSEndPoint cannot be instantiated or sub-classed My python class is declared as following: class PCSSEndPoint(OpalPCSSEndPoint): def __init__(self): super(OpalPCSSEndPoint, self).__init__() That should be super(PCSSEndPoint, self).__init__() def OnShowIncoming(self, connection): return True def OnShowOutgoing(self, connection): return True def GetMediaFormats(self): return [] SIP definitions: class OpalPCSSEndPoint : OpalLocalEndPoint /Abstract/ { /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowIncoming( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowOutgoing( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; }; Now the base class of OpalPCSSEndPoint is also an ABC, as it derives from an ABC but does not re-define the pure virtual function: class OpalLocalEndPoint : OpalEndPoint /Abstract/ { ... }; class OpalEndPoint /Abstract/ { virtual OpalMediaFormatList GetMediaFormats() const = 0; }; I tried removing /Abstract/ from OpalLocalEndPoint, but it made no difference. Any idea what's wrong in this scenario? The only way this works, is if I subclass OpalPCSSEndPoint in C++ and then in Python create a class derived from my OpalPCSSEndPoint subclass. /Abstract/ is the cause of the problem. It doesn't mean that the C++ is an ABC, it means that the class contains other (unspecified) abstract methods. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] SIP: deriving a python class from a C++ ABC results in a TypeError exception
CCing mailing list On Sat, Jul 2, 2011 at 10:50 PM, Demetrius Cassidy dcassid...@gmail.comwrote: On Sat, Jul 2, 2011 at 10:45 PM, Phil Thompson p...@riverbankcomputing.com wrote: On Sat, 2 Jul 2011 17:39:14 +, Demetrius Cassidy dcassid...@gmail.com wrote: I have a C++ class which is declared with pure virtual methods, but if I derive from this class in python and implement the pure virtual methods, I get an exception: TypeError: pyvoip.opal.OpalPCSSEndPoint cannot be instantiated or sub-classed My python class is declared as following: class PCSSEndPoint(OpalPCSSEndPoint): def __init__(self): super(OpalPCSSEndPoint, self).__init__() That should be super(PCSSEndPoint, self).__init__() The super thing was a typo. def OnShowIncoming(self, connection): return True def OnShowOutgoing(self, connection): return True def GetMediaFormats(self): return [] SIP definitions: class OpalPCSSEndPoint : OpalLocalEndPoint /Abstract/ { /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowIncoming( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowOutgoing( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; }; Now the base class of OpalPCSSEndPoint is also an ABC, as it derives from an ABC but does not re-define the pure virtual function: class OpalLocalEndPoint : OpalEndPoint /Abstract/ { ... }; class OpalEndPoint /Abstract/ { virtual OpalMediaFormatList GetMediaFormats() const = 0; }; I tried removing /Abstract/ from OpalLocalEndPoint, but it made no difference. Any idea what's wrong in this scenario? The only way this works, is if I subclass OpalPCSSEndPoint in C++ and then in Python create a class derived from my OpalPCSSEndPoint subclass. /Abstract/ is the cause of the problem. It doesn't mean that the C++ is an ABC, it means that the class contains other (unspecified) abstract methods. Phil So if /Abstract/ does not mean the class has pure virtual methods and cannot be instantiated itself, in which scenario should it be used? I'm a little confused here. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] SIP: deriving a python class from a C++ ABC results in a TypeError exception
I think I answered my own question after re-reading the annotation docs. Thanks. On Sat, Jul 2, 2011 at 10:52 PM, Demetrius Cassidy dcassid...@gmail.comwrote: CCing mailing list On Sat, Jul 2, 2011 at 10:50 PM, Demetrius Cassidy dcassid...@gmail.comwrote: On Sat, Jul 2, 2011 at 10:45 PM, Phil Thompson p...@riverbankcomputing.com wrote: On Sat, 2 Jul 2011 17:39:14 +, Demetrius Cassidy dcassid...@gmail.com wrote: I have a C++ class which is declared with pure virtual methods, but if I derive from this class in python and implement the pure virtual methods, I get an exception: TypeError: pyvoip.opal.OpalPCSSEndPoint cannot be instantiated or sub-classed My python class is declared as following: class PCSSEndPoint(OpalPCSSEndPoint): def __init__(self): super(OpalPCSSEndPoint, self).__init__() That should be super(PCSSEndPoint, self).__init__() The super thing was a typo. def OnShowIncoming(self, connection): return True def OnShowOutgoing(self, connection): return True def GetMediaFormats(self): return [] SIP definitions: class OpalPCSSEndPoint : OpalLocalEndPoint /Abstract/ { /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowIncoming( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; /**Call back to indicate that remote is ringing. If false is returned the call is aborted. The default implementation is pure. */ virtual PBoolean OnShowOutgoing( const OpalPCSSConnection connection /NoCopy/ /// Connection having event ) = 0; }; Now the base class of OpalPCSSEndPoint is also an ABC, as it derives from an ABC but does not re-define the pure virtual function: class OpalLocalEndPoint : OpalEndPoint /Abstract/ { ... }; class OpalEndPoint /Abstract/ { virtual OpalMediaFormatList GetMediaFormats() const = 0; }; I tried removing /Abstract/ from OpalLocalEndPoint, but it made no difference. Any idea what's wrong in this scenario? The only way this works, is if I subclass OpalPCSSEndPoint in C++ and then in Python create a class derived from my OpalPCSSEndPoint subclass. /Abstract/ is the cause of the problem. It doesn't mean that the C++ is an ABC, it means that the class contains other (unspecified) abstract methods. Phil So if /Abstract/ does not mean the class has pure virtual methods and cannot be instantiated itself, in which scenario should it be used? I'm a little confused here. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt