if (%CPPSELF.isVariant() || %CPPSELF.isString()) { QString format = QString().sprintf("%s(\"%s\")", ((PyObject*)%PYSELF)->ob_type->tp_name, qPrintable(%CPPSELF.toString())); %PYARG_0 = PyString_FromString(qPrintable(format)); } else { %PYARG_0 = PyObject_Str((PyObject*)%PYSELF); } Shiboken::AutoDecRef key(PyObject_Str(_key)); QVariant res = %CPPSELF.property(PyString_AS_STRING(key.object())).toVariant(); if (res.isValid()) { return %CONVERTTOPYTHON[QVariant](res); } else { PyObject* errorType = PyInt_Check(_key) ? PyExc_IndexError : PyExc_KeyError; PyErr_SetString(errorType, "Key not found."); return 0; }