How to Support a Python package that uses C Extensions for Multiple Versions of Python ?

CarterJohn11
I made a small python package in the latest version of Python that has a C Extension, which uses a lot of the newer features, and now I want to release it. The next thing I need to do is make it usable for the different versions of Python.

How am I supposed to do that? Do I meticulously create and test one branch for each of the latest major.minor version of Python (for example, create a branch for python 3.5.9, test it and hope it works on 3.5.0), replacing the newer features I've used with older features?

This sounds like a lot of work. Would it not have been smarter to make the master branch a lower version and using older features, like 3.0, and just trust it would be compatible with for example 3.8 ?

One example I have is that my project assumes that dict is sorted. This means in the <3.6 branch I need to use an OrderedDict instead.

Another painful example is that I'm using f-strings everywhere, so in lower versions I'll need to replace that with format.

I'm most afraid of the C extension. I assume the worst will be switching between Python 2 and 3 but I'm not sure how bad it will get.

Is there a better way of going about this that I'm not aware of?
Sign In or Register to comment.