Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandatory Default variables and parameter propagation while changing signature (refactoring) in pycharm

Tags:

pycharm

I'm doing an evaluation of pycharm and is stuck with the refactoring bit. What I want to achieve is to add a new parameter in one of the functions. I have two problems here.

  1. Whenever I add a new parameter, it says 'Default Value is missing'
  2. Propagate Parameters seems disabled all the time

So, is default value mandatory? and how would I reflect the new parameter in all function calls?

Attaching a screenshot if that helps.. enter image description here

like image 552
ranjjose Avatar asked Aug 12 '15 02:08

ranjjose


People also ask

How do I refactor codes in Pycharm?

Do one of the following: On the main Refactor menu or from the context menu of the selection, choose the desired refactoring or press the corresponding keyboard shortcut (if any). From the main menu, choose Refactor | Refactor This, or press Ctrl+Alt+Shift+T , and then select the desired refactoring from the popup.

How do I refactor a function name in Pycharm?

Press Shift+F6 or from the main menu, select Refactor | Rename. You can perform the rename refactoring in-place or press Shift+F6 again to open the Rename dialog. Enter a new name of the element to enable the Preview and Refactor buttons. You can specify additional options.

How do I refactor a signature in Intellij?

Select method or a class for which you want to change signature. From the context menu, select Refactor | Change Signature ( Ctrl+F6 ). In the dialog that opens depending on what you're changing signature for, specify the appropriate options and click Refactor.


1 Answers

It appears that "Default value" is not supposed to mean "default value" in the Python sense: it is the text to be put in calls that will be changed according to the new signature, these necessarily defaulting on the extended signature.

This would also explain the additional checkbox for actually putting that value as a "Python default value" with the new parameter. It is then shown as a Python default value (= ...) in the signature preview.

Thus, if you place the text thing2 in the box for "Default value" for new_param, and leave the checkbox unchecked, then after refactoring (which is then possible)

fn1(thing1)

becomes

fn1(thing1, thing2)

at the call site, and the refactored definition of fn1 then becomes

def fn1(param1, new_param):
    #  ...

That is, no Python default values are involved.

like image 130
B98 Avatar answered Oct 17 '22 23:10

B98