Skip to content

New project: python-incompatibility. Is Python 3.0 really incompatible?

May 15, 2008

Since PyCon I have been working on a set of tests to demonstrate incompatibilities between Python 2.5, 2.6 and 3.0, with the aim of not only documenting the incompatibilities, but also testing if you avoid them, and write code that runs under both Python 2.6 and 3.0, thereby providing a transitional path from 2.x to 3.0. (2.5 code should run under 2.6 unmodified, so that part of the transition is done).

I found only one major incompatibility, that 2.6 required u” for Unicode, but 3.0 doesn’t support it. This was solved in Python 2.6a3, which introduced a from __future__ import unicode_literals, which makes 2.6 behave the same as 3.0. Thanks for that!

So, at the moment, I’m not aware of any major unavoidable incompatibilities. I decided to put up my half-assed code somewhere public, so other people can add to it. So, I created a new project on code.google.com: http://code.google.com/p/python-incompatibility/

You can check out out for yourselves. running runtests.py 26 will work on both Python 2.6 and Python 3.0.
But the code isn’t finished yet. There may be incompatibilities I haven’t thought about, and there are no tests of the library reorganisation. Please help out on this! It’s fun, easy and a great way to learn Python 3.0!

See also: https://regebro.wordpress.com/2007/06/23/python-3000-and-compatibility/, https://regebro.wordpress.com/2008/03/22/why-python-26-and-30-compatibility-would-be-a-very-good-thing/

4 Comments
  1. Leroy Glinchy permalink

    I could be wrong, but I thought that the point of the python devs was to allow themselves the ability to break compatability. However, I doubt they’d break it deliberately. That is, they wanted to give themselves freedom to fix some long standing issues that only an api change could do. However, they found that there was less that needed changing than they thought.

    Alternatively, you need to write stricter tests.🙂

    I am talking out of my ass here. I don’t really know.

    Thanks for posting the test results. It’s nice to know that things are not broken more. I know there will be a day when we will find that our old versions of python are no longer supported on our platforms of choice.

  2. Yes, that’s indeed the idea behind Python 3. My point is that Guido has been telling everybody that the subset that is compatible is so small that it’s useless. That probably was true, but 2.6 has introduced more and more forward compatibility, and I don’t think it’s true anymore.

    We’ll see when we have a more complete set of tests.

  3. “unicode_listerals” should be “unicode_literals”

    At first I was confused because it seemed like you were saying, “Current Python code should work with Python 3.0”, which I know is not true. Then I realized you were actually saying, “Python code can be written in such a way that it works with Python 2.6 and Python 3.0”. That’s pretty different. You’re not very clear.

    But it’s great to see that this is possible. This should make transitioning much easier.

  4. You are right. I’ve tried to clarify (and fixed the spelling error), I hope that’s better?

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: