Compiler, ast and forwards/backwards compatibility

Orestis Markou orestis at orestis.gr
Tue Oct 7 05:26:05 EDT 2008


Hello,

I'm the developer of PySmell ( http://github.com/orestis/pysmell ), a
static analysis/intellisense provider for Python. I am targeting
Python 2.4 code so I'm using the compiler package.

I've been toying around yesterday with the ast module in Python 2.6
and it seems much more cleaner. One thing I don't understand is how
should one handle backwards and forwards compatibility.

The documentation for the ast module states that it "helps to find out
programmatically what the current grammar looks like". I can't find
any reference (even when reading the code) on how you should go about
this, other than checking the sys.version number and reading up on the
changes.

My understanding is that there is no way to write, say, an ast visitor
that runs under Python 3.0 that targets 2.4 because the ast has
changed, and there's no way to indicate that you want to parse another
version.

I guess that Python 2.6 can target Python 2.3-6, and with specific
compiler flags it can also target 3.0, so it seems that the correct
thing to do is to use that.

Am I correct? Am I seriously confused? Please help!

Thanks,
Orestis
-- 
orestis at orestis.gr
http://orestis.gr



More information about the Python-list mailing list