On Thu, Feb 2, 2012 at 4:35 PM, Nick Coghlan
On Thu, Dec 29, 2011 at 1:28 AM, Michael Foord
wrote: On a simple level, all of this is already "obtainable" by using the ast module that can parse Python code. I would love to see a "python-object" layer on top of this that will take an ast for a module (or other object) and return something that represents the same object as the ast.
So all module level objects will have corresponding objects - where they are Python objects (builtin-literals) then they will represented exactly. For classes and functions you'll get an object back that has the same attributes plus some metadata (e.g. for functions / methods what arguments they take etc).
That is certainly doable and would make introspecting-without-executing a lot simpler.
The existing 'clbr' (class browser) module in the stdlib also attempts to play in this same space. I wouldn't say it does it particularly *well* (since it's easy to confuse with valid Python constructs), but it tries.
Unfortunately http://docs.python.org/library/pyclbr.html misses info about variables. In the meanwhile I've patches my `astdump` module even further: - function to query top level variables changed from get_top_vars() to top_level_vars(), which is now accepts filename as a parameter. Now it will be even more convenient to use it for generating `setup.py` for simple modules. Sample `setup.py` generator is included. http://pypi.python.org/pypi/astdump/1.0 -- anatoly t.