PyCharm 2021.2 Help

Change signature

The Change Signature refactoring combines several different modifications that can be applied to a function signature. You can use this refactoring to:

  • change the function name

  • add, remove, and reorder parameters

  • assign default values to the parameters

When changing a function signature, PyCharm searches for all usages of the function and updates all the calls, implementations, and override replacements of the function that can be safely modified to reflect the change.

Change signature in place

You can also change the signature of a function as you type in the editor.

  1. Start adding or editing the parameter of a function. PyCharm will display the Refactoring icon in the gutter.

    In-place change signature refactoring
  2. Click the icon in the gutter or press Alt+Enter.

    If you are adding a new parameter, PyCharm will offer you to add a default value for it as well as update the usages.

    Add default value for a parameter

    If you are editing a parameter, PyCharm will offer to update the usages for you.

    Update usages for parameter
  3. Click Update to apply the suggestions.

Changing a function signature

  1. Position the caret at the name of the function that you want to refactor.

  2. Press Ctrl+F6. Alternatively, select Refactor | Change Signature from the main or context menu.

  3. In the Change Signature dialog, make necessary changes to the function signature depending on your needs:

    Change signature animation

    • Change the function name. To change the name, edit the text in the Name field.

    • Manage the function parameters. To configure the parameters, use the table and buttons in the Parameters area:

      • To add a new parameter, click The Add button and specify the new parameter's properties in the corresponding table row.

      • To remove a parameter, select any row and click The Remove button.

      • To reorder the parameters, click The Up icon and The down icon. For example, if you want to put a certain parameter first in the list, click any of the cells in the row corresponding to that parameter, and then click The Up icon the required number of times.

      • You can specify the default value of the newly added parameter. Do not select the Use default value in signature checkbox to use the specified value in existing calls as an explicit placeholder.

  4. To see the expected changes and make adjustments prior to the refactoring, click Preview.

  5. Click Refactor.

Last modified: 27 August 2021