Edward K. Ream added the comment: I urge the Python development team to fix this and the related bugs given in the Post Script. The lack of an easy way of associating ast nodes with text ranges in the original sources is arguably the biggest hole in the Python api.
These bugs have immediate, severe, practical consequences for any tool that attempts to regularize (pep 8) or beautify Python code. Consider the code for PythonTidy: http://lacusveris.com/PythonTidy/PythonTidy-1.23.python Every version has had bugs in this area arising from difficult workarounds to the hole in the API. The entire Comments class is a horror directly related to these issues. Consider Aivar's workaround to these bugs: https://bitbucket.org/plas/thonny/src/8cdaa41aca7a5cc0b31618b6f1631d360c488196/src/ast_utils.py?at=default See the docstring for def fix_ast_problems. This is an absurdly difficult solution to what should be a trivial problem. It's impossible to build reliable software using such heroic hacks. The additional bugs listed below further complicate a nightmarish task. In short, these bugs are *not* minor little nits. They are preventing the development of reliable source-code tools. Edward K. Ream P.S. Here are the related bugs: http://bugs.python.org/issue10769 Allow connecting AST nodes with corresponding source ranges http://bugs.python.org/issue21295 Python 3.4 gives wrong col_offset for Call nodes returned from ast.parse http://bugs.python.org/issue18374 ast.parse gives wrong position (col_offset) for some BinOp-s http://bugs.python.org/issue16806 col_offset is -1 and lineno is wrong for multiline string expressions EKR ---------- nosy: +Edward.K..Ream _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22616> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com