Python多重继承:类构造和_uinit__;()方法的参数数量未对齐,并导致类型错误

Python多重继承:类构造和_uinit__;()方法的参数数量未对齐,并导致类型错误,python,python-2.7,ironpython,multiple-inheritance,Python,Python 2.7,Ironpython,Multiple Inheritance,在IronPython项目中,我有一个名为Formbox的类,定义如下: class Formbox(TextBox, Widget): ... variables that I treat as static go here ... def __init__(self, parent, size, position, placeholder_text, formtype=str): TextBox.__init__(self) Widget.__init__(self,

在IronPython项目中,我有一个名为Formbox的类,定义如下:

class Formbox(TextBox, Widget):  

... variables that I treat as static go here ...

def __init__(self, parent, size, position, placeholder_text, formtype=str):
    TextBox.__init__(self)
    Widget.__init__(self, parent, size, position)
    ... rest of the init ...
其中TextBox是.NET System.Windows.Forms.TextBox类

每当我尝试实例化Formbox时,例如:

[例1] 发生以下情况:

TypeError: Formbox() takes exactly 1 argument (5 given)
如果我去掉ex1中传递的所有参数,将参数减少为隐含的self,则会出现以下情况:

TypeError: __init__() takes at least 5 arguments (1 given)
如果有帮助,Widget类如下所示:

class Widget:

    def __init__(self, parent, size, position):
        """

        :type parent:   System.Windows.Forms.Control
        :type size:     System.Drawing.Size
        :type position: System.Drawing.Point
        """
        self.parent = parent
        self.Size = size
        self.Location = position
当然,将继承自的类减少为一个(Widget或TextBox)会导致Formbox正确实例化。ex1工作得非常好,直到我将Widget添加到超类

我的问题是,为什么这些错误会被抛出我的头上,如何解决它,使Formbox类同时从Widget和TextBox类继承

p.S.我认为这是我自己的Python错误,而不是IronPython的限制


p.p.S为了简洁起见,Ex 1中的大多数参数都被缩短和简化了。

我不能很容易地重现这一点,但我怀疑您遇到了混合的情况。下面的代码片段在python 2.6.5、2.7.6和2.7.14中运行良好

from __future__ import print_function


class Widget:
    def __init__(self, parent, size, position):
        print('Widget(', self, parent, size, position, ')')


class TextBox(object):  # line: 9
    def __init__(self):
        print('TextBox(', self, ')')


class Formbox(TextBox, Widget):
    def __init__(self, parent, size, position, placeholder_text, formtype=str):
        print('Formbox(', self, parent, size, position, placeholder_text,
              formtype, ')')
        TextBox.__init__(self)
        Widget.__init__(self, parent, size, position)


if __name__ == '__main__':
    f = Formbox('parent', 'size', 'position', 'placeholder')
我怀疑
TextBox
对象的一个子类(如第9行所示)。这应该不会引起问题,因为您直接调用初始值设定项,而不是使用
super(Formbox,self)。\uu init\uu(…)
。运行此示例将产生以下输出:

Formbox( <__main__.Formbox instance at 0x7f34ded37b90> parent size position placeholder <type 'str'> )
TextBox( <__main__.Formbox instance at 0x7f34ded37b90> )
Widget( <__main__.Formbox instance at 0x7f34ded37b90> parent size position )
Formbox(父尺寸位置占位符)
文本框()
小部件(父级大小位置)
Python中的多重继承表现非常好。读一读这个题目。这是关于如何在Python中使用多重继承的简明说明

在本例中,我怀疑
TextBox
中正在改变类的创建

Formbox( <__main__.Formbox instance at 0x7f34ded37b90> parent size position placeholder <type 'str'> )
TextBox( <__main__.Formbox instance at 0x7f34ded37b90> )
Widget( <__main__.Formbox instance at 0x7f34ded37b90> parent size position )