[issue39686] add dump_json to ast module

Richard K report at bugs.python.org
Wed Feb 19 13:02:17 EST 2020


Richard K <qpotizo at gmail.com> added the comment:

Batuhan & Pablo thank you for your thoughts! Just wanted to reply to a few of the comments to clarify my position on the issue.


> IMHO this is not a feature that has a general usage. If you want, as far as I can see, there are some packages for doing that in PyPI already. Also, the patch looks small so you can just add this to the required project.


There seems to be movement towards a general usage. For instance, take a look at clang, in particular the flag '-ast-dump=json'.

$ clang -cc1 -ast-dump=json foo.cc


> ast.dump now can dump in pretty-printed way.

Indeed however, there is not much one can do further with the output of ast.dump. With ast.dump_json one would benefit from programmer-centric functionality.

-- 

> Thanks, Richard for your proposal. I concur with Batuhan: I am -1 as well on this addition. Echoing some of the same ideas, I think this is specialized enough that does not make sense to have it in the standard library, especially if a Pypi package already exists. 


After just browsing the the pypi package/s you may be referring to, it appears that they do so in non-standard ways.


> Additionally, this is straightforward to implement for very simple cases but PR18558 will fail for very generic ASTs if they are deep enough (it uses recursion).


The implementation of ast.dump also uses recursion. I have tested ast.dump_json on sufficiently large source files and have not run into recursion depth exceeded issues.


Thanks again for your perspective!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39686>
_______________________________________


More information about the Python-bugs-list mailing list