[PyQt] Re: PyQt overloaded constructors

Georg Altmann george at george-net.de
Wed Oct 1 10:41:35 BST 2008


Erick Tryzelaar schrieb:
> On Tue, Sep 30, 2008 at 6:27 AM, Georg Altmann <george at george-net.de> wrote:
>> Can I support the overloaded constructors in my subclass?
> 
> I believe what sip/PyQt is essentially manually extracting the
> arguments, like this:
> 
> def __init__(self, *args):
>   if len(args) == 1:
>     x = args[0]
>     assert isinstance(x, QUndoCommand)
>   elif len(args) == 2:
>     x, y = args
>     assert isinstance(x, Str)
>     assert isinstance(y, QUndoCommand)
>   else:
>     raise TooManyArgs
> 
> or something like that.

Actually I think this happens in the C++ code generated by sip. As 
described in the python documentation ("Extending Python with C or C++") 
extension functions are called with variable argument lists internally.

So the approach you described above seems to be the only way to support 
overloaded constructors in a python subclass.

Regards
Georg



More information about the PyQt mailing list