RedBaron (Python AST library) has an incredible Emacs mode for Python code transformations: