How to see if code is backwards compatible for Python? How to see if code is backwards compatible for Python? python python

How to see if code is backwards compatible for Python?


If you are actively developing a commercial product, and you -really- want to support all these versions properly, I would suggest:

  1. Writing an automated test suite that can be run and tests functionality for your entire library/application/whatever.

  2. Setting up a machine, or ideally virtual machine for each test environment (python 2.2-2.6 and any platform combinations if your product is not win32 only). This is especially easy to do nowadays given that there are several free virtualization products now (VirtualBox and VMWare Server, to name two)

  3. Using something like buildbot to automate the test running on all the other platforms, and collecting the results.

I might mention however, that there have been significant changes between 2.2 and 2.3, and again between 2.3 and 2.4. This is why most python libraries out there only support 2.3, and a number are moving to only supporting 2.4 and up now.

Every major release has a "What's new in python 2.x" document, but coding for 2.2 means you miss out on:

  • Generators (2.3) (well actually, you can get them in 2.2 with from __future__ import generators)
  • Generator expressions (2.4)
  • the subprocess module (2.4)
  • Decorator syntax (2.4)
  • sets (2.3)
  • decimal (2.4, but can be backported)
  • datetime (2.3)
  • itertools (2.3)

Just to name a very small subset of awesome things you probably can't have.

You have to really consider how badly you want to support a 7-year old python version, and miss out on a lot of cool features that can reduce your code size (or possibly just increase readability).


Try pyqver: https://github.com/ghewgill/pyqver/

Gives you the minimum version for given python script analyzing the keywords and modules used.

Also, you can compile locally python 2.2 and use virtualenv to create a python 2.2 environment with the --python flag.