Bowler
Bowler copied to clipboard
Safe code refactoring for modern Python.
Many of the codemods I write would benefit from knowing whether a given file is compatible with python 2, python 3, or both. May as well report minor versions while...
I am trying to perform a select like: ```python .select(r"funcdef< any* ':' suite< '\n' firstnode=' ' any* > >") ``` This indent which I have labelled `firstnode` will have the...
Currently it doesn't appear possible to set a breakpoint with `import pdb; pdb.set_trace()` in a `BowlerTestCase`. It looks like `in_process` is set to true when calling the modifier, but I...
For example, you want to rename node only if it matches some pattern. You can do this: ```python def modify(node: LN, capture: Capture, filename: Filename) -> None: if re.match(...): rename_transform(...)...
Now selectors captures everything related to the given topic. For example, `select_module` captures `module_name`, `module_nickname` etc. Sometimes it's useful to be more specific. For example: ```python ...select_module('test', capture=['module_name']) ```
Work with bowler quite easy. However, making custom modifier can be tricky. Now there is only [one example](https://pybowler.io/docs/basics-refactoring#modifiers) of it. Do you have more of them? Developers love examples :)
Input file: ```python from commonmark.main import commonmark ``` Code: ```python bowler.Query('__init__.py').select_module('commonmark').rename('testme').execute(write=True, silent=True) ``` Output: ```python from testme.main import testme ```
This appears to be valid in 3.6, 3.7, and 3.8.0a2: ```py def func(**kwargs): print(kwargs) x = {'a': '1'} func(**x or {}) ``` Bowler can't parse it, I'm wondering if there...
When transforms or modifiers fail, Bowler prints an error, and stringifies the exception, but this doesn't always help understand what the actual problem is (sometimes it just prints the Node,...
This looks like a great library, but the documentation is not very helpful in teaching it. I think I need to do a "from bowler import *" to get the...