[code-quality] RedBaron, a bottom-up refactoring lib/tool for python

Kay Hayen kay.hayen at gmail.com
Sat Nov 22 09:46:10 CET 2014


Hello Laurent,

for my coding conventions, which are a bit unusual, to me e.g. this is the
correct function call, if every parameter is passed by keyword argument,
and the "=" signs are aligned on the maximum level. I had looked into
lib2to3, and found it terribly complex to work with visitors, to pick up
enough state information, so I dropped my idea to make an automatic source
code formatter for my preferred style.

I think Redbaron might be much better suited to achieve that, it seems.

However, in the past years, when I did these things, I have come to expose
this sort of tree to the users in a way, so that they can make xpath
queries. Can you make your tree lxml walkable, and basically allow xml
transformations with its API.

That way tests on the syntax tree could be expressed more easily.

I am, in Nuitka, my Python compiler, exposing an XML dump of the final
internal tree, and use tests with xpath queries on it, to e.g. identify
print statements of non-constants, to declare these errors.

While I don't do enough of these, to me, that is the natural way now of
selecting data from a tree. My function calls to modify, and the values to
use in there, would be pretty natural xpath queries, I suppose. I would
then iterate in a for loop, determine the maximum identifier length of
keyword arguments, update the spacing before the equals sign, in the node
tree, with more xpath queries to find children.

Performance might be a red herring there, but xpath queries that make me
avoid touching nodes already properly formatted, would probably also be
faster. Most likely performance is not an issue at all. But xpath can be
run time compiled in principle.

Let me know what you think of that.

Yours,
Kay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/code-quality/attachments/20141122/d34a22ad/attachment.html>


More information about the code-quality mailing list