2016-06-10

!echo Bye-bye Python 2 !

In early 2013, we decided to port our chatbot project Errbot to Python 3. It was for its version 2.0.0beta.

I still remember that vividly, it was crazy at that time. First, absolutely nobody would use Errbot under Python 3. Finding compatible libraries was a gigantic pain not only for the plugin designers but also for ourselves: Check out this extract from the change log...

- xmpp backend has been replaced by sleekxmpp
- flask has been replaced by bottle (sorry flask no py3 support, no future)
- now the IRC backend uses the simpler python/irc package

We had to remove flask for rocket a small alternative and switch over the other 2 main dependencies we had for the 2 chat systems we supported. We barely wiggled through this ... and of course we broke stuff all over (I still have PTSD from the unicode breakages :) ).

2.0.0 stayed in beta for 10 months while users stayed safely on 1.7.1, a version from 2012.

We managed pretty well the next 3 years: the code was developed in Python 3 and translated automatically at install time to Python 2 with a tool called 3to2. The project grew in popularity and the general quality of the code, unit tests and documentation with it.

But something changed progressively, maintaining the Python 2 compatibility became more and more time consuming for not much benefit: simply less users were stuck with it. We could not find any reason for keeping the backward compatibility: all the main distributions have Python 3, the ecosystem moved on (even flask !), most plugins have the dual compatibility.

So today we pulled the plug, we are removing the Python 2 compatibility on master. We will maintain the backward compatibility for the latest version (4.2.x) until the end of the year while the new version will be Python 3.3+ only.

Some takeways

- It is quite impressive that, despite 3to2 making a very good job at converting the source code, a lot of hacks crept in over the years.  Just by browsing the diff, it is easy to see the jump in code readability.

- 3to2 was retrospectively the good choice: It allowed us to switch to the new Python version 3 years ago and today in just one long but very simple PR remove the support for the old one.

- 3 years ago it was definitely a little early to support Python 3 but today it is definitely the right time to drop Python 2.

If you have to port your project today, you are in luck ! You can drop Python 2 right away without all the complexity of maintaining a dual compatibility. Polish your test coverage, 2to3 in-place, fix it until it is done and enjoy the cleanliness and the new features of Python 3 without ever thinking again about Python 2.

No comments:

Post a Comment