takluyver / astsearch

Intelligently search in Python code
https://astsearch.readthedocs.io/en/latest/
MIT License
67 stars 3 forks source link

Python 2 compatibility #4

Open vfaronov opened 7 years ago

vfaronov commented 7 years ago

This is such an obvious, obviously useful tool. I just had one of those semi-regular boats of “this tool must exist”, but this time I decided to actually search for it (or maybe the last time was before 2014), and sure enough you’ve already did it. Thank you!

If only this were Python 2 compatible (i.e. could parse Python 2 code, not necessarily run under Python 2), I would use it daily and tell all my friends about it. Hell, I’d wear a T-shirt with an ASTsearch logo on it.

Any idea how hard that would be? With some trivial changes I can make more than 50% of the tests pass under Python 2, but maybe those are the trivial 50% :)

takluyver commented 7 years ago

I'd guess not too hard. The biggest challenge would be the differences in AST structure - it changes a bit on each Python version. My docs here have some notes on the differences: http://greentreesnakes.readthedocs.io/en/latest/nodes.html

I'm pretty sure that the easiest way to let it parse Py2 code is to make it run under Py2 as well; the stdlib ast module it uses parses the version of Python that it's part of.

alexbw commented 7 years ago

I've been searching for something similar, this is all I've found for helping with Python 2 & 3 compatibility: https://github.com/serge-sans-paille/gast