Feature request: handle ast node pretty printing
Ideally, something more like http://alexleone.blogspot.com/2010/01/python-ast-pretty-printer.html than like ast.dump, but anything would be better than the default useless repr() of ast nodes :)
Sounds awesome! Would definitely accept a PR which knows how to handle AST nodes.
Notes to myself about potentially implementing this from my initial reading of the code:
- [ ] Add new container type for
_mk_open_close_empty_dictfor an argument list, which is the same as dict, really, just with = separator between key and value rather than :, and unquoted keys. - [ ] Consider handling subclasses of handled types for
_mk_open_close_empty_dict, wrapping open/close in a call to__class__.__name__(), so we can add AST rather than each and every node class. This could potentially give us frozenset and Counter for free, so we could remove them, and would also get us e.g. OrderedDict. Of course it assumes that it's constructed in the same way as its base class, but if that's not the case, it's easy enough to explicitly add those to the list. Of course, trivial subclasses are handled already to a certain extent, but it formats them with the base class's repr, which isn't ideal. Showing the name of each ast node is critical.
Alternatively, add the ability to punt and call out to an external formatting function for a particular container class, feeding it the current indent, to let it handle pretty formatting itself rather than knowing how to format everything ourselves, possibly passing along the formatting function to use for the contained objects.
Woo!
I'm tentatively in favor of your proposed subclass handling, just so long as it won't break subclasses with custom repr methods (ex, if I have class MyOrderedDict(OrderedDict): def __repr__(self): return "weeee")
Thanks, I'll get started on it and keep you posted. Appreciate the feedback.