-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying the generator class. #114
Conversation
I have another related question. I would like to be able to adjust the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! This looks good to me, it would be great if we could add some tests and documentation:
-
For tests, adding just two tests would be enough: 1) we can convert the example I gave at Allow registering new
visit_xxx
forSourceGenerator
#113 (comment) 2) and we also need a test to cover theTypeError
branch -- see my review comments about this -
For documentation, we need to update the documentation in
docs/index.rst
. Please add a..versionchanged:: 0.7 Added *source_generator_class* parameter.
marker (feel free to change the wording, I just gave it as an example.) -
Please update
docs/changelog.rst
and add your name toAUTHORS
file.
Could you open a new issue to discuss this one? There is an open PR to refactor |
I just wanted to update that I have not forgotten about the PR, it's just that I ended up using astor quite a bit in new code I wrote, so before I continued with the PR I wanted to get a clearer picture for myself how I was going to use astor to make sure my solution was good approach. In the end, I just wrote my own version of If the underlying API used in |
I think this PR would still help users to customize source generator. I recently came across a blog post using astor (I can't read Chinese, but I can read Python :)): http://blog.soliloquize.org/2017/02/08/%E4%BD%BF%E7%94%A8ast%E7%A7%BB%E9%99%A4%E4%BB%A3%E7%A0%81%E4%B8%AD%E7%9A%84print%E8%AF%AD%E5%8F%A5/ With import astor
class RemovePrintGenerator(astor.code_gen.SourceGenerator):
def visit_Call(self, node):
if node.func.id != 'print':
super().visit_Call(node)
print(astor.to_source(astor.parse_file('foo.py'), source_generator_class=RemovePrintGenerator)) |
Thanks for finishing this off. I hadn't had the time to complete it. |
Fixes #113
Adds the ability to specify the class to be used to generate the source code.