AFAIK "self" is not available on class methods (see @classmethod modificator), cls should point to class object not to instance object
regards R. 2012/9/12 Thomas Pietrowski <[email protected]>: > Hey, > > I'm not familiar to Python3, but what happens, when you replace: > > def instance(cls): > > with: > > def instance(self, cls): > > For me it seems that it uses cls as self in that function, if self is not > set in the function of your class. > But, as I said, I'm not sure if that could be your solution ;-) > > Am 12.09.2012 12:20 schrieb "Roman Lacko" <[email protected]>: >> >> Hi, >> >> I have discovered strange bahaviour while testing qtdemo.py under Python >> 3.2. >> Plase look at sample code and the comment prefixed XXX: >> >> >>> >> from PySide import QtCore >> >> class MenuManager(QtCore.QObject): >> >> pInstance = None >> >> @classmethod >> def instance(cls): >> if cls.pInstance is None: >> cls_inst = cls() >> cls.pInstance = cls_inst >> # XXX: the cls.pInstance is None but cls_inst is NOT None !!! >> >> return cls.pInstance >> >> # This will allways return None under Python 3.2 >> menuManagerInstance = MenuManager.instance() >> print(menuManagerInstance) >> <<< >> >> Under Python 2.6 and 2.7 the code work as expected (cls.pInstance is NOT >> None) >> If MenuManager inherits from object it will work (class >> MenuManager(object)), so there is something wrong with QObject >> wrapper... >> Under PyQt4 it works fine. >> >> I have absolutely no idea what is going on here. >> >> Regards >> Roman >> _______________________________________________ >> PySide mailing list >> [email protected] >> http://lists.qt-project.org/mailman/listinfo/pyside _______________________________________________ PySide mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/pyside
