By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,247 Members | 1,880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,247 IT Pros & Developers. It's quick & easy.

Re: Compiler, ast and forwards/backwards compatibility

P: n/a
On Tue, Oct 7, 2008 at 5:39 PM, Terry Reedy <tj*****@udel.eduwrote:
Orestis Markou wrote:

I'm the developer of 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.

My impression is that the 2.6 ast package is quite different from the 2.4
compiler package, but I have not looked at it (in its 3.0 version) yet. If
the 2.4 code you are analyzing is syntactically and sematically valid as 2.6
code, which I believe is usual, then of course there is no problem. If it
is not, then I would not be sure.
The ast module is indeed very different from the compiler package, as
it depends on the exact grammar definition that the interpreter is
using, rather a re-implementation (which I understand the compiler.ast

My confusion starts with the fact that I'm not sure if all Python 2.4
code is going to be syntactically valid 2.6 code. I guess 2.3 is valid
2.4 is valid 2.5, which should be valid 2.6 (but not valid 3.0) - I
think it's the lockstep of 2.6 and 3.0 that's misleading me...
>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.

If you want to target 2.3 to 3.0, 2.6 is the only option as far as I know.
I expect you will want to run your code through 2to3 (still being improved)
and run under 3.0 to properly handle 3.0 code.
That sounds correct. It's annoying that I have to require Python 2.6
for this - I guess that since the compiler module is there in 2.6 I'm
not compelled to use ast until I want to run under 3.0...
Maybe someone else can give a better answer.



Oct 7 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
My confusion starts with the fact that I'm not sure if all Python 2.4
code is going to be syntactically valid 2.6 code.
That's not so much a matter of confusion, but of careful research.

I *think* all code that is syntactically correct in 2.4 is also
syntactically correct in 2.6 - but only because

raise "Hello"

is still syntactically correct in 2.6 - it's a TypeError, not a
SyntaxError. The other case would be assignment to None, but that
was banned in 2.4 already.
I guess 2.3 is valid
2.4 is valid 2.5
I think not so: assignment to None got disallowed, syntactically
(can't test 2.3, at the moment).

Oct 8 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.