What’s needed to port Shiboken to Python 3
Note: The Python3 support related ideas were moved to PySide_Python_3_Support!
- Python 3 C API doesn’t have PyInt * functions, just PyLong [docs.python.org]. The code used to handle type conversions recognizes the use of PyInt and PyLong. The proper code for conversion is executed depending on the scenario.
- Possible fix: Create PyInt _ * aliases to PyLong _ * functions.
- Severity: Low
- Python 3 module initialization is completely different from Python 2, supporting both types of initialization would be trick1.
- Possible fix: Change the generator to generate different initialization routines for different Python versions or pollute the generated module initialization routine with #ifdef’s.
- Severity: Medium
- PyTypeObject layout changed in Python 3 [python.org] . As many PyType objects are defined in libshiboken this implies some ugly changes to libshiboken to get the source code to support both Python versions.
- Possible fix: Do an “#ifdef festival” on libshiboken and on code generated by the generator to handle the differences between Python versions.
- Severity: High
- Python libraries will be ABI version tagged from 3.2 on [python.org]
- Possible fix: Support it in CMakeLists.txt.
- Severity: Medium
- Can’t access PyObject attributes from a PyTypeObject without casting it to PyObject beforehand.
- Possible fix: Cast it!
- Severity: Low
- Removal of PyString, addition of PyByte.
- Possible fix: Create some aliases to the respective PyUnicode functions or add #ifdefs when the aliasing solution isn’t possible.
- Severity: Medium
- CMake knows nothing about Python 3.
- Possible fix: Write our own findPython3 function to detect Python 3 on the underlying system.
- Severity: Medium
Summarizing, porting shiboken to Python 3 isn’t going to be a trivial task and support both versions will be even harder but not impossible.

