Re: python 2.5 and ast

2011-12-02 Thread DevPlayer
On Nov 30, 1:03 pm, Andrea Crotti andrea.crott...@gmail.com wrote: Another thing about the AST, I am having fun trying to for example list out all the unused imports. I have already a visitor which works quite nicely I think, but now I would like to get a way to find all the unused imports,

Re: python 2.5 and ast

2011-12-02 Thread Andrea Crotti
On 12/02/2011 03:18 PM, DevPlayer wrote: There was another topic in these forums recently about un-importing modules (and how you can not do that reliably without restarting python). There was various ways mentioned of keeping track of what was imported. And there was mentioned reasonable ways

Re: python 2.5 and ast

2011-12-02 Thread Andrea Crotti
And on a related topic, how can I actually detect other types of imports, for example __import__ Doing a dump I get this: In [113]: ast.dump(ast.parse('__import__(module)')) Out[113]: Module(body=[Expr(value=Call(func=Name(id='__import__', ctx=Load()), args=[Str(s='module')], keywords=[],

Re: python 2.5 and ast

2011-12-02 Thread 88888 Dihedral
On Monday, November 28, 2011 7:45:57 PM UTC+8, Andrea Crotti wrote: I'm happily using the ast module to analyze some code, but my scripts need also to run unfortunately on python 2.5 The _ast was there already, but the ast helpers not yet. Is it ok if I just copy over the source from the ast

Re: python 2.5 and ast

2011-12-02 Thread Ian Kelly
an indexed array with (k,v) pairs for k=0,1,2,3...n in a trivial way. What in the world does any of this have to do with using the ast module in Python 2.5? I am starting to suspect that 8 Dihedral may be a bot. -- http://mail.python.org/mailman/listinfo/python-list

Re: python 2.5 and ast

2011-11-30 Thread Andrea Crotti
Another thing about the AST, I am having fun trying to for example list out all the unused imports. I have already a visitor which works quite nicely I think, but now I would like to get a way to find all the unused imports, so I need more visitors that find out all the used names. I didn't

Re: python 2.5 and ast

2011-11-29 Thread Andrea Crotti
On 11/29/2011 03:55 AM, Dave Angel wrote: But don't forget to tag it as version specific, so it gets removed when the later version of the library is available. There are various ways of doing that, but the easiest is probably to put a test in the acceptance suite that fails if this code is

Re: python 2.5 and ast

2011-11-29 Thread Arnaud Delobelle
On 29 November 2011 09:51, Andrea Crotti andrea.crott...@gmail.com wrote: from sys import version_info if version_info[1] == 5:    from psi.devsonly.ast import parse, NodeVisitor else:    from ast import parse, NodeVisitor Why don't you just: try: from ast import parse, NodeVisitor

Re: python 2.5 and ast

2011-11-29 Thread Steven D'Aprano
On Tue, 29 Nov 2011 09:51:24 +, Andrea Crotti wrote: On 11/29/2011 03:55 AM, Dave Angel wrote: But don't forget to tag it as version specific, so it gets removed when the later version of the library is available. There are various ways of doing that, but the easiest is probably to put

Re: python 2.5 and ast

2011-11-29 Thread Andrea Crotti
On 11/29/2011 11:32 AM, Steven D'Aprano wrote: I prefer to check against sys.version. import sys if sys.version= '2.5': from psi.devsonly.ast import parse, NodeVisitor else: from ast import parse, NodeVisitor Or even: try: from ast import parse, NodeVisitor except

python 2.5 and ast

2011-11-28 Thread Andrea Crotti
I'm happily using the ast module to analyze some code, but my scripts need also to run unfortunately on python 2.5 The _ast was there already, but the ast helpers not yet. Is it ok if I just copy over the source from the ast helpers in my code base or is there a smarter way? (I don't even need

Re: python 2.5 and ast

2011-11-28 Thread Terry Reedy
On 11/28/2011 6:45 AM, Andrea Crotti wrote: I'm happily using the ast module to analyze some code, but my scripts need also to run unfortunately on python 2.5 The _ast was there already, but the ast helpers not yet. Is it ok if I just copy over the source from the ast helpers in my code base

Re: python 2.5 and ast

2011-11-28 Thread Dave Angel
On 11/28/2011 03:08 PM, Terry Reedy wrote: On 11/28/2011 6:45 AM, Andrea Crotti wrote: I'm happily using the ast module to analyze some code, but my scripts need also to run unfortunately on python 2.5 The _ast was there already, but the ast helpers not yet. Is it ok if I just copy over the