开发者

Python - "object layout"

can somebody describe the following exception? What is the "object layout" and how it is defined? Thanks

Traceback (most recent call last):
  File "test_gui.py", line 5, in <module>
    suite = AlgorithmEngine('gui_suite')
  File "/home/honza/Research/Voiar/algorithm.py", line 169, in __init__
    self.algorithms = self._initAlgorithms()
  File "/home/honza/Research/Voiar/algorithm.py", line 232, in _initAlgorithms
    self._initGUIAlgorithm(obj)
  Fil开发者_开发知识库e "/home/honza/Research/Voiar/algorithm.py", line 218, in _initGUIAlgorithm
    cls.__bases__ = bases
TypeError: __bases__ assignment: 'QWidget' object layout differs from 'GUIAlgorithm'


It means that you tried to change the type of an object (by assigning to __bases__) and the new type wasn't compatible with the old one. This happens when the underlying C data structure isn't the same for both types.

See http://www.mail-archive.com/python-list@python.org/msg52950.html for a list of differences between types that might trigger this exception.


In my case, the error occurred when I tried to use change the __class__ of an object that also has __slots__, like this:

class Base:
    __slots__ = ('a', 'b', 'c')

class Child(Base):
    pass


obj = Base()
obj.__class__ = Child  
# -> TypeError: __class__ assignment: 'Child' object layout differs from 'Base'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜