Inline
Introduction
PyCharm provides the following inline refactorings:
- The Inline Variable refactoring replaces redundant variable usage with its initializer. This refactoring is opposite to Extract Variable.
Example
Before | After |
---|---|
import math
class Solver:
def demo(self):
a = 3
b = 25
c = 46
return_type_of_sqrt = math.sqrt(b ** 2 - 4 * a * c)
root1 = (-b + return_type_of_sqrt) / (2*a)
root2 = (-b - return_type_of_sqrt) / (2*a)
print(root1,root2)
Solver().demo() | import math
class Solver:
def demo(self):
a = 3
b = 25
c = 46
root1 = (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)
root2 = (-b - math.sqrt(b**2 - 4*a*c)) / (2*a)
print(root1,root2)
Solver().demo() |
Performing inline refactoring
- Place the caret in the editor at the desired symbol to be inlined.
- Do one of the following:
- On the main menu or on the context menu, choose .
- Press Ctrl+Alt+N.
- In the Inline dialog box that corresponds to the selected symbol, confirm the inline refactoring.
Last modified: 28 March 2018