Sunday, December 4, 2011

About Python 3 support in kdev_python

Just a quick note about Python 3 support in the kdevelop python plugin: I will switch over to supporting Python 3 language features as soon as there's a release of the Django web framework using Python 3 (as this plugin was originally intended for developing Django applications, this seems like a reasonable point in time to me).

Most (all?) of the (syntactic) features Python 3 has so far are in Python2.7 anyways, so there's not much unsupported stuff. There's only one thing which really breaks compatibility with almost any script: the changes in the print() function (it was a statement in 2.7 but was made a function now, but with extra syntax sugar). Python 2 provides a way to emulate this behaviour; in the header of your file you need to put a line like
from __future__ import print_function

However, if you want to use kdev-python with your Python 3 project, you likely don't want to place those lines everywhere. That's why there's a new feature which allows you to specify a project-wide file header, which will be inserted into every python file in your project before it is parsed. This header file needs to be placed in your project root directory and needs to have the name ".kdev_python_header". You can, for example, put the above line in there to enable using the python 3 print function without syntax errors being thrown.