|
49 | 49 |
|
50 | 50 | QHash<QByteArray, int> PythonQtMethodInfo::_parameterTypeDict; |
51 | 51 |
|
| 52 | +// List of words that are reserved in Python, but not in C++, so they need escaping |
| 53 | +QSet<QByteArray> PythonQtClassInfo::_reservedNames{ |
| 54 | + "None", "True", "False" |
| 55 | +}; |
| 56 | + |
52 | 57 | PythonQtClassInfo::PythonQtClassInfo() { |
53 | 58 | _meta = nullptr; |
54 | 59 | _constructors = nullptr; |
@@ -279,7 +284,7 @@ bool PythonQtClassInfo::lookForEnumAndCache(const QMetaObject* meta, const char* |
279 | 284 | if (e.isFlag()) continue; |
280 | 285 |
|
281 | 286 | for (int j=0; j < e.keyCount(); j++) { |
282 | | - if (qstrcmp(e.key(j), memberName)==0) { |
| 287 | + if (escapeReservedNames(e.key(j)) == memberName) { |
283 | 288 | PyObject* enumType = findEnumWrapper(e.name()); |
284 | 289 | if (enumType) { |
285 | 290 | PythonQtObjectPtr enumValuePtr; |
@@ -869,7 +874,7 @@ void PythonQtClassInfo::createEnumWrappers(const QMetaObject* meta) |
869 | 874 | for (int j = 0; j < e.keyCount(); j++) { |
870 | 875 | PythonQtObjectPtr enumValuePtr; |
871 | 876 | enumValuePtr.setNewRef(PythonQtPrivate::createEnumValueInstance(p.object(), e.value(j))); |
872 | | - p.addVariable(e.key(j), QVariant::fromValue(enumValuePtr)); |
| 877 | + p.addVariable(escapeReservedNames(e.key(j)), QVariant::fromValue(enumValuePtr)); |
873 | 878 | } |
874 | 879 | } |
875 | 880 | #endif |
@@ -1018,6 +1023,16 @@ PythonQtVoidPtrCB* PythonQtClassInfo::referenceCountingUnrefCB() |
1018 | 1023 | return _unrefCallback; |
1019 | 1024 | } |
1020 | 1025 |
|
| 1026 | +QByteArray PythonQtClassInfo::escapeReservedNames(const QByteArray& name) |
| 1027 | +{ |
| 1028 | + if (_reservedNames.contains(name)) { |
| 1029 | + return name + "_"; |
| 1030 | + } |
| 1031 | + else { |
| 1032 | + return name; |
| 1033 | + } |
| 1034 | +} |
| 1035 | + |
1021 | 1036 | void PythonQtClassInfo::updateRefCountingCBs() |
1022 | 1037 | { |
1023 | 1038 | if (!_refCallback) { |
|
0 commit comments