-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Templates for common refactorings #109
Comments
This would be great. Just a handful of common examples would be very helpful to start. |
Also, a bit confused at the very beginning: from bowler import Query, Filename
query = Query(
'.',
# [lambda name: True if name in ('test.py', 'test2.py') else False],
)
selector = query.select_root('.').select_module('test').select_class('MyClass')
fixer = selector.rename('NewMyClass')
fixer.diff()
I'm confused how to match the class (in the example) across modules, while one-file selection leads to renaming only inside it. |
@jreese I think this is a support question for you... |
Unfortunately, you can't chain selectors like that; you either add filters/modifiers after each selector, or the next selector will just override the previous one. This is a limitation of how they are built on top of lib2to3's matching syntax. Dealing with classes/functions/variables with shared names across multiple modules is where lib2to3 does not make this easy, and Bowler isn't (yet) smart enough to track the origin of each name to know the difference. The most correct way is to use Bowler, and interactively keep or discard individual hunks of the diff based on whether it's referring to the class you want to rename or not. Bowler will at least be sure find all the references to that name for you though. |
For example, changing
from foo import baz
tofrom bar import baz
, a move refactoring seems quite difficult to execute with Bowler, as `select_module('baz¨) also returns usages of . It would be nice to have templates, i.e. functions returning queries, for common refactorings.The text was updated successfully, but these errors were encountered: