mbdevpl / horast

Human-oriented abstract syntax tree (AST) parser/unparser for Python 3 that doesn't discard comments.
Apache License 2.0
16 stars 6 forks source link

AST visitor example? #2

Closed void4 closed 4 years ago

void4 commented 5 years ago

Can you please provide an example of an ast.NodeVisitor equivalent in horast? This library looks very useful because it includes comments. I want to use it to automatically generate documentation from source, since tools like sphinx only seem to include function doc strings.

mbdevpl commented 5 years ago

Did you try using that visitor for horast and were there errors? It might work just like that. If there were errors, try using the typed_ast.ast3.NodeVisitor, because AST in horast is based on typed_ast. There is no separate implementation of NodeVisitor in horast.

Although I don't currently explicitly test if the visitors from upstream work as expected in horast, I might include such tests in the future if it doesn't.

mbdevpl commented 5 years ago

And, as far as I remember, the NodeVisitor in typed_ast works exactly the same as the one in ast. As a side note, typed_ast codebase was merged into CPython, so ast module in Python 3.8 will become what is now typed_ast. At that point I plan to adapt horast to not work with typed_ast anymore, as the module will become obsolete. But that's a thing for the future.

mbdevpl commented 4 years ago

I'm closing this because of no new activity for a long time. Please reopen if anything about this problem is unclear.