Python 3to2: Go check it out.

awesome.jpg Earlier this week – Joe Amenta shot an email to the Python-Dev mailing list announcing the completion of the Google Summer of Code project he had be working on – a Python 3 to Python 2 translation tool.

This is something which, when discussed at the Python Language Summit at PyCon 2009 was met with much “yes please make this” – but not a lot of people could allocate the time. In fact, when asked who could at least help drive it forward, I was lame^H^H^H awesome enough to raise my hand.

In true upper management style, I discussed it, and promptly delegated it to Benjamin Peterson, our release manager to later delegate to a google summer of code project.

Some work was done during the sprints – I don’t know if that work ended up being part of this, but thanks to Joe, we now have the first alpha of a Python 3 to Python 2 conversion tool.

Here’s Joe’s announcement:

Hello all,

I have released the first alpha version of 3to2 after finishing it for my Google Summer of Code 2009(tm) project. You can get the tarball for this release at http://bitbucket.org/amentajo/lib3to2/downloads/3to2_0.1-alpha1.tar.gz. This requires python 2.7, because it requires a newer version of 2to3 than what comes with 2.6.

Release notes are in the RELEASE file. Development happens at http://bitbucket.org/amentajo/lib3to2/, and the source code for this release lives at http://bitbucket.org/amentajo/3to2-01-alpha-1.
Report bugs at http://bitbucket.org/amentajo/lib3to2/issues/, please.

Additional notes and comments can (for now) be found at http://www.startcodon.com/wordpress/?cat=4.

–Joe

This is awesome – again, major props to Joe (and Benjamin!) and GSoC for making this happen. Please, please, please – if you have free time, go give it a shot. Especially if you have real, honest-to-goodness Python 3 code you’re working with.

Right now, it’s probably too early to get near python-core – there’s some discussion of that going on in the thread on Python-dev, but I personally feel if we can bang the hell out of this and get a lot of eyes looking at it, it would go a long way towards helping Python 3 adoption along.

Go check it out – again, the project page is here, and Joe’s notes on things 3to2 does not accept is here.

p.s. The first person to write an online 2to3 -> 3to2 app ala translation party gets mad props, and a bottle of something alcoholic at Pycon.

  • joeamenta
    Haha, I would love to see what comes out of the 2to3 -> 3to2 generator. I had initially thought about making it a goal that 2to3 -> 3to2 code would look the same as the original, but as I learned more, I conceded that it would be unrealistic and impractical.
  • awesome indeed. thanks for this. saw an email ages ago to dev (which i don't read all of) suggesting this and then it seemed to disappear - gret to see it didn't get lost. i will give it a go on lepl (see my link) next release (coming up soon).
  • donspaulding
    The py-postgresql project might be a good starting point for getting a realistic Python 3.X codebase backported via 3to2.

    http://python.projects.postgresql.org/

    It seems like 3to2 needs to learn how to remove annotations and dictionary comprehensions first. Unfortunately hacking 3to2 is a bit beyond me. Sounds like a great idea though.

    EDIT: Actually, 3to2 does handle annotations correctly, it was just barfing on ParseErrors in certain files and then not running any fixers on those files. Protip: READ THE OUTPUT.
blog comments powered by Disqus