Skip to content
Laurent Peuch edited this page Sep 6, 2016 · 5 revisions

On the field usage of RedBaron (add yours!)

A list of "on the field" usages of (Red)Baron that we've managed to gather (don't hesitate to contribute to this list).

Internal custom refactoring of Astroid (the lib behind pylint) by a combinaison of RedBaron and Astroid by ceridwen

The modified code: https://github.com/PCManticore/astroid/pull/2/files

ceridwen explaination:

The high-level summary is that astroid has had, up to this point, a doubly-linked tree, where nodes hold references to both their children and their parent. (I'm assuming redbaron has a similar structure, but I haven't looked at your implementation.) The problem with this is that, barring something like tying the knot which is difficult in Python because it's a very eagerly-evaluated language, this requires a two-stage instantiation for nodes, because you can't create a node's children without creating the node for their parent references to point to.

Thus, we had init and postinit methods, and you had to call both to properly instantiate a node. This has a lot of disadvantages.

So, I wrote a new data structure called a zipper (see http://blog.ezyang.com/2010/04/you-could-have-invented-zippers/ for a decent intro) that effectively gives parent links to a singly-linked tree. Once I had that, though, I had to go back and refactor all the methods on the nodes and all the places where node constructors were called to remove the doubly-linked structure

The vast majority of the refactoring in that patch was done with an astroid+redbaron script. I had to do some manual fixes, because of the limitations of astroid's static analysis and some bugs in my script.

Note that this isn't even all the constructor calls in astroid, we're in the process of separating out this part from the astroid static analysis part.

So I'm going to be using that script again at some point on the rest of astroid :).

The refactoring script isn't released yet.

TODO describe more

  • custom Advanced Editor for a Python based DSL for technicians at a Space company (yeah, RedBaron is used in a toolchain to talk to satellites)
  • hackeragenda demo
  • hackeragenda script to add a meetup
  • someone used it to replace print statement with python logger call in hundred of files
  • apparently someone made a code minimifier with it
  • used in some tests of flask
  • used in this scientific paper https://hal-mines-paristech.archives-ouvertes.fr/hal-01352808/document