Rename refactorings allow you to rename symbols , automatically correcting all references in the code.
The following rename refactorings are available in PyCharm:
-
Rename Class. The following usages are renamed:
- Import statements
- Qualified names of classes
-
Rename Method. The following usages are renamed:
- All calls of the method.
- All overridden/implemented methods in subclasses.
- Rename Field.
- Rename Function.
- Rename Variable.
-
Rename Parameter. The following usages are renamed:
- All usages of the parameter.
- The corresponding
param
tag in documentation comment.
- Rename CSS color value.
- Rename File.
- Rename Directory.
Example 1
Before | After |
---|---|
Renaming method | |
def was_published_today(self): return self.pub_date.date () == datetime.date.today() } |
def published_today(self): return self.pub_date.date () == datetime.date.today() } |
Example 2
Rename a template:
So doing, the following usages will be renamed:
- Select the item to be renamed.
- To select a file, click the desired file in the Project tool window.
- To select a symbol in the editor, place the caret at the name of the symbol to be renamed.
- To select a symbol in the Project tool window, make sure that the members are shown, and then click the desired symbol.
- To select a symbol in the Structure view, click the desired symbol in the Structure tool window.
- Choose Shift+F6. on the main menu or on the context menu of the selection or press
- The subsequent behavior depends on the check box
Enable in-place mode
(
).
- If this check box is selected, the suggested name appears right below the symbol in question. You can either accept suggestion, or type a new name. However, if you press Shift+F6 once more, PyCharm will display the Rename dialog box with more options.
- If this check box is not selected, the Rename dialog box opens immediately.
The set of controls and their names depend on the type of the symbol to be renamed.
- Preview and apply changes.
Important notes
- Local variables are renamed in-place:
To be able to use the Rename dialog when renaming local variables, you should disable in-place refactoring in the editor settings.
-
When renaming Gherkin steps, mind the following limitations:
- Step definitions should not contain regular expressions
- Step names should not contain non-alpha numeric characters.
- A step definition should be only one in various frameworks.
- There should be a "one-to-one" mapping between a step and a step definition.