Extract Method

Extract refactorings are performed for the various expressions and blocks of code.
The current release will extract all similar occurrences (within the current scope) of the selected expression and replace with a method call.

How to invoke the Extract Method command?

There are a three options to invoke the extract method command, they are as follows:

Option 1 (Command Palette)

  • Select the text (expression/code block) to be extracted into a method
  • Launch the Command Palette via the shortcut (⇧⌘P or Ctrl+Shift+P)
  • Select the ‘Extract Method’ command
  • The selected expression(s) or block(s) of code will be extracted into a method with a random name prefixed ‘newmethod’
  • Next provide a new name for this method

Sample

Option 2 (Quick Fix)

  • Select the text (expression/code block) to be extracted into a method
  • Launch the Quick Fix command from the Command Palette (or use the short cut ⌘. or cmd+.)
  • Select the ‘Extract Method’ command from the menu
  • The selected expression(s) or block(s) of code will be extracted into a method with a random name prefixed ‘newmethod’
  • Next provide a new name for this method

Launching the Quick Fix command from the Command Palette
Sample using Quick Fix Command

Launching the Quick Fix command using the keyboard shortcut
Sample using Quick Fix Short Cut

Option 3 (Keyboard Shortcut)

  • Setup a custom keyboard short cut for the command ‘python.refactorExtractMethod’
  • Select the text (expression/code block) to be extracted into a method in the editor
  • Invoke the above command using the designated keyboard shortcut
Topics:

Extract Method

Extract refactorings are performed for the various expressions and blocks of code.
The current release will extract all similar occurrences (within the current scope) of the selected expression and replace with a method call.

How to invoke the Extract Method command?

There are a three options to invoke the extract method command, they are as follows:

Option 1 (Command Palette)

  • Select the text (expression/code block) to be extracted into a method
  • Launch the Command Palette via the shortcut (⇧⌘P or Ctrl+Shift+P)
  • Select the ‘Extract Method’ command
  • The selected expression(s) or block(s) of code will be extracted into a method with a random name prefixed ‘newmethod’
  • Next provide a new name for this method

Sample

Option 2 (Quick Fix)

  • Select the text (expression/code block) to be extracted into a method
  • Launch the Quick Fix command from the Command Palette (or use the short cut ⌘. or cmd+.)
  • Select the ‘Extract Method’ command from the menu
  • The selected expression(s) or block(s) of code will be extracted into a method with a random name prefixed ‘newmethod’
  • Next provide a new name for this method

Launching the Quick Fix command from the Command Palette
Sample using Quick Fix Command

Launching the Quick Fix command using the keyboard shortcut
Sample using Quick Fix Short Cut

Option 3 (Keyboard Shortcut)

  • Setup a custom keyboard short cut for the command ‘python.refactorExtractMethod’
  • Select the text (expression/code block) to be extracted into a method in the editor
  • Invoke the above command using the designated keyboard shortcut